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.9.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.9-cp313-cp313-win_amd64.whl (221.6 kB view details)

Uploaded CPython 3.13Windows x86-64

usfm3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (380.3 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

usfm3-0.1.9-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.9-cp313-cp313-macosx_11_0_arm64.whl (331.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Hashes for usfm3-0.1.9.tar.gz
Algorithm Hash digest
SHA256 e2caebd80f526c978781469c88eaeca79d6ab1aa777dd95e303d9f1530bb3e4d
MD5 a7f7cc2a78789c0b740ca0fc2555e0ca
BLAKE2b-256 879569312cf45df743386e8fdb8d2151161508b62a6ec3c50ca42fbfb5ec4100

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.1.9.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.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

Hashes for usfm3-0.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d45884e94bde7aa4dfb83930c7818d5a9b50b023041c0dccb89501614fe3a40b
MD5 3fe87661b6bf8efbcce75521e13664f2
BLAKE2b-256 100eac817b5654c69ad8d293462449a014fd16a47926096a905c0c64b27ecbcf

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.1.9-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.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for usfm3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7d00738ad7908c3215ca990030ac67cce27a342799faaf79c13ecbfefa212bb7
MD5 e13adab4157b3576277009de3b93766e
BLAKE2b-256 e745892875989c84bab4c60cc947d2e4c2dc6a54c350db42056197524d8057ce

See more details on using hashes here.

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

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.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for usfm3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 20273198735451c3ff0e726a26f6de866884c60f6e5297c2605a7c83d8d4977f
MD5 9ea300e9ff68733244f092b2f7b9173d
BLAKE2b-256 1e286d6f4810a63f1159c8541e38334f43f14b6e2efdbd94c14874f333e78a6e

See more details on using hashes here.

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

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.9-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for usfm3-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b5828bab6a5e1ff47fca6231064fa8a00f8c102195352fbbe63c3552eb71f4b3
MD5 5d5a9be1e541104982a767a547f19c0a
BLAKE2b-256 737e14fb4a65c14d25ec3d846cc69c5e30d6dcb075e8636af9ee00269c9cf53e

See more details on using hashes here.

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

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