Skip to main content

Provides an API for scraping https://bible.usccb.org/bible/ to get Bible verses by book and language

Project description

catholic-bible

CI Build License PyPI Version versions

Provides an API for scraping the USCCB Bible website of the United States Conference of Catholic Bishops, returning structured verse data in both English and Spanish.

About catholic-bible

This package facilitates pulling books, chapters, and individual verses from the Catholic Bible. Please open new issues for any bugs you find — support is greatly appreciated! If you have a new feature, feel free to open a pull request.

Installation

To install catholic-bible from PyPI:

$ pip install catholic-bible

To install from source as editable:

$ pip install -e .

API Usage

Fetch a single chapter

import asyncio
from catholic_bible import USCCB, models

async def main() -> None:
    async with USCCB() as usccb:
        chapter = await usccb.get_chapter("genesis", 1)
        if chapter:
            print(chapter.title)          # "Genesis, Chapter 1"
            print(chapter.url)
            for section in chapter.sections:
                if section.heading:
                    print(section.heading)
                for verse in section.verses:
                    print(verse)          # "1[a] In the beginning..."

asyncio.run(main())

Fetch a single verse

import asyncio
from catholic_bible import USCCB, models

async def main() -> None:
    async with USCCB() as usccb:
        verse = await usccb.get_verse("john", 3, 16)
        if verse:
            print(verse.text)

asyncio.run(main())

Fetch all chapters of a book

import asyncio
from catholic_bible import USCCB, models

async def main() -> None:
    async with USCCB() as usccb:
        chapters = await usccb.get_book("psalms")
    for chapter in chapters:
        print(chapter.title)

asyncio.run(main())

Save chapters to JSON

import asyncio
import json
from pathlib import Path
from catholic_bible import USCCB, models

async def main() -> None:
    async with USCCB() as usccb:
        chapters = await usccb.get_book("genesis")
    out = Path("genesis")
    out.mkdir(exist_ok=True)
    for chapter in chapters:
        (out / f"chapter-{chapter.number:04d}.json").write_text(
            json.dumps(chapter.to_dict(), ensure_ascii=False, indent=2)
        )

asyncio.run(main())

Fetch in Spanish

Pass language=models.Language.SPANISH to any method:

import asyncio
from catholic_bible import USCCB, models

async def main() -> None:
    async with USCCB() as usccb:
        chapter = await usccb.get_chapter("genesis", 1, language=models.Language.SPANISH)
        if chapter:
            print(chapter)

asyncio.run(main())

Browse the book catalogue

from catholic_bible import constants

# Attribute access
print(constants.OLD_TESTAMENT_BOOKS.Genesis.num_chapters)   # 50
print(constants.NEW_TESTAMENT_BOOKS.Matthew.name)           # "Matthew"
print(constants.NEW_TESTAMENT_BOOKS.Corinthians1.name)      # "1 Corinthians"

# All 73 books in canonical order
for book in constants.ALL_BOOKS:
    print(book.name, book.num_chapters)

# Lookup by URL name
genesis = constants.BIBLE_BOOKS["genesis"]
print(genesis.short_abbreviation)  # "Gn"
print(genesis.long_abbreviation)   # "Gen"

Book lookup utilities

Books can be looked up by full name, URL name, or abbreviation (case-insensitive):

from catholic_bible.utils import lookup_book, book_url_name

book = lookup_book("Gen")          # long abbreviation
book = lookup_book("Gn")           # short abbreviation
book = lookup_book("genesis")      # URL name (lowercase, no spaces)
book = lookup_book("Genesis")      # full display name
book = lookup_book("Song of Songs")

print(book_url_name(book))         # "songofsongs"

CLI Usage

# List all 73 books
python -m catholic_bible list-books

# List only Old Testament books
python -m catholic_bible list-books --testament old

# List only New Testament books
python -m catholic_bible list-books --testament new

# Fetch a chapter and print to stdout
python -m catholic_bible get-chapter --book genesis --chapter 1

# Fetch a chapter and save to JSON
python -m catholic_bible get-chapter --book genesis --chapter 1 --save genesis-1.json

# Fetch a single verse
python -m catholic_bible get-verse --book john --chapter 3 --verse 16

# Fetch an entire book (all chapters)
python -m catholic_bible get-book --book psalms

# Save all chapters of a book to a directory
python -m catholic_bible get-book --book genesis --save-dir ./genesis/

# Fetch in Spanish
python -m catholic_bible get-chapter --book genesis --chapter 1 --language SPANISH
python -m catholic_bible get-book --book genesis --language SPANISH --save-dir ./genesis-es/

Key Types

Type Description
USCCB Async client — use as an async context manager
BibleChapter A parsed chapter with book, number, language, url, title, sections
BibleSection A named section within a chapter (heading, verses)
BibleVerse A single verse (number, text, footnote_refs)
Language Language.ENGLISH or Language.SPANISH
BibleBookInfo Book metadata (name, title, short_abbreviation, long_abbreviation, num_chapters)

Documentation

The documentation for catholic-bible can be found here or in the project's docstrings.

Development

Setup Python Environment

uv install
uvx pre-commit install

Re-lock dependencies

uv lock

Run code

uv run python -m catholic_bible

Generating test fixtures

# Fetch and save a chapter for use as a test fixture
python -m catholic_bible get-chapter --book genesis --chapter 1 --save tests/data/genesis-chapter-1.json

Run tests

uv run pytest

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

catholic_bible-0.1.0.tar.gz (38.2 kB view details)

Uploaded Source

Built Distribution

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

catholic_bible-0.1.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file catholic_bible-0.1.0.tar.gz.

File metadata

  • Download URL: catholic_bible-0.1.0.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for catholic_bible-0.1.0.tar.gz
Algorithm Hash digest
SHA256 69a64dda2284a66ca2041fe718ccec2ee700faa2baa617db90ddee3603238dd1
MD5 ced9e9751db8237106e05456a0d6fff7
BLAKE2b-256 04443cccf6cb5b055d55048cef9a0cd017a4a77c03996a3ab3630bb8a3b39d14

See more details on using hashes here.

File details

Details for the file catholic_bible-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: catholic_bible-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for catholic_bible-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 013935b01c3556ae86bd30538b41603d2bfb0d3eaf3d8edcc464d011708f1a6a
MD5 01f691872d7c279f32611bf90b1deef8
BLAKE2b-256 7d76061bedb9dce845e9a0006d7d62e0475de9a8d708eacce4cbf61d4ba9f568

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