Skip to content

Python SDK

Python is the primary automation language for many MolTrace users, so every example on this page must be complete, runnable, and verified against the sandbox API before customer release.

Terminal window
pip install moltrace
from moltrace import MolTrace
client = MolTrace(api_key="mt_sk_live_YOUR_KEY")

For production scripts, prefer environment-based configuration:

from moltrace import MolTrace
client = MolTrace() # reads MOLTRACE_API_KEY
analysis = client.analyses.create(
fid_path="./data/batch_001/fid",
acqus_path="./data/batch_001/acqus",
nucleus="1H",
instrument="bruker",
)
result = client.analyses.wait(analysis.id, timeout=120)
print(f"Confidence: {result.confidence}%")
print(f"Peaks detected: {len(result.peaks)}")
print(f"Impurities: {len([p for p in result.peaks if p.category == 'impurity'])}")
client.reports.download(
analysis_id=result.id,
format="pdf",
jurisdiction="FDA", # FDA, EMA, PMDA, or Health Canada after verification
output_path="./reports/batch_001_report.pdf",
)
print("Report saved.")
  • Upload and process one Bruker FID.
  • Poll an analysis until complete.
  • Retrieve the peak table.
  • Download a report.
  • Batch upload a directory of spectra with retry handling.
ErrorLikely causeFix
UnauthorizedMissing or invalid API key.Rotate the key and verify MOLTRACE_API_KEY.
ValidationErrorMissing acqus file or invalid enum.Upload complete instrument metadata and use documented enum values.
RateLimitExceededToo many concurrent uploads.Reduce parallel jobs or request a higher limit.