Skip to content

Replace chembl_webresource_client with direct REST API calls #49

@HFooladi

Description

@HFooladi

Summary

The chembl_webresource_client package appears to have low maintenance activity (no releases since Feb 2024) and can cause import failures when the ChEMBL API service is unavailable. This blocks the entire import chain even when ChEMBL functionality isn't needed.

Current State

  • The package is now in the optional [chembl] dependency group
  • Import is lazily handled in themap/utils/protein_utils.py with a try/except
  • Functions raise RuntimeError with helpful message when ChEMBL client is unavailable

Proposed Solution

Replace chembl_webresource_client usage with direct REST API calls using requests:

import requests

def get_protein_accession(target_chembl_id: str) -> Optional[str]:
    """Get protein accession using direct REST API."""
    url = f"https://www.ebi.ac.uk/chembl/api/data/target/{target_chembl_id}.json"
    response = requests.get(url, timeout=30)
    if response.status_code == 200:
        data = response.json()
        components = data.get("target_components", [])
        if components:
            return components[0].get("accession")
    return None

def get_target_chembl_id(assay_chembl_id: str) -> Optional[str]:
    """Get target ChEMBL ID using direct REST API."""
    url = f"https://www.ebi.ac.uk/chembl/api/data/assay/{assay_chembl_id}.json"
    response = requests.get(url, timeout=30)
    if response.status_code == 200:
        data = response.json()
        return data.get("target_chembl_id")
    return None

Benefits

  1. Removes dependency on potentially unmaintained package
  2. requests is already a dependency (used elsewhere)
  3. More explicit error handling
  4. No import-time network calls

Files to Modify

  • themap/utils/protein_utils.py - Replace client usage with REST calls
  • pyproject.toml - Remove chembl-webresource-client from [chembl] optional deps

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions