Get Bible verses in Python
This guide fetches Bible verses from Python using the popular requests library. It works the same in a script, a Flask or Django app, or a data notebook.
Uses a secret key (bva_sk_…), because the code runs on a server.
1. Get a free API key and install requests
Create a secret key (it starts with bva_sk_) at bibleverse-api.com, then install requests with pip install requests.
2. Fetch a passage
Keep the key in an environment variable. requests encodes the reference for you.
import os
import requests
API = "https://api.bibleverse-api.com/v1"
KEY = os.environ["BIBLE_API_KEY"] # bva_sk_…
def get_verses(ref, bible="kjv"):
res = requests.get(
f"{API}/bibles/{bible}/passages",
params={"ref": ref},
headers={"Authorization": f"Bearer {KEY}"},
timeout=10,
)
body = res.json()
if not res.ok:
raise RuntimeError(body["error"]["message"])
return body
data = get_verses("John 3:16-18")
for passage in data["passages"]:
print(passage["reference"])
for chapter in passage["chapters"]:
for verse in chapter["verses"]:
print(verse["verse"], verse["text"])
print(data["attribution"])3. Several references at once
Separate references with semicolons. Each one comes back as its own passage.
data = get_verses("Psalm 23:1; Romans 8:28; Philippians 4:13")
for passage in data["passages"]:
print(passage["reference"])4. Wait and retry when you reach a limit
The API answers 429 with a Retry-After header (seconds). This helper waits and tries again.
import time
def get_verses_with_retry(ref, bible="kjv", attempts=3):
for _ in range(attempts):
res = requests.get(
f"{API}/bibles/{bible}/passages",
params={"ref": ref},
headers={"Authorization": f"Bearer {KEY}"},
timeout=10,
)
if res.status_code != 429:
body = res.json()
if not res.ok:
raise RuntimeError(body["error"]["message"])
return body
time.sleep(int(res.headers.get("Retry-After", "1")))
raise RuntimeError("Still rate limited; try again later.")Ready to try it?
The Free plan gives you 5,000 requests and 2,000 verses a day, with no card.