Skip to main content

BibleQL Python

CI PyPI Python versions

A typed Python client for the BibleQL GraphQL API. Query Bible verses, passages, translations, search and concordance across 47 translations in 31 languages, without writing GraphQL.

Installation

pip install bibleql

Requires Python 3.10+.

Quick start

import bibleql

with bibleql.Client(api_key="bql_live_...") as client:
    passage = client.passage("John 3:16")
    print(passage.reference)  # John 3:16
    print(passage.text)  # For God so loved the world...

Get an API key at bibleql.org, and try queries in the playground.

Configuration

client = bibleql.Client(
    api_key="bql_live_...",  # or set the BIBLEQL_API_KEY environment variable
    default_translation="spa-bes",  # optional, defaults to "eng-web"
    api_url="https://custom-host.com/graphql",  # optional, defaults to https://bibleql.org/graphql
    timeout=60,  # optional, seconds, defaults to 30
)

If api_key is omitted, the client reads BIBLEQL_API_KEY:

export BIBLEQL_API_KEY=bql_live_...
client = bibleql.Client()

Use the client as a context manager (with ... as client:) or call client.close() when done, so its connection pool is released.

Every method that takes translation= falls back to default_translation when it's omitted. The exception is semantic_search, which lets the API pick a translation that has embeddings.

Usage

Passages

passage = client.passage("John 3:16")
passage.reference  # "John 3:16"
passage.text  # "For God so loved the world..."
passage.translation_id  # "eng-web"
passage.verses  # [Verse(book_id='JHN', book_name='John', chapter=3, verse=16, text='...')]

client.passage("John 3:16-18")
client.passage("Matthew 25:31-33,46")
client.passage("Genesis 1")
client.passage("Mateo 28:18-20", translation="spa-bes")

Verses and chapters

verse = client.verse("MAT", 5, 3)
verse.book_name  # "Matthew"
verse.text  # "Blessed are the poor in spirit..."

verses = client.chapter("GEN", 1)  # list[Verse]

Random verse

client.random_verse()
client.random_verse(testament="NT")  # "OT" or "NT"
client.random_verse(books=["PSA", "PRO"])  # or books="PSA,PRO"

Verse of the day

import datetime

client.verse_of_the_day()
client.verse_of_the_day(date=datetime.date(2026, 1, 1))  # or date="2026-01-01"

Case-insensitive substring search, with no stemming ("love" won't match "loved"):

for verse in client.search("love", limit=5):
    print(verse.book_name, verse.chapter, verse.verse, verse.text)

Semantic search finds verses by meaning, using AI embeddings:

for result in client.semantic_search("fe y esperanza", limit=5):
    print(f"{result.similarity:.2f}", result.verse.text)

Concordance

Exhaustive, canonically ordered occurrences of a word, with per-book and per-testament totals:

page = client.concordance("misericordia", translation="spa-rv1909", first=10)
page.total_count  # total occurrences
page.entry.surface_forms  # ["misericordia", "misericordias", ...]
page.entry.occurrences_by_testament.old  # verses in the Old Testament
for occurrence in page.occurrences:
    print(occurrence.verse.book_name, occurrence.context)  # context has <mark> tags

# Next page
if page.has_next_page:
    page = client.concordance("misericordia", translation="spa-rv1909", after=page.end_cursor)

# Or let the client paginate for you (pages are fetched lazily)
for occurrence in client.iter_concordance("misericordia", translation="spa-rv1909"):
    ...

# Filters
client.concordance("misericordia", translation="spa-rv1909", book="Salmos")
client.concordance("misericordia", translation="spa-rv1909", testament=bibleql.Testament.NEW)

# Alphabetical word-frequency index
client.concordance_index(translation="spa-rv1909", prefix="mis", min_occurrences=5)

The context field contains <mark> HTML tags around the match, so sanitize it before rendering it as HTML.

Translations, languages, books

client.translations()  # list[Translation]
t = client.translation("eng-web")
t.name, t.abbrev  # "World English Bible", "WEB"
t.books  # list[LocalizedBook]

client.languages()  # list[Language], each with .translations
client.books()  # list[Book], the 66 canonical books

Bible index

index = client.bible_index()
index[0].name  # "Genesis"
index[0].chapters[0].verse_count  # 31

Models

All results are immutable dataclasses with snake_case attributes. To convert one to a dict:

import dataclasses

dataclasses.asdict(client.verse("JHN", 3, 16))

Error handling

Every error inherits from bibleql.BibleQLError:

BibleQLError
├── ConfigurationError        no API key
├── NetworkError              no response (DNS, connection refused, ...)
│   └── RequestTimeoutError
├── APIError (.status, .body) non-2xx HTTP response
│   ├── AuthenticationError     401
│   ├── RateLimitError          429
│   └── ServerError             5xx
└── QueryError (.errors)      GraphQL errors in the response
    └── NotFoundError
try:
    client.passage("Hezekiah 1:1")
except bibleql.NotFoundError as e:
    print(f"Not found: {e}")
except bibleql.AuthenticationError:
    print("Invalid API key")
except bibleql.RateLimitError:
    print("Too many requests")
except bibleql.RequestTimeoutError:
    print("Request timed out")
except bibleql.NetworkError:
    print("Connection failed")
except bibleql.QueryError as e:
    print(f"GraphQL error: {e}")
    print(e.errors)  # raw error list from the API

Development

asdf install                      # Python version from .tool-versions
python -m venv .venv && source .venv/bin/activate
python -m pip install -e ".[dev]"

pytest                            # run tests (HTTP is mocked with respx, no network needed)
ruff check . && ruff format .     # lint and format

tests/fixtures/schema.graphql is a snapshot of the API schema, and every query is validated against it. Refresh it from the API repo (docs/generated/schema.graphql) when the schema changes.

Testing against the live API

The test suite never touches the network. To check the client against the real API, put your key in a .env file (gitignored) and run the smoke test, which loads it with python-dotenv:

cp .env.example .env              # then set BIBLEQL_API_KEY in .env
python scripts/smoke_test.py      # calls every method and prints the results

The library itself never reads .env files. In your own app, load them yourself (for example with dotenv.load_dotenv()) before creating a Client().

License

Released under the MIT License.

Metadata

Release files for bibleql 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bibleql 0.1.0
File Size Uploaded
bibleql-0.1.0.tar.gz 23.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bibleql 0.1.0
File Interpreter ABI Platform
bibleql-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.9 kB

Release files / bibleql-0.1.0.tar.gz

Download URL bibleql-0.1.0.tar.gz
Size 23.0 kB
Tags Source
SHA-256 checksum
How to use checksums
60deb24f31a9866f58458a32695de4df0f6f9901f091c31a330033a9a700ee80
BLAKE2b-256 checksum
How to use checksums
8f8d746266daaddb22cc54e00ace76e6410b2377eb175f3307c2037fbf154398
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

Release files / bibleql-0.1.0-py3-none-any.whl

Download URL bibleql-0.1.0-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c8bccdd174223ec57f45f5525d55672515284e57b8ea6a2421616f519073de3
BLAKE2b-256 checksum
How to use checksums
16157d2549bba679cdbe93469c085252de11e8782120d0df72f95e37f03183a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page