quran-foundation-api
Official Python SDK for Quran Foundation APIs.
pip install quran-foundation-api
from quran_foundation import QuranClient
client = QuranClient(client_id="YOUR_CLIENT_ID", access_token="ACCESS_TOKEN")
chapters = client.list_chapters()
print(chapters)
Content and search
from quran_foundation import QuranClient
client = QuranClient(client_id="YOUR_CLIENT_ID", access_token="ACCESS_TOKEN")
chapter = client.get_chapter(1)
verses = client.get_verses_by_range("1:1", "1:7", translations="131")
translations = client.list_translations()
results = client.search("mercy", mode="advanced", params={"size": 10})
Content resource sync
Chapter recitations, Mushafs, and word-by-word translations can be included in content sync and fetched as resource snapshots:
changes = client.sync_resources(
params={
"bootstrap": True,
"resources": "chapter_recitations:159;mushafs:1;word_by_word_translations:85",
}
)
chapter_recitation_snapshot = client.get_chapter_recitation_snapshot(159)
snapshot = client.get_word_by_word_translation_snapshot(85)
mushaf_snapshot = client.get_mushaf_snapshot(1)
Chapter-recitation snapshots use the audio recitation ID and contain its chapter audio files. Mushaf snapshots contain the layout metadata, pages, publicly distributable font assets, and words needed for offline use. The API also exposes approved, shareable word-translation resources; transliteration resources are excluded.
For endpoints that do not yet have a dedicated helper, use the service request helpers:
client.content_request("/verses/by_page/1", params={"translations": "131"})
client.search_request("/api/v1/search", params={"query": "mercy", "mode": "quick"})
client.user_request("/bookmarks", params={"page": 1})
Analytics Events
Analytics submission is server-side and requires a client-credentials access
token with the analytics.events.write scope. Keep the client secret and token
in server-side environment variables.
import os
from datetime import datetime, timezone
from quran_foundation import AnalyticsEvent, QuranClient
from quran_foundation.oauth import client_credentials
token = client_credentials(
client_id=os.environ["QURAN_CLIENT_ID"],
client_secret=os.environ["QURAN_CLIENT_SECRET"],
scope="analytics.events.write",
)
client = QuranClient(
client_id=os.environ["QURAN_CLIENT_ID"],
access_token=token["access_token"],
)
result = client.submit_analytics_events(
[
AnalyticsEvent(
event_id="stable-event-id-1",
name="quran.reader.verse_viewed",
version=1,
occurred_at=datetime.now(timezone.utc),
user_id="QURAN_FOUNDATION_USER_ID",
session_id="session-123",
properties={"verse_key": "2:255", "surface": "reader"},
),
AnalyticsEvent(
event_id="stable-event-id-2",
name="quran.app.started",
version=1,
occurred_at=datetime.now(timezone.utc),
anonymous_id="anonymous-123",
),
]
)
A successful response accepts the complete batch. Retry a failed batch with
the same event IDs so downstream processing can identify duplicates. Use a
Quran Foundation OAuth user ID for user_id; omit it for guests or unknown
users.
User APIs
Use signed-in User API helpers with a user access token. Keep the token server-side.
profile = client.get_profile()
bookmarks = client.list_bookmarks()
client.create_bookmark({"verse_key": "2:255", "mushaf_id": 1})
client.update_preference({"key": "theme", "value": "dark"})
OAuth2 helpers
Use OAuth helpers on the server side. Never expose client_secret, access tokens, or refresh tokens to browser code.
from quran_foundation.oauth import build_authorization_url, create_pkce_pair, exchange_code
verifier, challenge = create_pkce_pair()
authorize_url = build_authorization_url(
client_id="YOUR_CLIENT_ID",
redirect_uri="https://your-app.com/callback",
scope="openid offline_access user bookmark",
state="random-state",
code_challenge=challenge,
)
tokens = exchange_code(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
code="CODE_FROM_CALLBACK",
code_verifier=verifier,
redirect_uri="https://your-app.com/callback",
)
Development
python -m pip install -e ".[dev]"
ruff check .
pytest
python -m build
twine check dist/*
Contributing and releases
Public API changes require tests, documentation, a changelog entry, and a
version bump. Merging to main runs CI but does not publish the package. See
CONTRIBUTING.md for the versioning and release process.
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 quran_foundation_api-0.2.0.tar.gz.
File metadata
- Download URL: quran_foundation_api-0.2.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a143ce9e807d70685bca0fe37686dde3ad98f94d3f83fccc729c7150d6d52401
|
|
| MD5 |
5d2e8bb9d9716c2ec3fb07fd3aa9d123
|
|
| BLAKE2b-256 |
9948155c7fd5d4f0f417698ea3f0efb550146732fd266f5e9e38dd55b5063d0d
|
Provenance
The following attestation bundles were made for quran_foundation_api-0.2.0.tar.gz:
Publisher:
publish.yml on quran/api-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quran_foundation_api-0.2.0.tar.gz -
Subject digest:
a143ce9e807d70685bca0fe37686dde3ad98f94d3f83fccc729c7150d6d52401 - Sigstore transparency entry: 2634487685
- Sigstore integration time:
-
Permalink:
quran/api-python@5d900c9d0add350c6d851d9205ab12c8b747c6e9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/quran
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5d900c9d0add350c6d851d9205ab12c8b747c6e9 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file quran_foundation_api-0.2.0-py3-none-any.whl.
File metadata
- Download URL: quran_foundation_api-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03be0a6912a59f1f946a3b1aea70c5302c91628cf05d2a933e8fc7fdaa085c66
|
|
| MD5 |
e83d3b073d15488e8dbc7c24a2efbf08
|
|
| BLAKE2b-256 |
1560c04503c7d5bc1359ba5f54ddb16a9ee7c317ccc2b32bf2f526b21d941a15
|
Provenance
The following attestation bundles were made for quran_foundation_api-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on quran/api-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quran_foundation_api-0.2.0-py3-none-any.whl -
Subject digest:
03be0a6912a59f1f946a3b1aea70c5302c91628cf05d2a933e8fc7fdaa085c66 - Sigstore transparency entry: 2634487757
- Sigstore integration time:
-
Permalink:
quran/api-python@5d900c9d0add350c6d851d9205ab12c8b747c6e9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/quran
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5d900c9d0add350c6d851d9205ab12c8b747c6e9 -
Trigger Event:
workflow_dispatch
-
Statement type: