Parses scripture references and returns OSIS references/ranges.
Project description
scripture-ref-parser
A modular Python library and CLI that parses scripture references (KJV OT/NT and LDS canon: Book of Mormon, Doctrine & Covenants, Pearl of Great Price) and returns OSIS-based ranges.
Installation
pip install scripture-ref-parser
Or with uv:
uv add scripture-ref-parser
Usage
Python API
from scripture_ref_parser import parse_references
# Simple reference
results = parse_references("Gen 1:1")
# [{'start': 'Gen.1.1', 'end': 'Gen.1.1'}]
# Multiple references with ranges
results = parse_references("Gen 1:1-3; Exod 2:1")
# [{'start': 'Gen.1.1', 'end': 'Gen.1.3'}, {'start': 'Exod.2.1', 'end': 'Exod.2.1'}]
# LDS canon references
results = parse_references("1 Ne. 3:7")
# [{'start': '1Ne.3.7', 'end': '1Ne.3.7'}]
# Fuzzy matching (default: loose mode)
results = parse_references("Exodis 1:1", mode="loose")
# [{'start': 'Exod.1.1', 'end': 'Exod.1.1', 'fuzzy_ratio': 83}]
# Strict mode (no fuzzy matching)
results = parse_references("Exodis 1:1", mode="strict")
# [{'start': None, 'end': None, 'not_found': "Unknown book 'Exodis'"}]
# Chapter expansion
results = parse_references("Gen 1")
# [{'start': 'Gen.1.1', 'end': 'Gen.1.31'}]
CLI
scripture-ref-parser "Gen 1:1-3; 1 Ne. 3:7"
# [{"start": "Gen.1.1", "end": "Gen.1.3"}, {"start": "1Ne.3.7", "end": "1Ne.3.7"}]
# Fuzzy matching (includes fuzzy_ratio)
scripture-ref-parser "Exodis 1:1"
# [{"start": "Exod.1.1", "end": "Exod.1.1", "fuzzy_ratio": 83}]
# With strict mode
scripture-ref-parser "Gen 1:1" --mode strict
# Or use the shortcut flags:
scripture-ref-parser "Gen 1:1" --strict
scripture-ref-parser "Exodis 1:1" --loose
# With pretty output
scripture-ref-parser "Gen 1:1" --pretty
# Get all fuzzy candidates
scripture-ref-parser "E 1:1" --all-candidates
# Help
Use the `--help` flag to display a comprehensive, example-driven help message describing available modes and flags. The help output includes short, copyable examples and explains the differences between `loose` (fuzzy) and `strict` matching.
Note: `--loose` and `--strict` are provided as shorthand flags and are mutually exclusive. They are equivalent to `--mode loose` and `--mode strict`, respectively.
```bash
scripture-ref-parser --help
# Displays usage, options (including `--mode`, `--all-candidates`, `--pretty`),
# and examples such as:
# scripture-ref-parser "Gen 1:1-3; 1 Ne. 3:7" --pretty
# scripture-ref-parser "E 1:1" --all-candidates --pretty
Supported Canons
- KJV Old Testament (Genesis - Malachi)
- KJV New Testament (Matthew - Revelation)
- Book of Mormon (1 Nephi - Moroni)
- Doctrine & Covenants (Sections 1-138)
- Pearl of Great Price (Moses, Abraham, JS-Matthew, JS-History, Articles of Faith)
- JST Appendix
Pipeline Architecture
The parser operates in four stages:
- Tokenize: Convert raw text into tokens (book names, numbers, separators)
- Normalize: Map book names/abbreviations to canonical OSIS keys
- Parse: Convert tokens into structured chapter:verse references
- Resolve: Expand references to complete OSIS ranges
Development
# Run tests
uv run pytest
# Format code
uvx ruff format
# Lint
uvx ruff check --fix
# Type check
uvx ty check
# Edit package itself
uv pip install -e .
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 scripture_ref_parser-0.2.0.tar.gz.
File metadata
- Download URL: scripture_ref_parser-0.2.0.tar.gz
- Upload date:
- Size: 22.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aea8e71055d8dbfb325891c3d32cc7c92cf1dfe79487530e2088331cb45008d6
|
|
| MD5 |
60cfe55362ff1a61a7382797d5ee1231
|
|
| BLAKE2b-256 |
95e0005c5705f3b348b2e5642f07cd1bf922a94b50de3faddad90d9df4ed0e7d
|
File details
Details for the file scripture_ref_parser-0.2.0-py3-none-any.whl.
File metadata
- Download URL: scripture_ref_parser-0.2.0-py3-none-any.whl
- Upload date:
- Size: 23.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d612b9e759db2873f3a2a4a70e125a7d0be2cff4c4408037ab8d6953e4afa6c9
|
|
| MD5 |
ae7a7f6b6f1acffa65449d04da694af5
|
|
| BLAKE2b-256 |
915889f92c6657bb919547d4347db24fd8e2ba45c67337d31d2909c2226506e5
|