Skip to main content

Parse Bible verse references like 'Gen 1:1' to canonical form 'Genesis 1:1'

Project description

bibleverseparser

A small Python library that parses Bible verse references (like Gen 1:1) into a canonical form (Genesis 1:1).

Supports English, Dutch, Turkish, and Spanish book names, with many common abbreviations.

Installation

pip install bibleverseparser

Quick start

from bibleverseparser import parse_unvalidated_localized_reference

# Parse loose user input
ref = parse_unvalidated_localized_reference("en", "Gen 1:1")
print(ref.canonical_form())  # "Genesis 1:1"

# Handles abbreviations, spacing variations, and different separators
ref = parse_unvalidated_localized_reference("en", "1 Cor 13:4-7")
print(ref.canonical_form())  # "1 Corinthians 13:4-7"

# Returns None for unparseable input
result = parse_unvalidated_localized_reference("en", "not a verse")
assert result is None

Features

  • Loose parsing: accepts common abbreviations (Gen, Gen., Ge., etc.), flexible whitespace, and alternative verse/chapter separators (:, v, .)
  • Strict parsing: validates that a reference is already in canonical form
  • Multi-language: English (en), Dutch (nl), Turkish (tr), Spanish (es)
  • Verse ranges: Genesis 1:1-3, Genesis 1:2-3:4
  • Whole chapters: Genesis 1
  • Whole books: Genesis
  • Validation: checks chapter/verse bounds, correct ordering
  • Translation: convert references between languages
  • Fully typed: includes py.typed marker and type hints throughout

API

parse_unvalidated_localized_reference(language_code, reference, *, allow_whole_book=True, allow_whole_chapter=True)

Parse user input. Returns a ParsedReference or None if it doesn't look like a reference. Raises InvalidVerseReference if it parses but is invalid (e.g. end verse before start verse).

parse_validated_localized_reference(language_code, reference)

Parse a reference that is expected to be in canonical form. Raises InvalidVerseReference on any error.

ParsedReference

Dataclass with fields:

  • language_code: str
  • book_name: str (canonical form)
  • start_chapter: int | None
  • start_verse: int | None
  • end_chapter: int | None
  • end_verse: int | None

Key methods:

  • canonical_form() -> str
  • translate_to(language_code) -> ParsedReference
  • to_internal() -> ParsedReference
  • is_single_verse() -> bool
  • is_whole_chapter() -> bool
  • is_whole_book() -> bool
  • is_in_bounds() -> bool
  • get_start() -> ParsedReference
  • get_end() -> ParsedReference
  • to_list() -> list[ParsedReference]

localize_internal_reference(language_code, internal_reference) -> str

Convert an internal reference to a localized canonical string.

internalize_localized_reference(language_code, localized_reference) -> str

Convert a localized reference to an internal canonical string.

Supported languages

Code Language
en English
nl Dutch
tr Turkish
es Spanish

Origin

Extracted from learnscripture.net.

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

bibleverseparser-0.2.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

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

bibleverseparser-0.2-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file bibleverseparser-0.2.tar.gz.

File metadata

  • Download URL: bibleverseparser-0.2.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.6

File hashes

Hashes for bibleverseparser-0.2.tar.gz
Algorithm Hash digest
SHA256 8042503bf98544a0470abb366f5eef747cc33b33c071a60b20dcffd061b6fe2b
MD5 8b25b840fc0634a4a74f47611081ca9f
BLAKE2b-256 2fde23a395cf973cd3ba5d9c71862d7973ec68f57a03822fcb5d8e3d3c95688c

See more details on using hashes here.

File details

Details for the file bibleverseparser-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for bibleverseparser-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 626e0c4c25d2756c17b5743041e824312935b5843ac3d3aea1822214cd4729c3
MD5 a77d0b525f447e52a9ff739b8ba54d83
BLAKE2b-256 f147d88538b91bd076d1b68e20cb63844ca0ade4a4bd41e9158dff640305cdfc

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