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.typedmarker 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: strbook_name: str(canonical form)start_chapter: int | Nonestart_verse: int | Noneend_chapter: int | Noneend_verse: int | None
Key methods:
canonical_form() -> strtranslate_to(language_code) -> ParsedReferenceto_internal() -> ParsedReferenceis_single_verse() -> boolis_whole_chapter() -> boolis_whole_book() -> boolis_in_bounds() -> boolget_start() -> ParsedReferenceget_end() -> ParsedReferenceto_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8042503bf98544a0470abb366f5eef747cc33b33c071a60b20dcffd061b6fe2b
|
|
| MD5 |
8b25b840fc0634a4a74f47611081ca9f
|
|
| BLAKE2b-256 |
2fde23a395cf973cd3ba5d9c71862d7973ec68f57a03822fcb5d8e3d3c95688c
|
File details
Details for the file bibleverseparser-0.2-py3-none-any.whl.
File metadata
- Download URL: bibleverseparser-0.2-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
626e0c4c25d2756c17b5743041e824312935b5843ac3d3aea1822214cd4729c3
|
|
| MD5 |
a77d0b525f447e52a9ff739b8ba54d83
|
|
| BLAKE2b-256 |
f147d88538b91bd076d1b68e20cb63844ca0ade4a4bd41e9158dff640305cdfc
|