usfm3
usfm3 is a Python binding for the Rust usfm3 parser — an error-tolerant,
blazingly fast USFM 3.x parser.
A single parse() produces a flat tape; every output (USJ, USX, USFM, CST, vref,
diagnostics) is a cheap view over it. There is no separate token/AST/source-map
stage — the handle below is all you need.
Coming from 0.2? 0.3 is a rewrite:
tokenize,parse_ast,ast()andsource_map()are gone,diagnosticsis now a method with a flat result, and the CST has a new shape. See CHANGELOG.md.
Installation
pip install usfm3
Quick Start
import usfm3
doc = usfm3.parse(text) # diagnostics off (hot path)
doc = usfm3.parse(text, diagnostics=True) # opt into validation
doc = usfm3.parse(text, version="3.2") # select USFM version
usj = doc.to_usj() # dict
usx = doc.to_usx() # str (XML)
usfm = doc.to_usfm() # str (normalized USFM)
vref = doc.to_vref() # { "GEN 1:1": "In the beginning…", ... }
cst = doc.cst() # dict (concrete syntax tree, for editors)
diags = doc.diagnostics() # list (empty unless diagnostics=True)
# One-shot convenience:
cst = usfm3.parse_cst(text)
API
usfm3.parse(usfm: str, *, diagnostics: bool = False, version: str = "3.1") -> ParsedDocument
Parse into a lazy handle. Never raises on malformed input — the parser recovers,
and (when diagnostics=True) reports what it had to recover from. version is
"3.1" or "3.2".
usfm3.parse_cst(usfm: str, *, diagnostics: bool = False, version: str = "3.1") -> dict
One-shot: parse and return the concrete syntax tree.
ParsedDocument
cst() -> dict— concrete syntax tree (byte spans, marker category/role/closing, matching close token), for editor decoration and folding.to_usj() -> dict— USJ document.to_usx() -> str— USX (XML).to_usfm() -> str— normalized USFM.to_vref() -> dict[str, str]— verse-reference → cleaned text, in document order. Empty verses are dropped and duplicate references merged, so it is a faithful dictionary.diagnostics(*, offsets="chars") -> list[dict]— flat list of diagnostics. Empty unlessdiagnostics=Truewas passed.offsetsis"chars"(code points, the default),"utf16"or"utf8"(bytes).tape(*, offsets="chars") -> bytes— the flat tape packed as little-endianuint32s: an 8-word header, then 4 words per node. The numeric/vectorized view (numpy.frombuffer(doc.tape(), dtype="<u4")); for ordinary traversal usecst().
Module-level: parse, parse_cst, and tape_schema(*, version="3.1") — the kind and
marker tables needed to resolve the ids in a packed tape. The array index is the id.
Notes
- Diagnostics carry
severity("error" | "warning" | "info"), a stablecode, a humanmessage,start/end, and 1-basedline/column. - Offsets are code points for
diagnostics()andtape(), sosrc[d["start"]:d["end"]]is correct.cst()reports UTF-8 byte offsets. - vref text is version-correct: notes are excluded, character-marker tags are dropped (inner text kept), whitespace is collapsed.
License
MIT
Metadata
Release files for usfm3 0.3.1
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 |
|---|---|---|---|---|
| usfm3-0.3.1.tar.gz | 101.4 kB | With provenance | Details for usfm3-0.3.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| usfm3-0.3.1-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details for usfm3-0.3.1-cp313-cp313-win_amd64.whl |
| usfm3-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.17+ x86-64 | Details for usfm3-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| usfm3-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.17+ ARM64 | Details for usfm3-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| usfm3-0.3.1-cp313-cp313-macosx_11_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 11.0+ ARM64 | Details for usfm3-0.3.1-cp313-cp313-macosx_11_0_arm64.whl |
Total release size: 1.2 MB
Release files / usfm3-0.3.1.tar.gz
| Download URL | usfm3-0.3.1.tar.gz |
|---|---|
| Size | 101.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ca8f51b8b06665051e7ff3f86ff785908b613f817e0520bca2ccad195f4f647
|
|
BLAKE2b-256 checksum How to use checksums |
5d222873093db044df381262ddbdb070d2249f433ec5a1289beba8cacda1a085
|
| 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 Oct 27, 2026.
Transparency logRelease files / usfm3-0.3.1-cp313-cp313-win_amd64.whl
| Download URL | usfm3-0.3.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 199.1 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
16ec3fd76b1ba83e27449e5a25248f2bdabc79d763df18350875d2f5af48837a
|
|
BLAKE2b-256 checksum How to use checksums |
77f4395a06c39cbf644803820a2bb00bf30f1d6c2640aabe33694f858621e7d2
|
| 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 Oct 27, 2026.
Transparency logRelease files / usfm3-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | usfm3-0.3.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 317.8 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
64a46ee68f6ee1f1c63f38b48f6ad78dfdc711a898ea4f30ee553acb053be26b
|
|
BLAKE2b-256 checksum How to use checksums |
9b9b2a99bdd8731c721b25e1318aac09a21d534bbb5c0fd94fa3045564a89597
|
| 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 Oct 27, 2026.
Transparency logRelease files / usfm3-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | usfm3-0.3.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 312.9 kB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
1e2d410d111113bab823374f1686257554965a75ff32da28b5531a86ffe69493
|
|
BLAKE2b-256 checksum How to use checksums |
71f419eabe9e7e1d6339273539e40a597f43f98296384b50ccfa848e11949a11
|
| 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 Oct 27, 2026.
Transparency logRelease files / usfm3-0.3.1-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | usfm3-0.3.1-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 285.3 kB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
69938627064accfca7ac0387848dacfdc461b66e10f1b6e6340fb6a8156c305e
|
|
BLAKE2b-256 checksum How to use checksums |
c2ce3206a24bbfc049ae19043311bf9e48a01d71e3694cfae2226ca09bf908ef
|
| 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 Oct 27, 2026.
Transparency logSecurity for usfm3 0.3.1
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
All 5 files in this release have been uploaded with provenance metadata.
Attestation for usfm3-0.3.1.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 Oct 27, 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.