Skip to main content

USFM reference parser

Project description

USFMTC Module

Introduction

The USFMTC module is a module for reading and writing USFM scripture files in all their formats: USFM, USX and USJ. It is designed to be a reference implementation of the standard. It also has support for Scripture References.

import sys, usfmtc
from usfmtc.versification import cached_versification
from usfmtc.reference import Ref, RefList

engvrs = cached_versification("eng")   # can also be a path to a .vrs file
usxdoc = usfmtc.readFile(sys.argv[1])
usxdoc.canonicalise()
# usxdoc.reversify(engvrs, None)
usxdoc.saveAs(sys.argv[2])

r = Ref("ISA 9:1-4")      # returns a RefRange
canr = engvrs.remap(r, None)    # one way conversion
print(canr)     # prints "ISA 8:23-9:3"
rlist = RefList("JHN 3:16, GEN 1:1, PSA 23, ISA 53, PSA 23:1")
print(rlist.simplify())     # GEN 1:1; PSA 23; ISA 53; JHN 3:16
print(Ref("PSA 23").end())  # PSA 23:6
print(Ref("PSA 23:10").isvalid())   # False

newdoc = usxdoc.getrefs(Ref("PSA 23:2-4"))
print(newdoc.outUsfm(None))     # A new doc of just PSA 23:2-4

The internal representation of the data is as an ElementTree structure conforming to the USX standard.

See the tests/test_\*.py files for more examples. See also pydoc usfmtc.

Utilities

usfmtc comes with a few utilities:

  • usfmconv: Converts from one serialisation to another
  • usfmreversify: Change the versification of a file to something different
  • urnc2rng: Convert to relax-NG

Installation

python3 -m venv venv
source venv/bin/activate
pip install .

To install the dev profile with extra optional dependencies:

pip install .[dev]

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

usfmtc-0.4.4.tar.gz (119.5 kB view details)

Uploaded Source

Built Distribution

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

usfmtc-0.4.4-py3-none-any.whl (110.8 kB view details)

Uploaded Python 3

File details

Details for the file usfmtc-0.4.4.tar.gz.

File metadata

  • Download URL: usfmtc-0.4.4.tar.gz
  • Upload date:
  • Size: 119.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for usfmtc-0.4.4.tar.gz
Algorithm Hash digest
SHA256 e6dba8901bc57c709ae9b0500b07133daf0e3dc655220dfd01412eddd8bf3d28
MD5 d0c8692f7675b7bb56dcbe982f35b386
BLAKE2b-256 c12d5c7027d3c983c661b23a5a4faac544973e848e3ede72662b3638d62ddab7

See more details on using hashes here.

File details

Details for the file usfmtc-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: usfmtc-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 110.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for usfmtc-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2c69f3e0d5080a9022f19e49b5788a69996b5098c0a49abd77fcac54b80b5db5
MD5 7cc175790ad756b071e2131d57c30b86
BLAKE2b-256 023ab9f8fb3e6b1fd2e2ad05444a1e4adcb1fb2173188383da9f35afbcc9db40

See more details on using hashes here.

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