asciichem (Python)
Python implementation of AsciiChem — parse
ASCII chemistry into a semantic model (atoms, bonds, isotopes,
charges, reactions, electron configurations), then render canonical
text or the canonical wire JSON. The defining fix over AsciiMath:
^14C binds the isotope to the atom, never to a phantom {} carrier.
Strategy A of the ecosystem's language-binding
ADR:
a native implementation conforming to the shared contracts —
asciichem-model (v1 wire form) and asciichem-tests (the corpus
every implementation passes). This package, like the TypeScript one,
must agree with the reference on every corpus case.
Parsing runs on the parsanol family (TODO.v2/17 slice 9): the
grammar is NOT reimplemented here — asciichem.engine consumes the
checksummed AsciiChem PARG artifact (vendored at
src/asciichem/parg/asciichem.json, the same artifact the Rust core
embeds and the Ruby reference vendors) through
parsanol, the one runtime
dependency (its per-platform wheels vendor the native engine).
Usage
from asciichem import parse_text
from asciichem.text import render
from asciichem.wire import to_model_json, from_model_json
from asciichem.smiles import parse_smiles, write_smiles
formula = parse_text("2H_2 + O_2 ->[heat] 2H_2O")
aspirin = parse_smiles("CC(=O)OC1=CC=CC=C1C(=O)O") # same model, same renderers
write_smiles(aspirin) # deterministic writer; round-trips exactly
render(formula) # canonical AsciiChem text (round-trip contract)
to_model_json(formula) # asciichem-model v1 wire JSON
back = from_model_json(to_model_json(formula))
Identity, resolution, citation, linting (TODO.v2 07/08/10)
from asciichem import linter, citation, identifiers
from asciichem import resolver
from asciichem.inchi import RdkitEngine, set_engine # pip install 'asciichem[inchi]'
linter.run(parse_text("H_2 + O_2 -> H_2O")) # [error] Reaction is not balanced: O: 2 vs 1
resolver.resolve(value="50-78-2", convention="cas") # Substance with per-identifier provenance
citation.to_xml(substance) # dataset-type Relaton bibitem (through leptris)
identifiers.valid("cas", "50-78-2") # offline CAS checksum validation
Sources self-register (PubChem, OPSIN, CAS Common Chemistry — CC BY-NC 4.0, default-on per the maintainer decision of 2026-11-11); the transport is injectable for offline runs, the TTL cache lives in the user cache dir, and one dead endpoint never poisons the fan-out.
Conformance claim
Verified in CI against the asciichem-tests corpus and asciichem-model schemas (both cloned as siblings):
| Level | Claim |
|---|---|
| parse/reject | 100% — every corpus case parses or raises ParseError exactly as marked |
| L0 | 100% — emission validates against the v1 JSON Schemas |
| L1 | 100% — render(parse(s)) == s for every roundTrip case |
| L3 | 100% — @/@@ chirality, directional bonds; every stereo fixture |
| SMILES | 100% — ingestion + deterministic emission, every structure/smiles/* fixture |
| molfile | 100% — V2000 ingestion + emission, every structure/molfile/* fixture |
| L2 (MathML goldens) | 100% — byte-identical against the corpus goldens |
| linter | 100% — every engine-independent case plus this run's engine posture (suite 0.11.0); CI runs both postures (no-engine and rdkit) |
| resolver | 100% — recorded-source replay, provenance, TTL caching, per-source failure isolation (suite 0.11.0) |
| citation | 100% — byte-identical dataset bibitem goldens, emitted through leptris (suite 0.11.0) |
| CML round-trip | 100% — three-way (parse → CML → parse → text) every cml-roundtrip fixture (23/23), through leptris with the aci: extension channels (atom attributes, top-level constructs — crystal/spectrum/calculation/zmatrix/mechanism included, groups, reaction conditions) |
| mechanism flows | 100% — every mechanisms.json fixture's per-step electron-flow markers, keyed by step label (suite 0.11.0) |
| html / latex | byte parity with the reference formatters — gated through the CLI family's convert -t html / -t latex cases |
| cli | 100% — the offline command set (convert, lint + --json, validate, roundtrip, parse-cml, version, tree) at 22/22 (suite 0.11.0), dispatched in-process |
| Resolver / InChI | offline validators + engine seam — asciichem.inchi wraps RDKit via the inchi extra; live resolution needs network |
| rinchi (reaction identity) | 100% — the full 36-case corpus family byte-exact in the chemomer posture (derive: the five oracle lines from every RXNfile edge and the identifier line from every RDfile edge; decode: role-resolved components, forced-equilibrium readings order-free); CI runs both postures (no-engine skips with a reported posture) — asciichem.rinchi wraps the chemomer engine via the rinchi extra |
Conformance levels
Mapped onto the ecosystem's formal levels — see the levels document:
| Level | Claim |
|---|---|
| L0 notation | yes — parse/reject and canonical Text round-trip at 100% |
| L1 semantics | yes — wire emission validates against the v1 JSON Schemas (corpus L0 gate at 100%) |
| L2 render | yes — canonical text, wire, MathML goldens, SVG byte-exact with the TypeScript implementation |
| L3 stereo | yes — @/@@ chirality, directional bonds |
| L4 identity | engine seam + offline identity cross-check — linter diagnostics gate at 100% (engine-posture aware); derivation wraps RDKit via the inchi extra |
Development
pip install -e ".[dev]"
python -m pytest # unit + corpus conformance (siblings cloned)
License
BSD-2-Clause — same as the rest of the AsciiChem ecosystem.
Metadata
Release files for asciichem 1.2.13.0
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 |
|---|---|---|---|---|
| asciichem-1.2.13.0.tar.gz | 140.5 kB | With provenance | Details for asciichem-1.2.13.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asciichem-1.2.13.0-py3-none-any.whl | Python 3 | none | any | Details for asciichem-1.2.13.0-py3-none-any.whl |
Total release size: 267.6 kB
Release files / asciichem-1.2.13.0.tar.gz
| Download URL | asciichem-1.2.13.0.tar.gz |
|---|---|
| Size | 140.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f95c6a59837ca1a509e0ae765a54c4fe5fe21d7828d0f76f43de357b05b2d19
|
|
BLAKE2b-256 checksum How to use checksums |
b1f125f0416d4720cfeba6a46e333d41b45d4bb7a2e1ed2b7bbd045a4aa2c7c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / asciichem-1.2.13.0-py3-none-any.whl
| Download URL | asciichem-1.2.13.0-py3-none-any.whl |
|---|---|
| Size | 127.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6ca4408a4b028c3686e1dc103e8ddcbec79407fa95a0b5051288e2551cf7e94
|
|
BLAKE2b-256 checksum How to use checksums |
6a77f9d57d29aba4b75c77f8b33cd4ad191d573216d19b93218065bd04c7dd65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for asciichem 1.2.13.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for asciichem-1.2.13.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA 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.