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

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.0
File Size Uploaded Provenance Actions
usfm3-0.3.0.tar.gz 100.7 kB With provenance Details for usfm3-0.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for usfm3 0.3.0
File Actions
usfm3-0.3.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for usfm3-0.3.0-cp313-cp313-win_amd64.whl
usfm3-0.3.0-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.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
usfm3-0.3.0-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.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
usfm3-0.3.0-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for usfm3-0.3.0-cp313-cp313-macosx_11_0_arm64.whl

Total release size: 1.2 MB

Release files / usfm3-0.3.0.tar.gz

Download URL usfm3-0.3.0.tar.gz
Size 100.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c007caf35beaec8dfb76995698a95855ebd6480c7c213e1de6ffecbaaf9cd788
BLAKE2b-256 checksum
How to use checksums
19183c0fcd3929ebcb5fa3aa3e3f6b22947fa7937205accd38f322f7fa91f013
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 22, 2026.

Transparency log

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

Download URL usfm3-0.3.0-cp313-cp313-win_amd64.whl
Size 200.0 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
d9a4a971dab6b6dffc3cba4a9f6dfcffca0ace1425fb7f4b5f9db48886e7b9b9
BLAKE2b-256 checksum
How to use checksums
73e0aee65c1291583b88e7863798bc93ce8d9e32582f54ac6b40bb4c7041d189
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 22, 2026.

Transparency log

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

Download URL usfm3-0.3.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 318.5 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
7db6c3a6962f5f94978b9182d9df7760c6deeb00bf2986e4e818fcfefb56cc59
BLAKE2b-256 checksum
How to use checksums
17e55a29895fe1ce00444f9529d4ebf97fda79dc5dcc9bb82cad7032cc9d7449
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 22, 2026.

Transparency log

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

Download URL usfm3-0.3.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 313.7 kB
Tags CPython 3.13 Linux glibc 2.17+ ARM64
SHA-256 checksum
How to use checksums
202729291bb27b5a6f6a89f2521223dc75888e31d2c1a2949c53e328bc4ef82a
BLAKE2b-256 checksum
How to use checksums
4247f2f9cc5ca80a960b4aa10114319024e2cdb66483085f5aea9abf714f8c69
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 22, 2026.

Transparency log

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

Download URL usfm3-0.3.0-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
dc323e67b586116a6fe3019fc37054dd737af823cabe0b0d3e098bf9b0719ef3
BLAKE2b-256 checksum
How to use checksums
4163c60321bc2b75dc2d4709584b554a179d2522e47d969121636d169e1f487a
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 22, 2026.

Transparency log

Security for usfm3 0.3.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

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for usfm3-0.3.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 Oct 22, 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