Skip to main content

bible-io-references-py

Parse, validate, format, serialize, and extract multilingual Bible references in Python.

The package is dependency-free at runtime, fully typed, and supports Python 3.10+. Its data model covers 83 books: the 66-book Protestant canon plus the separately modelled Catholic and Orthodox additions used by the companion Dart and Rust packages.

Features

  • Checked immutable verse and range values; chapter and verse numbers are limited to 1..999, and ranges must be canonically ascending.
  • Narrow references such as John 3:16, John 3:16-18, John 3:16-4:2, and John 3:16-Acts 1:2.
  • Rich passages such as John, John 3, John 3-4, John 3:16,18-20,4:1-5:2, and semicolon-separated sequences.
  • Parsing data for English plus Arabic, Chinese, French, German, Hebrew, Hindi, Indonesian, Korean, Portuguese, Russian, Spanish, and Tagalog.
  • Unicode normalization for fullwidth forms, Arabic/Persian digits, punctuation and dash variants, Unicode spaces, bidi controls, and vocalization/combining marks.
  • Configurable aliases, language preference, ambiguity rejection, and detection metadata.
  • Localized long/short formatting, stable dictionary serialization, and complete OSIS/USFM identifiers for all 83 books.
  • Prose extraction, one-pass replacement, and Markdown linkification with exact Python string offsets.
  • A single-value and streaming batch CLI with text, JSON, OSIS, and USFM output.

Installation

pip install bible-io-references

References

Use the checked value types when you know the expected shape, or parse_reference when either a verse or range is valid:

from bible_io_references import VerseRangeRef, VerseRef, parse_reference

verse = VerseRef.parse("John 3:16")
same_book = VerseRangeRef.parse("John 3:16-4:2")
cross_book = parse_reference("John 21:25-Acts 1:2")

assert str(verse) == "John 3:16"
assert verse.copy_with(verse=17) == VerseRef.parse("John 3:17")
assert VerseRef.try_parse("not a reference") is None

from_str(...) remains available as a compatibility alias. Direct construction is checked too:

from bible_io_references import Book, VerseRef

ref = VerseRef(Book.John, 3, 16)
# VerseRef(Book.John, 0, 16) raises ValueError

Invalid input raises ParseVerseRefError. For expected failures, use a parse result instead of exceptions:

from bible_io_references import ReferenceParseErrorCode, parse_reference_result

result = parse_reference_result("Acts 1:2-John 3:16")
assert not result.is_success
assert (
    result.error_or_none.error_code
    is ReferenceParseErrorCode.CROSS_BOOK_RANGE_NOT_ASCENDING
)

The narrow parser deliberately rejects chapter-only input such as John 3; use the passage API for that grammar.

Rich passages

from bible_io_references import Passage, PassageSequence, VersePassage

passage = Passage.parse("John 3:16,18-20,4:1-5:2")
sequence = Passage.parse("John 3:16; Acts 2:1-4; Romans 8")

assert isinstance(passage, VersePassage)
assert isinstance(sequence, PassageSequence)
assert Passage.from_dict(sequence.to_dict()) == sequence

Whole books, chapters, inclusive chapter ranges, verse selections, and sequences use BookPassage, ChapterPassage, VersePassage, and PassageSequence. In the five one-chapter books, a bare number is a verse: Jude 3 means Jude 1:3. PassageParser(single_chapter_books=...) can replace that set.

Languages, aliases, and ambiguity

Automatic mode searches English first and then the 12 localized packs. Pass an explicit language to prevent cross-language abbreviation matches:

from bible_io_references import Language, VerseRef

assert VerseRef.parse("Juan 3:16", language="es") == VerseRef.parse("John 3:16")
assert VerseRef.parse("约翰福音3:16", language=Language.CHINESE).chapter == 3

Language strings accept display names, short codes, canonical identifiers, and valid identifier/locale suffixes such as spa-rva-1602 and es-MX. Reserved enum languages without a bundled term pack report is_parsing_supported == False; formatting them falls back to English.

For application aliases and deterministic collision handling, reuse a ReferenceParser:

from bible_io_references import (
    Book,
    ReferenceAmbiguityPolicy,
    ReferenceParser,
)

parser = ReferenceParser(
    aliases={"favorite": Book.John},
    preferred_languages=["es"],
    ambiguity_policy=ReferenceAmbiguityPolicy.REJECT,
)

parsed = parser.parse_result("favorite 3:16")
assert parsed.is_success
assert parsed.metadata_or_none.book_matches[0].selected.is_custom

Custom global aliases outrank bundled terms. Language-specific aliases can be supplied with aliases_by_language. Parser inputs are copied into immutable mappings, so a configured parser is safe to reuse.

Unicode input and source spans

Normalization is applied before reference and passage parsing:

from bible_io_references import VerseRef, normalize_reference_input_detailed

assert VerseRef.parse("John٣:١٦") == VerseRef.parse("John 3:16")

normalized = normalize_reference_input_detailed("A\u200fB")
assert normalized.normalized_text == "AB"
assert normalized.map_normalized_span(1, 2).text_from(normalized.original_text) == "B"

Offsets and spans use native Python string indices (Unicode code points), not UTF-16 code units.

Localized formatting

from bible_io_references import BookNameStyle, ReferenceFormatter, VerseRef

ref = VerseRef.parse("John 3:16")
spanish = ReferenceFormatter.for_language("es")
short = spanish.with_book_name_style(BookNameStyle.SHORT)

assert spanish.format(ref) == "Juan 3:16"
assert short.format(ref) == "Jn 3:16"

Ranges are compact by default. Use with_compact_ranges(False) to repeat the localized book name at both endpoints.

JSON-shaped dictionaries and identifiers

Values serialize to stable, JSON-compatible dictionaries:

from bible_io_references import VerseRef, reference_from_dict

ref = VerseRef.parse("John 3:16")
assert ref.to_dict() == {
    "type": "verse", "book": "jo", "chapter": 3, "verse": 16
}
assert reference_from_dict(ref.to_dict()) == ref

OSIS and USFM helpers are strict and case-sensitive:

from bible_io_references import (
    Passage,
    osis_identifier,
    reference_from_osis_identifier,
    reference_from_usfm_identifier,
    usfm_identifier,
)

assert osis_identifier(Passage.parse("John 3:16-18")) == "John.3.16-John.3.18"
assert usfm_identifier(Passage.parse("John 3:16,18-20")) == "JHN 3:16,18-20"
assert str(reference_from_osis_identifier("John.3.16")) == "John 3:16"
assert str(reference_from_usfm_identifier("JHN 3:16-4:2")) == "John 3:16-4:2"

Cross-book USFM ranges use the companion packages' reversible extension, for example JHN-ACT 21:25-1:2.

Extract and linkify references in prose

from bible_io_references import ReferenceExtractor

text = "Study John 3:16,18-20; Acts 2:1-4 today."
extractor = ReferenceExtractor()
match = extractor.extract(text)[0]

assert match.source_text == "John 3:16,18-20; Acts 2:1-4"
assert text[match.start:match.end] == match.source_text

linked = extractor.linkify_markdown(
    text,
    lambda item: f"/passage?osis={item.passage.osis_identifier}",
)

Extraction returns the longest deterministic non-overlapping matches and never rescans replacements. Bare-book matching is opt-in. Conservative automatic-mode filters suppress common prose words and lowercase short aliases; use an explicit language when such an alias is intentional.

Command line

bible-io-references "John 3:16"
bible-io-references --language es --format json "Juan 3:16"
bible-io-references --format osis "John 3:16-18"
bible-io-references --format usfm "John 3:16,18-20"
bible-io-references --format json --batch < references.txt
bible-io-references --format json --input references.txt

Batch mode reads strict UTF-8, skips blank lines, preserves source line numbers, continues after parse failures, and writes JSON Lines for JSON output. Exit codes are 0 for success, 64 for usage errors, 65 when any item fails to parse, and 66 for unreadable or non-UTF-8 input.

Supported parsing languages

SUPPORTED_PARSING_LANGUAGES contains AUTO, English, and the 12 localized packs. Every localized pack covers all 83 books. AUTO_LANGUAGE_PRECEDENCE and AUTO_LANGUAGE_COLLISIONS expose default legacy resolution for applications that need to audit ambiguous short terms.

from bible_io_references import SUPPORTED_PARSING_LANGUAGES

print([language.code for language in SUPPORTED_PARSING_LANGUAGES])

Scope

Validation is intentionally edition-neutral. The library checks syntax, positive 1..999 coordinates, and canonical ordering; it does not validate chapter counts, verse counts, or whether a book belongs to a particular canon or Bible edition. Unicode normalization is syntax-oriented rather than a general transliteration system, and extraction uses bounded lookaround windows to keep prose scanning predictable.

See UPSTREAM.md for the cross-language parity contract and CHANGELOG.md for release notes.

License

GNU Affero General Public License v3.0 only (AGPL-3.0-only).

Metadata

Release files for bible-io-references 1.1.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 bible-io-references 1.1.0
File Size Uploaded Provenance Actions
bible_io_references-1.1.0.tar.gz 131.8 kB With provenance Details for bible_io_references-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bible-io-references 1.1.0
File Interpreter ABI Platform Actions
bible_io_references-1.1.0-py3-none-any.whl Python 3 none any Details for bible_io_references-1.1.0-py3-none-any.whl

Total release size: 236.6 kB

Release files / bible_io_references-1.1.0.tar.gz

Download URL bible_io_references-1.1.0.tar.gz
Size 131.8 kB
Tags Source
SHA-256 checksum
How to use checksums
6b28efd04e895e4ded19b1b03c52a57c1c01644a6a2ccb336aa4c66f5788d72c
BLAKE2b-256 checksum
How to use checksums
a206434defae62b17c730b556e054175f7f4dbb4665531d44e3c117af06aa73c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 13, 2026.

Transparency log

Release files / bible_io_references-1.1.0-py3-none-any.whl

Download URL bible_io_references-1.1.0-py3-none-any.whl
Size 104.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e48da85ab3d19e1e5fd05292e850612a6e1ce797137478e9d35acd51299c9d6
BLAKE2b-256 checksum
How to use checksums
a36186479283442115c17cb379b5ac1de2784dda70b694d4cde48a6332dded89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 13, 2026.

Transparency log

Security for bible-io-references 1.1.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 bible_io_references-1.1.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 Aug 13, 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