ChemInformant.api_helpers module#

setup_cache(cache_name='pubchem_cache', backend='sqlite', expire_after=604800, **kwargs)[source]#

Configures the cache used for PubChem API requests.

Call this function before making any ChemInformant API calls if you want to use non-default cache settings. This function should be imported from the ChemInformant package level (e.g., ChemInformant.setup_cache(…)).

Parameters:
  • cache_name (str) – Name of the cache file/db.

  • backend (str) – Cache backend (‘sqlite’, ‘memory’, etc.).

  • expire_after (int | float | None | timedelta) – Expiration time in seconds.

  • **kwargs – Additional backend arguments for requests_cache.CachedSession.

get_session()[source]#

Internal function to get the current session (cached or default).

get_cids_by_name(compound_name)[source]#

Get a list of PubChem CIDs matching a name. Returns None if none found.

Return type:

Optional[List[int]]

Parameters:

compound_name (str)

get_cas_unii(cid)[source]#

Get CAS and UNII for a single CID using PUG View.

Return type:

Tuple[Optional[str], Optional[str]]

Parameters:

cid (int)

get_additional_properties(cid)[source]#

Get additional chemical properties for single CID.

Return type:

Dict[str, Any]

Parameters:

cid (int)

get_compound_description(cid)[source]#

Get the description for a single CID.

Return type:

Optional[str]

Parameters:

cid (int)

get_all_synonyms(cid)[source]#

Get synonyms for a single CID.

Return type:

List[str]

Parameters:

cid (int)

get_batch_properties(cids, properties)[source]#

Get multiple properties for a list of CIDs in one request.

Return type:

Dict[int, Dict[str, Any]]

Parameters:
get_batch_synonyms(cids)[source]#

Get synonyms for a list of CIDs in one request.

Return type:

Dict[int, List[str]]

Parameters:

cids (List[int])

get_batch_descriptions(cids)[source]#

Get descriptions for a list of CIDs in one request (uses XML batch).

Return type:

Dict[int, Optional[str]]

Parameters:

cids (List[int])