Skip to main content

Python SDK for the MolBuilder REST API

Project description

molbuilder-client

Python SDK for the MolBuilder REST API.

Install

pip install molbuilder-client

Requires Python 3.11+. The only runtime dependency is httpx.

Quickstart

from molbuilder_client import MolBuilder

client = MolBuilder(api_key="mb_...")

# Parse a SMILES string
mol = client.from_smiles("CCO", name="ethanol")
print(mol.id, mol.num_atoms)  # mol_xxxx 9

# Get molecular properties
props = client.get_properties(mol.id)
print(props.formula, props.molecular_weight)  # C2H6O 46.07

# Get 3D coordinates
structure = client.get_3d(mol.id)
for atom in structure.atoms:
    print(atom.symbol, atom.position)

# Look up an element
fe = client.get_element("Fe")
print(fe.name, fe.atomic_weight)  # Iron 55.845

# Retrosynthesis
plan = client.retrosynthesis("c1ccccc1O")  # phenol
print(plan.routes_found, plan.best_route.total_steps)

# Process evaluation
proc = client.process_evaluate("CCO", scale_kg=100.0)
print(proc.cost.total_usd, proc.cost.per_kg_usd)

Async usage

import asyncio
from molbuilder_client import AsyncMolBuilder

async def main():
    async with AsyncMolBuilder(api_key="mb_...") as client:
        mol = await client.from_smiles("CCO")
        props = await client.get_properties(mol.id)
        print(props.formula)

asyncio.run(main())

Error handling

All API errors raise typed exceptions that inherit from MolBuilderError:

from molbuilder_client import MolBuilder, ValidationError, RateLimitError

client = MolBuilder(api_key="mb_...")

try:
    client.from_smiles("not_valid")
except ValidationError as e:
    print(f"Bad SMILES: {e.message}")
except RateLimitError as e:
    print(f"Slow down! Retry after {e.retry_after}s")
HTTP Status Exception
401 AuthenticationError
403 ForbiddenError
404 NotFoundError
422 ValidationError
429 RateLimitError
500 ServerError
501/503 ServiceUnavailableError

API reference

Auth

Method Returns Description
register(email) APIKeyInfo Register a new free-tier API key
get_token() Token Exchange API key for a JWT

Molecule

Method Returns Description
from_smiles(smiles, name="") MoleculeInfo Parse SMILES into a molecule
get_properties(mol_id) MoleculeProperties Computed molecular properties
get_3d(mol_id) Molecule3D 3D coordinates and bonds

Elements

Method Returns Description
get_element(symbol) Element Look up element by symbol

Retrosynthesis

Method Returns Description
retrosynthesis(smiles, max_depth=5, beam_width=5) RetrosynthesisPlan Plan retrosynthetic routes

Process

Method Returns Description
process_evaluate(smiles, scale_kg=1.0, max_depth=5, beam_width=5) ProcessEvaluation Full process engineering report

Billing

Method Returns Description
create_checkout(plan) CheckoutSession Create Stripe checkout session
billing_status() BillingStatus Current subscription status

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

molbuilder_client-0.1.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

molbuilder_client-0.1.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file molbuilder_client-0.1.1.tar.gz.

File metadata

  • Download URL: molbuilder_client-0.1.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for molbuilder_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8256c2fb432a0ecd3c1257d7ec8bd9d78e7c6886abae4992e95b089f14cfc4f8
MD5 b3556f0b7896ed212964072ad43168ab
BLAKE2b-256 bff117f80a8ced30be1f87403812dad82aaa49b65fc95e1c9844abc3f317b390

See more details on using hashes here.

Provenance

The following attestation bundles were made for molbuilder_client-0.1.1.tar.gz:

Publisher: release-sdk.yml on Taylor-C-Powell/Molecule_Builder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file molbuilder_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for molbuilder_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 37d8a42bc08dd4bbff40a4b25ad1ffd58520b35d242dc1eca81a5d3c3b4826f6
MD5 97001782319047b99dcb343ba1a4a1f1
BLAKE2b-256 7b57fe9f245669d2158ed6626a8ebbb4659aa6df79a80b39c44bae96df929ec9

See more details on using hashes here.

Provenance

The following attestation bundles were made for molbuilder_client-0.1.1-py3-none-any.whl:

Publisher: release-sdk.yml on Taylor-C-Powell/Molecule_Builder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page