chemistry_tools.pubchem.pug_rest

Attention

This package has the following additional requirements:

cawdrey>=0.1.7
mathematical>=0.1.13
pillow>=7.0.0
pyparsing>=2.4.6
tabulate>=0.8.9

These can be installed as follows:

python -m pip install chemistry-tools[pubchem]

Functions for interacting with PubChem PUG_REST API.

Functions:

async_get(identifier[, namespace, …])

Request wrapper that automatically handles asynchronous requests.

do_rest_get(namespace, identifier[, …])

Responsible for performing the actual GET request.

get_full_json(cid)

Returns the full JSON record for the compound with the given ID.

request(identifier[, namespace, operation, …])

Construct API request from parameters and return the response.

async_get(identifier, namespace='cid', operation=None, output='JSON', searchtype=None, **kwargs)[source]

Request wrapper that automatically handles asynchronous requests.

Parameters
  • identifier – Identifiers (e.g. name, CID) for the compounds to look up. When using the CID namespace data for multiple compounds can be retrieved at once by supplying either a comma-separated string or a list.

  • namespace (Union[PubChemNamespace, str]) – The type of identifier to look up. Valid values are in PubChemNamespace. Default 'cid'.

  • operation – Default None.

  • output – Default 'JSON'.

  • searchtype – Default None.

  • **kwargs – Keyword parameters passed along with the GET request.

Return type

bytes

do_rest_get(namespace, identifier, format_=<PubChemFormats.JSON: 'JSON'>, domain=None, record_type='2d', png_width=300, png_height=300)[source]

Responsible for performing the actual GET request.

Parameters
  • namespace (Union[PubChemNamespace, str]) – The type of identifier to look up. Valid values are in PubChemNamespace.

  • identifier (Union[str, int, Sequence[Union[str, int]]]) – Identifiers (e.g. name, CID) for the compounds to look up. When using the CID namespace data for multiple compounds can be retrieved at once by supplying either a comma-separated string or a list.

  • format_ (Union[PubChemFormats, str]) – The file format to retrieve the data in. Valid values are in PubChemFormats, plus 'PNG'. Default <PubChemFormats.JSON: 'JSON'>.

  • domain (Optional[str]) – Default None.

  • record_type (str) – Default '2d'.

  • png_width (int) – Default 300.

  • png_height (int) – Default 300.

Return type

Response

get_full_json(cid)[source]

Returns the full JSON record for the compound with the given ID.

Parameters

cid (Union[str, int])

Return type

str

request(identifier, namespace='cid', operation=None, output='JSON', searchtype=None, **kwargs)[source]

Construct API request from parameters and return the response.

Full specification at http://pubchem.ncbi.nlm.nih.gov/pug_rest/PUG_REST.html

Parameters
  • identifier – Identifiers (e.g. name, CID) for the compounds to look up. When using the CID namespace data for multiple compounds can be retrieved at once by supplying either a comma-separated string or a list.

  • namespace (Union[PubChemNamespace, str]) – The type of identifier to look up. Valid values are in PubChemNamespace. Default 'cid'.

  • operation – Default None.

  • output (Union[PubChemFormats, str]) – Default 'JSON'.

  • searchtype – Default None.

  • **kwargs – Keyword parameters passed along with the GET request.

Return type

Response