Skip to content

Client

Implementation of the PubChem API parser class. https://pubchemdocs.ncbi.nlm.nih.gov/pug-rest

PUBCHEM_BASE_URL = 'https://pubchem.ncbi.nlm.nih.gov/rest/pug'

PubChemAPI(base_url=PUBCHEM_BASE_URL, response_format=APIResponseType.JSON, client_factory=httpx.AsyncClient, rate_limiter=None, sleep=asyncio.sleep)

Bases: BaseAPI

Asynchronous Client for PubChem REST API.

Initialize the PubChemAPI client.

PARAMETER DESCRIPTION
base_url

Base URL for the PubChem API. Defaults to the PubChem REST root [PUBCHEM_BASE_URL].

response_format

The response format for the API, JSON or XML. Defaults to JSON.

client_factory

httpx client factory. Pass a cache policy's factory to enable caching. Defaults to a plain httpx.AsyncClient.

rate_limiter

AsyncLimiter instance for rate limiting. Defaults to 5 requests per second when None.

sleep

A callable for sleeping between retries. Defaults to asyncio.sleep.

TYPE: Callable[[float], Awaitable[None]] DEFAULT: sleep

response_format = str(config.response_format)

enrich_cid_properties(assay_data, extra_properties=None)

Fetch properties for each unique CID and enrich the assay in place.

PARAMETER DESCRIPTION
assay_data

AssayInfo object containing the assay data.

extra_properties

Additional properties to retrieve beyond the default set of properties declared in DEFAULT_PROPERTIES.

RETURNS DESCRIPTION
AssayInfo

The same AssayInfo, with each record's properties populated.

get_assay(aid)

Fetch the concise assay information for a given PubChem Assay ID (AID).

PARAMETER DESCRIPTION
aid

PubChem Assay ID.

RETURNS DESCRIPTION
AssayInfo | None

An AssayInfo object containing the assay information, or None if not

AssayInfo | None

found.

get_enriched_assay(aid, extra_properties=None)

Fetch and enrich an assay in one step.

PARAMETER DESCRIPTION
aid

PubChem Assay ID.

extra_properties

Additional properties to retrieve on top of DEFAULT_PROPERTIES.

RETURNS DESCRIPTION
AssayInfo | None

An enriched AssayInfo, or None if the assay could not be fetched.

get_properties(cids, properties)

Public wrapper to fetch compound properties for a list of CIDs.