Skip to main content

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 a dict
  • to_usx(): USX as an XML str
  • to_usfm(): normalized USFM as a str
  • to_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) -> dict
  • to_usx() -> str
  • to_usfm() -> str
  • to_vref() -> dict[str, str]
  • has_errors() -> bool
  • diagnostics -> list[Diagnostic]

Diagnostic

Each diagnostic has:

  • severity: "error", "warning", or "info"
  • code: machine-readable code such as "UnknownMarker"
  • message: human-readable message
  • start
  • end

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 nested spans object with node and optional code, number, and close ranges.
  • Invalid USFM is reported through diagnostics; parse() still returns a result.

Related Packages

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

usfm3-0.1.8.tar.gz (70.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

usfm3-0.1.8-cp313-cp313-win_amd64.whl (223.5 kB view details)

Uploaded CPython 3.13Windows x86-64

usfm3-0.1.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (380.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

usfm3-0.1.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (370.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

usfm3-0.1.8-cp313-cp313-macosx_11_0_arm64.whl (332.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file usfm3-0.1.8.tar.gz.

File metadata

  • Download URL: usfm3-0.1.8.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

Hashes for usfm3-0.1.8.tar.gz
Algorithm Hash digest
SHA256 fe13eb043252de2ca8b2df2e7950596787fb2881e06cc924cb8ad231179453a1
MD5 80be75253ef53cd197032821a8f78ee9
BLAKE2b-256 5fa2bec2cb94ab110a9b81321be666fd78cff9c5b8e6e7028e61156fa075d155

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.1.8.tar.gz:

Publisher: publish-pypi.yml on jcuenod/usfm3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usfm3-0.1.8-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: usfm3-0.1.8-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 223.5 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

Hashes for usfm3-0.1.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e1bc22a8b8ae9b216878bcdc183f2e1bce899dbc534f20625fbcb42b0614330f
MD5 612721dabcddcfce85f43e707352cf55
BLAKE2b-256 7b818d31f2e76d87e8a763a8a958eb4c07d4674bd6b501dc325e9a943b74ff25

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.1.8-cp313-cp313-win_amd64.whl:

Publisher: publish-pypi.yml on jcuenod/usfm3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usfm3-0.1.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for usfm3-0.1.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 16f764453c2673f63d68b10878216d79890138d8d61cf49fd88d8c3df09f63ab
MD5 81463bf802562f1b5ea4e35d67143c70
BLAKE2b-256 b3e19f6f4871aa714ded57d867074018f0791814de8e354e2197592de2da5d49

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.1.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-pypi.yml on jcuenod/usfm3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usfm3-0.1.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for usfm3-0.1.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1deaebaa2dc673780a765457d9cb662e812debd207a5d020f5b99781e6e3a64e
MD5 8e8daf1f5fcb1a53a8f87ddd9bf09dbb
BLAKE2b-256 140ebfeb8d59a841ea7bc991d6fe271293f3c4833ae761b4ee242b7b1698db23

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.1.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish-pypi.yml on jcuenod/usfm3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file usfm3-0.1.8-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for usfm3-0.1.8-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2fffb0b33e6e7892f5d061826fca57b2ad9822b159e8c64bfbfad985e43edc1c
MD5 96a35e0efb6baf28e62f54f977186199
BLAKE2b-256 ab8d869dccb8addaa479e364cb59c1491d8811a8122ee2b5b81067c3cfae0519

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.1.8-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish-pypi.yml on jcuenod/usfm3

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page