pubchem-compounds
A Python wrapper for the PubChem PUG REST API, focused on Compounds and Substances. It provides:
- Identifier conversion: CAS → CID / SID, InChIKey → CID, SMILES → CID, CID → CAS / EINECS / DTXSID
- Batch property fetching from lists of CIDs
- SDF / RDKit mol retrieval for CIDs, SIDs, or CAS numbers
- SMILES and InChI extraction for any PubChem synonym
- PFAS classification tree node queries
- Built-in rate limiting (max 5 req/s, 400 req/min) and automatic retry on HTTP 403
Installation
From PyPI
pip install pubchem-compounds
Note: RDKit is required only for functions that return molecules (
get_mols_from_cids,cas_to_mols,synonyms_to_smiles, etc.). Install it separately:pip install rdkit # rdkit ≥ 2023.03 # or via conda: conda install -c conda-forge rdkit
From source
git clone https://gitlab.com/lucmiaz/pubchem.git
cd pubchem
pip install -e .
Install with optional dependencies:
pip install -e ".[dev]" # pytest, pylint
pip install -e ".[docs]" # sphinx, sphinx-rtd-theme
Quick start
import pubchem_compounds as pc
CAS → CID
mapping, failed = pc.cas_to_cid("7732-18-5") # water
print(mapping) # {'7732-18-5': [962]}
Batch CAS lookup
cas_list = ["7732-18-5", "74-82-8", "71-43-2"]
mapping, failed = pc.cas_to_cid(cas_list)
# {'7732-18-5': [962], '74-82-8': [297], '71-43-2': [241]}
CAS → SMILES
processed, failed = pc.cas_to_smiles(["7732-18-5", "74-82-8"])
print(processed["7732-18-5"]) # 'O'
print(processed["74-82-8"]) # 'C'
CAS → RDKit molecules
mols = pc.cas_to_mols(["7732-18-5", "74-82-8"])
for cas, mol_list in mols.items():
for mol in mol_list:
print(cas, mol.GetNumAtoms())
Fetch compound properties for a list of CIDs
data = pc.get_from_cids([962, 297, 241], target="property/MolecularFormula,MolecularWeight")
for prop in data["PropertyTable"]["Properties"]:
print(prop["CID"], prop["MolecularFormula"], prop["MolecularWeight"])
CID → CAS (reverse lookup)
cas_list = pc.cid_to_cas(962)
print(cas_list) # ['7732-18-5']
InChIKey → CID
cids = pc.inchikey_to_pubchem("XLYOFNOQVPJJNP-UHFFFAOYSA-N")
print(cids) # [962]
DTXSID → SMILES
Via PubChem
processed, failed = pc.dtxsid_to_smiles(["DTXSID9020584"])
print(processed["DTXSID9020584"])
Via CompTox
from pubchemcompounds import mols_from_comptox
mols = mols_from_comptox(["DTXSID4059916"])
PFAS classification tree
# Fetch all CIDs from the OECD PFAS list node (default hnid = 5517102)
cids = pc.pubchem_pfas_tree()
print(f"{len(cids)} PFAS CIDs found")
For a full API reference and more examples, see the documentation.
Dependencies
| Package | Purpose |
|---|---|
requests |
HTTP requests |
numpy |
Rate-limiting random intervals |
regex |
CAS / EINECS / DTXSID pattern matching |
tqdm |
Progress bars for batch operations |
rdkit (optional) |
SDF parsing and mol/SMILES generation |
Licence
Copyright © 2024–2026 Luc T. Miaz.
Licensed under the Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0) licence.
Acknowledgments
Developed under the ZeroPM project (WP2) funded by the European Union's Horizon 2020 research and innovation programme (grant agreement No 101036756). Developed at the Department of Environmental Science, Stockholm University.
Metadata
Release files for pubchem-compounds 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pubchem_compounds-1.1.3.tar.gz | 21.8 kB | Without provenance | Details for pubchem_compounds-1.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pubchem_compounds-1.1.3-py3-none-any.whl | Python 3 | none | any | Details for pubchem_compounds-1.1.3-py3-none-any.whl |
Total release size: 39.7 kB
Release files / pubchem_compounds-1.1.3.tar.gz
| Download URL | pubchem_compounds-1.1.3.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
899ade1b40863bd3f42a72e6d0a24d995640ad1b911efa0847f7f01a4bdace0d
|
|
BLAKE2b-256 checksum How to use checksums |
f8147545446eb1659efc18cc98081c297dd7ab1030667229dbdf778e0c7236d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / pubchem_compounds-1.1.3-py3-none-any.whl
| Download URL | pubchem_compounds-1.1.3-py3-none-any.whl |
|---|---|
| Size | 17.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d32ddab9f2150093deb800dd7955aec7c8cd6da19cfd77f617f70024723ae887
|
|
BLAKE2b-256 checksum How to use checksums |
a754516edd477064183b06481e716186ef2c89421eebf602b5aa4b83473490e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for pubchem-compounds 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.