Skip to main content

Bible parsing package

Project description

Bible-IO

A Python package for loading and working with structured Bible text data. The package reads JSON exports of Bible translations and exposes convenient classes for navigating books, chapters, and verses or running simple searches.

Features

  • Parse Bible translations from JSON files into rich Python objects.
  • Access books, chapters, and verses via BibleBookEnum or numeric helper methods.
  • Run fast, case-insensitive word searches using a cached reverse index across all verses.
  • Pythonic error handling with custom exceptions for missing references.

Installation

Install the package from PyPI:

pip install bible-io

Python 3.10 or later is required.

Getting Started

from bible_io import Bible
from bible_io.bible_book_enums import BibleBookEnum

# Load a translation exported in the supported JSON structure
# The loader accepts either strings or Path objects.
bible = Bible("path/to/en_kjv.json")

# Retrieve a specific chapter (Genesis 1) using the enum identifiers
for verse in bible.get_verses(BibleBookEnum.Genesis, 1):
    print(f"Genesis 1:{verse.verse_number} {verse.text}")

# Access a book via the BibleBookEnum or by numeric index
john = bible.get_book(BibleBookEnum.John)
acts = bible.get_book_by_id(44)  # Book numbers are 1-indexed

# Fetch John 3:16 and print the verse text
john_316 = john.get_verse(3, 16)
print(john_316.text)

# Search the entire translation (case-insensitive)
for verse in bible.search("shepherd"):
    print(verse)

# If you edit verse text at runtime, refresh the cached search index
bible.invalidate_search_index()

The high-level API centres around four classes:

  • Bible - container for all loaded books and the cached search index.
  • Book - holds the chapters of a single Bible book.
  • Chapter - manages the verses inside a chapter and validates access.
  • Verse - stores an individual verse with helpers such as contains_word.

Additional helper enums and exceptions live in bible_io.bible_book_enums and bible_io.errors respectively.

Search Index

Repeated searches reuse a cached word-to-verse index that is generated on demand. Queries are normalized by lowercasing and removing punctuation, and multi-word searches return deduplicated matches for any token in the phrase. If you mutate verse text after loading (for example, when normalizing or annotating data), call invalidate_search_index() on the Bible instance so the next search rebuilds the index with the updated content.

JSON Structure

The loader expects Bible data in the following JSON format:

{
    "id": "kjv",
    "name": "King James Version",
    "description": "The King James Version (Oxford 1769) is a standardized revision of the classic 1611 English Bible.",
    "language": "English",
    "books": {
        "gn": {
            "name": "Genesis",
            "chapters": {
                "1": {
                    "1": "In the beginning God created the heaven and the earth.",
                    "2": "And the earth was without form, and void; and darkness {was} upon the face of the deep. And the Spirit of God moved upon the face of the waters.",
                    "3": "And God said, Let there be light: and there was light."
                },
                "2": {
                    "1": "Thus the heavens and the earth were finished, and all the host of them.",
                    "2": "And on the seventh day God ended his work which he had made; and he rested on the seventh day from all his work which he had made.",
                    "3": "And God blessed the seventh day, and sanctified it: because that in it he had rested from all his work which God created and made. "
                }
            }
        }
    }
}

Each book entry uses a compact abbreviation (e.g., "gn" for Genesis). The loader maps these abbreviations onto BibleBook enum members and constructs the corresponding hierarchy of Book, Chapter, and Verse objects.

Check https://github.com/m0ty/bible-io-json repository for ready to use bible .json files.

Running the Tests

The repository uses pytest for automated tests. After installing the package's dependencies (via pip install . or pip install -e .), run:

pytest

If you prefer uv, you can run the suite via:

uv run pytest

The test suite expects the sample translation at test/bible_versions/en_kjv.json.

License

MIT License - see the LICENSE file for details.

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

bible_io-1.0.3.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

bible_io-1.0.3-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file bible_io-1.0.3.tar.gz.

File metadata

  • Download URL: bible_io-1.0.3.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for bible_io-1.0.3.tar.gz
Algorithm Hash digest
SHA256 b05210f4096f53efd077e4571a33d7a97792bbf3e749c1092369e85d39c99c59
MD5 9911b813116d0f2e6705956294f343e1
BLAKE2b-256 68aed41d14afbe905a262079ffbb0d01d776859b04ba1202dc35a94aa77b2526

See more details on using hashes here.

File details

Details for the file bible_io-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: bible_io-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for bible_io-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bebf1b7a9eabbf6309f8dd6f37c300e996a14fc3d1fd455520da86b1ee2c39f3
MD5 3824367305be3082b45365191942ab97
BLAKE2b-256 56722579ec8b6c1d361f9bce9cfd85f63cfbc35267f9dcab0b1e0dcae193ba86

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