Error-tolerant USFM 3.x parser
Project description
usfm3
usfm3 is a Python parser for USFM 3.x.
It turns USFM into Python-friendly outputs:
to_usj(spans=False): USJ as adictto_usx(): USX as an XMLstrto_usfm(): normalized USFM as astrto_vref(): a verse-text map like{"GEN 1:1": "In the beginning..."}
The parser is error-tolerant, so malformed input still produces a parse result with structured diagnostics.
Built in Rust for speed, with native Python bindings via PyO3.
Installation
pip install usfm3
Requires Python 3.9+.
Quick Start
import usfm3
text = r"""\id GEN
\c 1
\p
\v 1 In the beginning God created the heavens and the earth.
"""
result = usfm3.parse(text)
print(result.to_vref()["GEN 1:1"])
for diagnostic in result.diagnostics:
print(
f"[{diagnostic.severity}] {diagnostic.code}: "
f"{diagnostic.message} ({diagnostic.start}..{diagnostic.end})"
)
usj = result.to_usj()
usj_with_spans = result.to_usj(spans=True)
usx = result.to_usx()
normalized_usfm = result.to_usfm()
Validation
parse() runs semantic validation by default, so diagnostics can include issues such as
chapter and verse sequencing, invalid attributes, or mismatched milestones.
If you only want parsing, disable validation:
result = usfm3.parse(text, validate=False)
API Summary
usfm3.parse(usfm: str, validate: bool = True) -> ParseResult
Parses a USFM string and returns a ParseResult.
ParseResult
to_usj(spans: bool = False) -> dictto_usx() -> strto_usfm() -> strto_vref() -> dict[str, str]has_errors() -> booldiagnostics -> list[Diagnostic]
Diagnostic
Each diagnostic has:
severity:"error","warning", or"info"code: machine-readable code such as"UnknownMarker"message: human-readable messagestartend
start and end are byte offsets into the original source.
Notes
to_vref()returns plain verse text keyed by references such as"GEN 1:1".to_usfm()returns normalized USFM, so whitespace may be regularized.- When
spans=True, structural USJ nodes include a nestedspansobject withnodeand optionalcode,number, andcloseranges. - Invalid USFM is reported through
diagnostics;parse()still returns a result.
Related Packages
- Rust crate: crates.io/crates/usfm3
- JavaScript/TypeScript package: npmjs.com/package/usfm3
- Source code: github.com/jcuenod/usfm3
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file usfm3-0.1.9.tar.gz.
File metadata
- Download URL: usfm3-0.1.9.tar.gz
- Upload date:
- Size: 70.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2caebd80f526c978781469c88eaeca79d6ab1aa777dd95e303d9f1530bb3e4d
|
|
| MD5 |
a7f7cc2a78789c0b740ca0fc2555e0ca
|
|
| BLAKE2b-256 |
879569312cf45df743386e8fdb8d2151161508b62a6ec3c50ca42fbfb5ec4100
|
Provenance
The following attestation bundles were made for usfm3-0.1.9.tar.gz:
Publisher:
publish-pypi.yml on jcuenod/usfm3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
usfm3-0.1.9.tar.gz -
Subject digest:
e2caebd80f526c978781469c88eaeca79d6ab1aa777dd95e303d9f1530bb3e4d - Sigstore transparency entry: 1186097624
- Sigstore integration time:
-
Permalink:
jcuenod/usfm3@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/jcuenod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file usfm3-0.1.9-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: usfm3-0.1.9-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 221.6 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d45884e94bde7aa4dfb83930c7818d5a9b50b023041c0dccb89501614fe3a40b
|
|
| MD5 |
3fe87661b6bf8efbcce75521e13664f2
|
|
| BLAKE2b-256 |
100eac817b5654c69ad8d293462449a014fd16a47926096a905c0c64b27ecbcf
|
Provenance
The following attestation bundles were made for usfm3-0.1.9-cp313-cp313-win_amd64.whl:
Publisher:
publish-pypi.yml on jcuenod/usfm3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
usfm3-0.1.9-cp313-cp313-win_amd64.whl -
Subject digest:
d45884e94bde7aa4dfb83930c7818d5a9b50b023041c0dccb89501614fe3a40b - Sigstore transparency entry: 1186097679
- Sigstore integration time:
-
Permalink:
jcuenod/usfm3@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/jcuenod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file usfm3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: usfm3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 380.3 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d00738ad7908c3215ca990030ac67cce27a342799faaf79c13ecbfefa212bb7
|
|
| MD5 |
e13adab4157b3576277009de3b93766e
|
|
| BLAKE2b-256 |
e745892875989c84bab4c60cc947d2e4c2dc6a54c350db42056197524d8057ce
|
Provenance
The following attestation bundles were made for usfm3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-pypi.yml on jcuenod/usfm3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
usfm3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
7d00738ad7908c3215ca990030ac67cce27a342799faaf79c13ecbfefa212bb7 - Sigstore transparency entry: 1186097695
- Sigstore integration time:
-
Permalink:
jcuenod/usfm3@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/jcuenod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file usfm3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: usfm3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 370.9 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20273198735451c3ff0e726a26f6de866884c60f6e5297c2605a7c83d8d4977f
|
|
| MD5 |
9ea300e9ff68733244f092b2f7b9173d
|
|
| BLAKE2b-256 |
1e286d6f4810a63f1159c8541e38334f43f14b6e2efdbd94c14874f333e78a6e
|
Provenance
The following attestation bundles were made for usfm3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
publish-pypi.yml on jcuenod/usfm3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
usfm3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
20273198735451c3ff0e726a26f6de866884c60f6e5297c2605a7c83d8d4977f - Sigstore transparency entry: 1186097640
- Sigstore integration time:
-
Permalink:
jcuenod/usfm3@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/jcuenod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Trigger Event:
push
-
Statement type:
File details
Details for the file usfm3-0.1.9-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: usfm3-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 331.8 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5828bab6a5e1ff47fca6231064fa8a00f8c102195352fbbe63c3552eb71f4b3
|
|
| MD5 |
5d5a9be1e541104982a767a547f19c0a
|
|
| BLAKE2b-256 |
737e14fb4a65c14d25ec3d846cc69c5e30d6dcb075e8636af9ee00269c9cf53e
|
Provenance
The following attestation bundles were made for usfm3-0.1.9-cp313-cp313-macosx_11_0_arm64.whl:
Publisher:
publish-pypi.yml on jcuenod/usfm3
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
usfm3-0.1.9-cp313-cp313-macosx_11_0_arm64.whl -
Subject digest:
b5828bab6a5e1ff47fca6231064fa8a00f8c102195352fbbe63c3552eb71f4b3 - Sigstore transparency entry: 1186097663
- Sigstore integration time:
-
Permalink:
jcuenod/usfm3@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/jcuenod
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@4504bd418ec155e29c2a39dd5a986fa66cb0de73 -
Trigger Event:
push
-
Statement type: