{"id":2200,"library":"pubchempy","title":"PubChemPy","description":"PubChemPy is a simple Python wrapper around the PubChem PUG REST API, providing an intuitive interface to query chemical information from PubChem. It allows programmatic access to compounds, substances, assays, and their properties. The current version is 1.0.5, and releases are infrequent, primarily addressing bug fixes and minor enhancements.","status":"active","version":"1.0.5","language":"en","source_language":"en","source_url":"https://github.com/mcs07/PubChemPy","tags":["chemistry","cheminformatics","pubchem","api","chemical-data","rest-api"],"install":[{"cmd":"pip install PubChemPy","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for making HTTP requests to the PubChem PUG REST API.","package":"requests"}],"imports":[{"symbol":"pubchempy","correct":"import pubchempy as pcp"},{"symbol":"Compound","correct":"from pubchempy import Compound"},{"symbol":"Substance","correct":"from pubchempy import Substance"},{"symbol":"PubChemPyError","correct":"from pubchempy import PubChemPyError"}],"quickstart":{"code":"import pubchempy as pcp\n\ntry:\n    # Search for compounds by name\n    compounds = pcp.get_compounds('aspirin', 'name')\n\n    if compounds:\n        aspirin = compounds[0]\n        print(f\"Compound Name: {aspirin.iupac_name}\")\n        print(f\"CID: {aspirin.cid}\")\n        print(f\"Molecular Formula: {aspirin.molecular_formula}\")\n        print(f\"Canonical SMILES: {aspirin.canonical_smiles}\")\n\n        # Retrieve specific properties for a compound\n        properties = pcp.get_properties(\n            ['molecular_weight', 'xlogp'], # List of properties to fetch\n            aspirin.cid,\n            'cid' # Namespace: 'cid' for compound IDs\n        )\n        if properties:\n            print(f\"Molecular Weight: {properties[0]['MolecularWeight']}\")\n            print(f\"XLogP: {properties[0]['XLogP']}\")\n        else:\n            print(\"Could not retrieve additional properties.\")\n\n    else:\n        print(\"Aspirin not found in PubChem.\")\n\nexcept pcp.PubChemPyError as e:\n    print(f\"A PubChemPy API error occurred: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This example demonstrates how to search for a compound by name, retrieve its basic properties, and then fetch additional specific properties using its PubChem CID."},"warnings":[{"fix":"Implement explicit delays (`time.sleep()`) between calls or use `PubChemPy` features that support batch processing for large numbers of queries.","message":"PubChem imposes rate limits (e.g., 10 requests per second from a single IP address) on its PUG REST API. PubChemPy does not inherently manage these limits, so users must implement delays or batch queries (where applicable, like `as_dataframe=True` for `get_compounds`) to avoid HTTP 429 (Too Many Requests) errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always check if results are empty or `None` before accessing elements, and wrap API calls in `try...except PubChemPyError` blocks.","message":"API calls might return empty lists or `None` if no data is found, or raise `pubchempy.PubChemPyError` for issues like invalid CIDs or API errors. Robust error handling is crucial.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If `Compound.fingerprint` was used in versions prior to 1.0.4, review any code that depends on its output, as the generated fingerprints might now be different and more accurate.","message":"The behavior of `Compound.fingerprint` was corrected in v1.0.4 to align with the CACTVS fingerprint specification. Users relying on outputs from older versions might observe different fingerprint values.","severity":"gotcha","affected_versions":"Before 1.0.4"},{"fix":"Ensure `http_proxy` and `https_proxy` environment variables are correctly set for system-wide proxy use, or explore `requests` library documentation for direct proxy configuration if `pubchempy` specific methods are not available for advanced proxy setups.","message":"Proxy configuration was a known issue in older versions (addressed in v1.0.4). While PubChemPy leverages `requests` for HTTP, direct proxy configuration might still be needed via environment variables (`http_proxy`, `https_proxy`) or by passing a `proxies` dictionary to `requests` if direct `pubchempy` support is lacking for a specific function.","severity":"gotcha","affected_versions":"Before 1.0.4, potential for all versions if environment variables are not set correctly."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}