Skip to main content

usfm-references

Build Status Coverage Status Python versions

Utilities for parsing, validating and manipulating USFM (Unified Standard Format Markers) references.

This library provides:

  • validators for USFM strings (verse, chapter, intro, multi references)
  • a Reference model for composing and formatting references

Requirements

Python 3.9 or newer. The project CI runs on 3.9–3.12.

Installation

Install from PyPI:

pip install usfm-references

Quick Usage

Validate USFM reference strings using the valid_ helpers:

from usfm_references import valid_verse, valid_chapter, valid_multi_usfm

valid_verse("GEN.1.1")               # True
valid_chapter("GEN.1")               # True
valid_multi_usfm("GEN.1.1+GEN.1.3")  # True

Get a book's canon grouping:

from usfm_references import convert_book_to_canon

convert_book_to_canon("GEN")  # 'ot'

Look up a USFM book code from an English book name or common abbreviation:

from usfm_references import convert_book_name_to_usfm

convert_book_name_to_usfm("Genesis")          # 'GEN'
convert_book_name_to_usfm("Gen")              # 'GEN'
convert_book_name_to_usfm("1 Samuel")         # '1SA'
convert_book_name_to_usfm("I Samuel")         # '1SA'
convert_book_name_to_usfm("Song of Solomon")  # 'SNG'
convert_book_name_to_usfm("Apocalypse")       # 'REV'
convert_book_name_to_usfm("GEN")              # 'GEN'  (USFM codes pass through)
convert_book_name_to_usfm("Not a book")       # None

The lookup is case-insensitive and ignores surrounding whitespace and trailing punctuation. Numbered books accept arabic, roman, and word forms (e.g. 1Sam, I Sam, First Samuel). Returns None for unrecognized input.

Reference Model

The Reference dataclass is a convenient way to parse, build and format USFM references. It normalizes verse ranges (they are kept sorted and merged when intersecting or adjacent).

Examples:

from usfm_references import Reference

Reference.from_string("GEN.1")                # whole chapter -> Reference(book='GEN', chapter=1)
Reference.from_string("GEN.1.1-3")            # verse range -> verses [(1, 3)]
Reference.from_string("GEN.1.1+GEN.1.3")      # multiple verses -> verses [(1, 1), (3, 3)]
Reference.from_string("GEN.INTRO1")           # intro chapter -> intro=1

# Overlapping/adjacent ranges are merged:
str(Reference.from_string("GEN.1.1+GEN.1.2+GEN.1.3"))  # 'GEN.1.1-3'

Development

For local development, create a venv and install dev dependencies (project uses pip-tools):

make venv

Run linting and formatting:

make lint

Run tests:

make test

A pre-commit hook is provided to lint and run tests before each commit. To install it, run:

(cd .git/hooks && ln -s ../../pre-commit pre-commit)

Metadata

Release files for usfm-references 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for usfm-references 3.1.1
File Interpreter ABI Platform
usfm_references-3.1.1-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / usfm_references-3.1.1-py2.py3-none-any.whl

Download URL usfm_references-3.1.1-py2.py3-none-any.whl
Size 9.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
54dc9aa1e77d95f744ecc8c315dc3f7988cb13b9ea4075c31d65d6d4688f4441
BLAKE2b-256 checksum
How to use checksums
6b0739f3459c0d7db04d7365d910f97642b1b2384593d19c3ea2b9d23e252bcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Security for usfm-references 3.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page