Skip to content

Python

Ruby
asciichem
gem install asciichemReference implementation.
TypeScript
asciichem
npm install asciichemPowers this page.
Pythonyou are here
asciichem
pip install asciichemZero runtime deps.
Terminal window
pip install asciichem
from asciichem import parse_text, ParseError
from asciichem.text import render
from asciichem.wire import to_model_json, from_model_json
from asciichem.smiles import parse_smiles, write_smiles
from asciichem.mathml import render_mathml
formula = parse_text("2H_2 + O_2 ->[heat] 2H_2O")
print(render(formula)) # canonical AsciiChem text (round-trip)
print(render_mathml(formula)) # presentation MathML (L2 goldens)
aspirin = parse_smiles("CC(=O)OC1=CC=CC=C1C(=O)O")
print(write_smiles(aspirin)) # deterministic — round-trips exactly
# Canonical wire form (asciichem-model v1) with lossless round-trip
wire = to_model_json(formula)
back = from_model_json(wire)
assert render(back) == render(formula)

Parse / reject · L0 emission · L1 text · L2 MathML · L2 SVG (SVG byte-exact with the TypeScript renderers) · L3 stereo (chirality, directional bonds) · SMILES · molfile — 100% of the shared corpus. Resolver, citation, and the linter are not yet claimed (asciichem-py#19 converges them from the Rust contract); InChI stays an engine seam. See the Implementations matrix for the full table.

The Python implementation is built for data and science workflows where heavy dependencies are liabilities:

  • One runtime dependency: parsanol — parsing runs on the parsanol family over the checksummed PARG artifact (the same artifact the Rust crate embeds; the rd grammar port is deleted, 0.1.2, asciichem-py#20). parsanol’s per-platform wheels vendor the native engine, so pip install stays clean.
  • Plain dataclasses — the model is @dataclass-shaped, introspectable with standard tools (dataclasses.asdict, pydantic if you must). No framework magic.
  • Wire form as the canonical I/O — round-trips via to_model_json/from_model_json for pipelines that already speak JSON.
  • Optional asciichem[inchi] extra — RDKit-backed InChI engine when you need to derive identity locally; off by default.
  • Three-pane live diff (above) — the parity is provable client-side.

github.com/asciichem/asciichem-py — zero runtime deps.

Play