Skip to main content

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() and source_map() are gone, diagnostics is 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 unless diagnostics=True was passed. offsets is "chars" (code points, the default), "utf16" or "utf8" (bytes).
  • tape(*, offsets="chars") -> bytes — the flat tape packed as little-endian uint32s: an 8-word header, then 4 words per node. The numeric/vectorized view (numpy.frombuffer(doc.tape(), dtype="<u4")); for ordinary traversal use cst().

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 stable code, a human message, start/end, and 1-based line/column.
  • Offsets are code points for diagnostics() and tape(), so src[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.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for usfm3 0.3.2
File Size Uploaded Provenance Actions
usfm3-0.3.2.tar.gz 106.1 kB With provenance Details for usfm3-0.3.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for usfm3 0.3.2
File Actions
usfm3-0.3.2-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for usfm3-0.3.2-cp313-cp313-win_amd64.whl
usfm3-0.3.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for usfm3-0.3.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
usfm3-0.3.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ ARM64 Details for usfm3-0.3.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
usfm3-0.3.2-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for usfm3-0.3.2-cp313-cp313-macosx_11_0_arm64.whl

Total release size: 1.2 MB

Release files / usfm3-0.3.2.tar.gz

Download URL usfm3-0.3.2.tar.gz
Size 106.1 kB
Tags Source
SHA-256 checksum
How to use checksums
24bcf8944a01f463b61be80867551d38b0ebec062cc3ba45496c9e83518b649e
BLAKE2b-256 checksum
How to use checksums
e3f2966e65a628eb0ebc10f7229a012bf0439efc41e81124fa6d3582505b697e
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 2, 2026.

Transparency log

Release files / usfm3-0.3.2-cp313-cp313-win_amd64.whl

Download URL usfm3-0.3.2-cp313-cp313-win_amd64.whl
Size 205.5 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
5676967877c6cf09c5d469b310f76fc9ee04d6d96dd7da69d9efe6537e8c6a13
BLAKE2b-256 checksum
How to use checksums
6dfdb7001cde4c05f3543d80dd1f8dbec88c2db56b56b42749987470b987e1af
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 2, 2026.

Transparency log

Release files / usfm3-0.3.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL usfm3-0.3.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 324.8 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ca433d6ffdb17815bec61a5b0b5cb8d06fabcc241b190a7fce1fe199b2dc09e5
BLAKE2b-256 checksum
How to use checksums
37b8278371feade0e3bfa39eed743528fec20c07c73214245e0683d3624c4bb0
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 2, 2026.

Transparency log

Release files / usfm3-0.3.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL usfm3-0.3.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 318.6 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
1a1a6c1a696f46186da752f1a1c66bb67f8a6b85c04070f643356991831afa04
BLAKE2b-256 checksum
How to use checksums
076f135e9c16cf3ea5e47728fac824c08a15b8a984c6c7dbc9199d6179f4eae6
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 2, 2026.

Transparency log

Release files / usfm3-0.3.2-cp313-cp313-macosx_11_0_arm64.whl

Download URL usfm3-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
Size 291.7 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
419d3f8e1fb7b6b148e0b864eccad364ab2681f5bfb9017574f1fb2eb89331e1
BLAKE2b-256 checksum
How to use checksums
35585dfc2cfe1ce2ec85c9dcbf44c4874a9cb3b657ebc796808e892d5e2df4bf
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 2, 2026.

Transparency log

Security for usfm3 0.3.2

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.

Select from 5 files

Attestation for usfm3-0.3.2.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 2, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page