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.0.tar.gz (79.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.2.0-cp313-cp313-win_amd64.whl (282.2 kB view details)

Uploaded CPython 3.13Windows x86-64

usfm3-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (441.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

usfm3-0.2.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (429.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

usfm3-0.2.0-cp313-cp313-macosx_11_0_arm64.whl (386.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: usfm3-0.2.0.tar.gz
  • Upload date:
  • Size: 79.7 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.0.tar.gz
Algorithm Hash digest
SHA256 2aa2fafcc098f053624c1888a649d7def750bcc3f3b29ff8183e8e5a1c3f28cc
MD5 453397c25816b40eb0884d54c9d70238
BLAKE2b-256 bc6f401a15ff26f823ce36516c68d01e2d92087a9aa3e57518ce33ecad207404

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: usfm3-0.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 282.2 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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 be703be20b3bd636252b5c1571f782d568074dd3b0c1923a691e39e44e2c8c85
MD5 542426ae56d17cb258fa47b035d6df11
BLAKE2b-256 bec8d60df368ef6437f2704cdffda643c4a8652330cc488ee51626ebe9402f18

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for usfm3-0.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7738a0aa9e0103df58b3b41733319966f1ef4e0afcd1cafcf8a9b98203e4d280
MD5 a40124c23f6117da5c43d391a184a731
BLAKE2b-256 651fe3cae34df7a2f7cd1ec7216a9c65779cfa48e1d79a3aee8e3ccd3876f48e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for usfm3-0.2.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 947aee4009862c5bf52fc481996b53828d2684d102008d4ca7e95468b8f34791
MD5 f54c613ee4aa3d84f8cb13c9d99ea901
BLAKE2b-256 bf05dba07f694a40ab86e27a79fe6b63aa4d43340b1c7300765399ba8df3a1c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for usfm3-0.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e80ceb5f18a6c9bb861e5490d868f206a0e429ef5be70deb69de4d3d8be8b267
MD5 aab3dc663f31ffadef66bee9be7e9fb4
BLAKE2b-256 642195394736a8f00d45782c030db393831d92fe6ddac81edfbd86c5135e6840

See more details on using hashes here.

Provenance

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