Data Models and Exceptions (models)ο
This module is the core of the libraryβs data contract, responsible for enforcing data integrity and providing clear error signals. It leverages Pydantic to transform unstructured API responses into robust, type-safe Python objects.
By defining clear data models, this module ensures that all data consumed by the application layer is valid and predictable.
Data Models
- class ChemInformant.models.Compound(*, cid: int, input_identifier: str | int, MolecularFormula: str | None = None, MolecularWeight: float | None = None, CanonicalSMILES: str | None = None, IsomericSMILES: str | None = None, IUPACName: str | None = None, XLogP: float | None = None, cas: str | None = None, synonyms: list[str] = <factory>)[source]ο
Bases:
BaseModelA Pydantic model representing a curated view of a PubChem compound.
This container holds the most commonly used fields for a single compound with runtime type validation. It is intentionally a subset of the full PubChem property catalog; for the complete ~40 properties use
ChemInformant.get_properties()withall_properties=Truewhich returns a DataFrame.- pubchem_urlο
A computed property with the direct link to the compoundβs PubChem page.
- classmethod to_float(v: Any) float | None[source]ο
Validator to safely convert string values to float.
- model_config = {'extra': 'ignore', 'populate_by_name': True, 'validate_by_alias': True, 'validate_by_name': True}ο
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Custom Exceptions