Skip to main content

VersiRef

VersiRef is a Python package for sophisticated parsing, manipulation, and printing of references to the Bible.

Features

  • Parse and manipulate Bible references.
  • Support for different versification systems (e.g., original language [BHS + UBS GNT], "English," LXX, Vulgate).
  • Query information about chapters and verses in different books of the Bible.

Psalm 151 is written under the Psalms name ("Ps 151:1") whether a versification counts it as PSA 151 or as the separate book PS2.

Overview of versiref classes

  • BibleRef represents a sequence of verse ranges within one or more books of the Bible.
    • It has a Versification and a tuple of VerseRanges. Without a Versification it can still be formatted, but not validated, mapped, or given verse keys.
    • It is immutable and hashable, and two references are equal if they cite the same verses in the same versification, however they were written.
  • VerseRange is a range from one RefPoint to another, each of which names a book and optionally a chapter and a verse.
    • A point with no verse is a whole chapter, and one with no chapter is a whole book.
    • The two points may be in different books, as in "Matt–John" or "1 Sam 31:1–2 Sam 1:27".
  • Versification represents a division of the Bible into chapters and verses. Different texts of the Bible do this differently.
  • RefStyle defines separators and book names or abbreviations to use in formatting or parsing a reference.
    • This gives the package the versatility to handle different styles and languages.
  • RefParser creates PEG parsers based on a RefStyle and Versification.
    • These can be used to parse a single reference or to find all references in a long string, e.g., the content of a text file.

License

Examples

Convert references from one style to another

from pyparsing import ParseException
from versiref import RefParser, RefStyle, Versification

def convert_reference(reference: str) -> None:
    """Parse argument and print result."""
    # Expect SBL style references
    sbl_style = RefStyle.named("en-sbl")
    # Use typical versification for English Bibles
    versification = Versification.named("eng")
    # Build parser for style
    parser = RefParser(sbl_style, versification)
    # Use Italian CEI Bible style for output
    cei_style = RefStyle.named("it-cei")
    try:
        ref = parser.parse(reference, silent=False)
        # Check whether it refers to verse ranges that exist
        if not ref.is_valid():
            print(f"Warning: {reference} is not a valid reference.")
        print(ref.format(cei_style))
    except ParseException as e:
        print(f"Could not parse reference: {reference}")
        print(e)

# Prints "Gv 7,53–8,11"
convert_reference("John 7:53–8:11")

Look for references in a string

from versiref import RefParser, RefStyle, Versification, standard_names

def scan_string(content: str) -> None:
    """Count and print the Bible references in content."""
    # Use SBL abbreviations
    sbl_abbrevs = standard_names("en-sbl_abbreviations")
    style = RefStyle(names=sbl_abbrevs)
    # But also recognize abbreviations from the Chicago Manual of Style
    style.also_recognize("en-cmos_short")
    # Use typical versification for English Bibles
    versification = Versification.named("eng")
    # Build parser for style
    parser = RefParser(style, versification)
    count = 0
    for ref, start, end in parser.scan_string(content):
        # Check for out-of-range chapter or verse
        if not ref.is_valid():
            print(f"Warning: {ref.format(style)} is not a valid reference.")
        else:
            # Print in SBL style
            print(ref.format(style))
        count += 1
    print(f"Found {count} references.")

text = """
Today's readings are Acts 2:1-11; Ps 104:1,24,29-30,31,34; 1 Cor 12:3b-7,12-13; Jn 20:19-23.
The prophecy in Is 7:10-14 is important background for Lk 1:26-38.
The Septuagint has a Ps 118:120, but English Bibles don't.
"""
scan_string(text)

Output:

Acts 2:1–11; Ps 104:1, 24, 29–30, 31, 34; 1 Cor 12:3b–7, 12–13; John 20:19–23
Isa 7:10–14
Luke 1:26–38
Warning: Ps 118:120 is not a valid reference.
Found 4 references.

Map a reference to a different versification

from versiref import RefParser, RefStyle, Versification

# Parse a reference using typical English versification
eng = Versification.named("eng")
style = RefStyle.named("en-sbl")
parser = RefParser(style, eng)
ref = parser.parse("Ps 23:1-3")

# Map to Septuagint versification
lxx = Versification.named("LXX")  # Names are case insensitive.
mapped = ref.map_to(lxx)

# The Psalm number is one lower
assert mapped is not None
print(mapped.format(style))  # Ps 22:1-3

Recognize a versification designator

A reference is sometimes followed by a designator such as Vulg. or (LXX) signaling that it uses a different versification. Teach a RefStyle to recognize these, and the parser returns a BibleRef in the named versification for those references while keeping its default for the rest.

from versiref import RefParser, RefStyle, Versification, standard_names

style = RefStyle(names=standard_names("en-sbl_abbreviations"))
# Map each designator to a versification id.
style.also_recognize_versifications({"Vulg.": "vulgata", "LXX": "lxx", "(LXX)": "lxx"})
parser = RefParser(style, Versification.named("eng"))

# Susanna is Daniel 13 in the Vulgate but invalid under English numbering.
assert parser.parse("Dan 13:23").is_valid() is False
assert parser.parse("Dan 13:23 Vulg.").is_valid() is True
assert parser.parse("Dan 13:23 Vulg.").versification.identifier == "vulgata"

The designator is recognized only at the end of a whole reference and applies to every book in it. The map is part of RefStyle, so it can be declared in a style config file via a versification_identifiers block and reused across a corpus.

Development

This project uses uv for project setup and dependencies.

To build the API reference, run

uv run python scripts/build_api_md.py

This creates or updates src/versiref/docs/api.md by walking the package with griffe. The file is generated (not hand-edited) and is git-ignored; it ships inside the package as bundled documentation alongside index.md (a copy of this README) and cli.md, reachable at runtime via versiref docs.

Run that step before building the HTML site, which renders the same bundled docs:

uv run mkdocs build

Metadata

Release files for versiref 0.15.0

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

Source distribution (sdist)

Source distribution for versiref 0.15.0
File Size Uploaded Provenance Actions
versiref-0.15.0.tar.gz 111.9 kB With provenance Details for versiref-0.15.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for versiref 0.15.0
File Interpreter ABI Platform Actions
versiref-0.15.0-py3-none-any.whl Python 3 none any Details for versiref-0.15.0-py3-none-any.whl

Total release size: 244.2 kB

Release files / versiref-0.15.0.tar.gz

Download URL versiref-0.15.0.tar.gz
Size 111.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bebf68afd768f52894b1464d424e2a2d359f0254b25edc35218fe175f5d7b622
BLAKE2b-256 checksum
How to use checksums
52c41f8a4efc18f393e687dc9fc0f7624b70f25f6419124790c9d8dbe155cce9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / versiref-0.15.0-py3-none-any.whl

Download URL versiref-0.15.0-py3-none-any.whl
Size 132.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61a2bfd97df4cb246c156b52c706658cd41f16d5c46fab9c01260470211b1b44
BLAKE2b-256 checksum
How to use checksums
c00ebe3815be2490071fffc8052c77a8096587f62e7e3db90959a39f6e775b71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for versiref 0.15.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for versiref-0.15.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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