Skip to main content

Error-tolerant USFM 3.x parser

Project description

usfm3

usfm3 is a Python binding for the Rust usfm3 parser.

It exposes a staged API so live-editor code can stay on tokens/CST until it actually needs AST-backed output.

Installation

pip install usfm3

Quick Start

import usfm3

parsed = usfm3.parse(text)

tokens = usfm3.tokenize(text)
cst = usfm3.parse_cst(text)
ast_document = usfm3.parse_ast(text, diagnostics=True)

ast = parsed.ast()
source_map = parsed.source_map()
diagnostics = parsed.diagnostics

usj = parsed.to_usj()
usj_with_spans = parsed.to_usj(spans=True)
usx = parsed.to_usx()
usfm = parsed.to_usfm()
vref = parsed.to_vref()

API

usfm3.parse(usfm: str, diagnostics: bool = False) -> ParsedDocument

Returns a lazy parsed handle.

usfm3.parse_cst(usfm: str) -> dict

Returns a JSON-friendly CST tree.

usfm3.parse_ast(usfm: str, diagnostics: bool = False) -> dict

Returns:

{
    "ast": ...,
    "source_map": ...,
    "diagnostics": list | None,
}

usfm3.tokenize(usfm: str) -> list[dict]

Returns token spans suitable for editor tooling.

ParsedDocument

  • cst() -> dict
  • ast() -> dict
  • source_map() -> dict
  • to_usj(spans: bool = False) -> dict
  • to_usx() -> str
  • to_usfm() -> str
  • to_vref() -> dict[str, str]
  • diagnostics -> list[dict] | None

Notes

  • Diagnostics are only computed when diagnostics=True.
  • Diagnostics are a flat list with severity, code, message, span, and optional anchor_cst.
  • AST nodes do not include spans.
  • spans=True on to_usj() derives inline span data from the source map.

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.2.1.tar.gz (81.5 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.2.1-cp313-cp313-win_amd64.whl (292.3 kB view details)

Uploaded CPython 3.13Windows x86-64

usfm3-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (442.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

usfm3-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (434.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

usfm3-0.2.1-cp313-cp313-macosx_11_0_arm64.whl (389.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: usfm3-0.2.1.tar.gz
  • Upload date:
  • Size: 81.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for usfm3-0.2.1.tar.gz
Algorithm Hash digest
SHA256 2a7f0c5a18f2a39f09ebb666bd10389d28844d42aada10ffe90bf7a714744c55
MD5 d27e1d6285c8648329daecf05cb06cc8
BLAKE2b-256 1452017a60d3bb6d07a529596bdef5a346acbf68ccea3eaf90ed244c8d1f856b

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.2.1.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.2.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: usfm3-0.2.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 292.3 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for usfm3-0.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 21f84a2e331c4acdebfae2a70c25eaf0e9d44089d25b73616154f9198720064c
MD5 9e6f16a65b6d64707f3c97a7f414c708
BLAKE2b-256 c5c01b43af749b6bb17b50b055cdb4a8f724e1648c21689f3601379da19eccca

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for usfm3-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f5d7f76a702147b5ac7b2b7e72d83575d9abb6ac6f78c6339710005d579fc705
MD5 28a04e2c43a68c8cc9406100a9bfa711
BLAKE2b-256 c9d4041112910d637bad950798000d25632a4a7a1cdebead81e8ba1d6a668279

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.2.1-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.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for usfm3-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 03ef68e1f631f09ce77fb12299219e6feb6c62e4102dfea3b71e6095994acb29
MD5 f078c426f621e29a334a54a6e598127f
BLAKE2b-256 b13bf613c49bc638f79b9397a7e61467301d96815b4e3cb4cfd335ec4c285356

See more details on using hashes here.

Provenance

The following attestation bundles were made for usfm3-0.2.1-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.2.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for usfm3-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 06a26637ff9711ad43ba60365f626a1749301ea0fe7d18c8a1be5056b1bd2b1e
MD5 427c657ba71e473651dfa6ae061e7e93
BLAKE2b-256 30f549228d5080d990c87c47a64d491fec644b53a2142a2a17401340d9ed7dec

See more details on using hashes here.

Provenance

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