qurancom-py
A modern, fast, fully typed Python wrapper for the official Quran.com API (v4).
Built with httpx and Python standard library dataclasses, providing both synchronous (QuranClient) and asynchronous (AsyncQuranClient) interfaces, automatic pagination, word-by-word timing segments, multi-script Quranic text, tafsirs, translations, audio streaming, and a built-in CLI.
Features
- ✨ Full Quran.com v4 Endpoint Coverage: Chapters, Verses, Tafsirs, Translations, Audio, Juzs, and Search.
- ⚡ Sync & Async: Dual client interfaces (
QuranClient&AsyncQuranClient) sharing the same typed abstractions. - 🔄 Smart Pagination: Seamlessly iterate across chapters, juzs, and pages item-by-item or page-by-page (
Paginator&AsyncPaginator). - 📜 Multi-Script Support: Uthmani, Tajweed, Indo-Pak, Imlaei, and Madani V1/V2 font glyphs.
- 🎧 Audio & Timestamps: Complete verse and chapter-level recitation streams with word-by-word sync timestamps.
- 🛡️ Type-Safe & Lightweight: Zero bloated dependencies (only
httpx), powered by standard dataclasses withslots=True. - 💻 Built-in CLI: Query chapters, verses, search, and recitations directly from your terminal.
Installation
pip install qurancom-py
Or install with development dependencies:
pip install "qurancom-py[dev]"
Quickstart
1. Synchronous Client (QuranClient)
from qurancom import QuranClient
with QuranClient() as client:
# 1. Fetch all chapters (Surahs)
chapters = client.chapters.list()
for chapter in chapters[:3]:
print(f"Surah {chapter.id}: {chapter.name_simple} ({chapter.name_arabic}) - {chapter.verses_count} verses")
# 2. Fetch Ayat al-Kursi with English translation
verse = client.verses.by_key("2:255", translations=[20])
print(f"\nArabic: {verse.arabic_text}")
print(f"Translation: {verse.primary_translation}")
# 3. Search the Quran
search_results = client.search.search("mercy", size=3)
for result in search_results.results:
print(f"[{result.verse_key}] {result.text}")
2. Asynchronous Client (AsyncQuranClient)
import asyncio
from qurancom import AsyncQuranClient
async def main():
async with AsyncQuranClient() as client:
# Fetch chapter information
surah = await client.chapters.get(1)
print(f"Surah {surah.name_simple} - Revelation: {surah.revelation_place}")
# Fetch raw Uthmani text of Surah Al-Ikhlas (Chapter 112)
verses = await client.quran.uthmani(chapter_number=112)
for v in verses:
print(f"{v.verse_key}: {v.text}")
asyncio.run(main())
3. Automatic Pagination
Stream through verses without manual page calculation:
from qurancom import QuranClient
with QuranClient() as client:
# Auto-paginates across all 7 verses of Surah Al-Fatihah
for verse in client.verses.iterate_chapter(1, per_page=2):
print(f"{verse.verse_key} -> {verse.arabic_text}")
Async iteration is equally straightforward:
async for verse in async_client.verses.iterate_chapter(1):
print(verse.verse_key)
4. Audio & Recitations
from qurancom import QuranClient
with QuranClient() as client:
# Fetch full chapter audio stream
audio = client.audio.chapter_recitation(reciter_id=7, chapter_id=1)
print(f"Audio URL: {audio.audio_url} (Format: {audio.format})")
# Fetch verse audio with word-by-word timestamps
ayah_audio = client.audio.by_ayah(reciter_id=7, verse_key="1:1")
print(f"Ayah Audio: {ayah_audio.url}")
print(f"Segments: {ayah_audio.segments}")
Command Line Interface (CLI)
qurancom-py comes with a built-in CLI tool qurancom:
# List all 114 Surahs
qurancom chapter list
# Get Surah details
qurancom chapter get 1
# Read historical chapter background
qurancom chapter info 1
# Fetch verse by key with English translation
qurancom verse get 1:1
qurancom verse get 2:255 --translations 20,85
# Get a random Ayah
qurancom verse random
# Search the Quran
qurancom search "patience" --size 5
# List available translations & reciters
qurancom resources translations
qurancom resources recitations
Authentication & Custom Configuration
While public endpoints on Quran.com do not require authentication, you can supply OAuth2 credentials if using Quran Foundation developer features:
client = QuranClient(
auth_token="YOUR_OAUTH_TOKEN",
client_id="YOUR_CLIENT_ID",
timeout=45.0,
max_retries=5,
)
Error Handling
All API errors inherit from QuranAPIError:
from qurancom import QuranClient
from qurancom.exceptions import ResourceNotFoundError, RateLimitError, QuranAPIError
with QuranClient() as client:
try:
client.chapters.get(999)
except ResourceNotFoundError as e:
print(f"Chapter not found: {e}")
except RateLimitError as e:
print(f"Rate limited: {e}")
except QuranAPIError as e:
print(f"API Error [{e.status_code}]: {e.message}")
Contributing & Testing
# Clone the repository
git clone https://github.com/ayoubanlouf/qurancom-py.git
cd qurancom-py
# Install in editable mode with test dependencies
pip install -e ".[dev]"
# Run unit tests
pytest tests/unit/ -v
# Run live integration tests
pytest tests/integration/ -v
License
This project is licensed under the MIT License. See LICENSE for details.
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 qurancom_py-0.1.0.tar.gz.
File metadata
- Download URL: qurancom_py-0.1.0.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d41891af9fd41ab5559180864e5dd96ac51918d9ea031d17486092682e7366e1
|
|
| MD5 |
6c5444cb058e3d0d62d959f10784d581
|
|
| BLAKE2b-256 |
1b543e8e8b6affe93aabbf23e0cdf107e8307f2c45902d643f7355b4a3e4713a
|
Provenance
The following attestation bundles were made for qurancom_py-0.1.0.tar.gz:
Publisher:
publish.yml on ayoubanlouf/qurancom-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qurancom_py-0.1.0.tar.gz -
Subject digest:
d41891af9fd41ab5559180864e5dd96ac51918d9ea031d17486092682e7366e1 - Sigstore transparency entry: 2680487236
- Sigstore integration time:
-
Permalink:
ayoubanlouf/qurancom-py@151b091a885b7245753b7010a403ca3735731cc7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ayoubanlouf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@151b091a885b7245753b7010a403ca3735731cc7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file qurancom_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qurancom_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.1 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 |
f681c0664c206a784c5174fc0d59471dc1c8d76c98ebb0df4eaa58985beac5e7
|
|
| MD5 |
47c329f613d01fd4a8a1c912f38280f9
|
|
| BLAKE2b-256 |
59498a9ab768c7908ccdee23e6a7982a308cb6bb0baeb101bcebb90a7462fc5e
|
Provenance
The following attestation bundles were made for qurancom_py-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on ayoubanlouf/qurancom-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qurancom_py-0.1.0-py3-none-any.whl -
Subject digest:
f681c0664c206a784c5174fc0d59471dc1c8d76c98ebb0df4eaa58985beac5e7 - Sigstore transparency entry: 2680487301
- Sigstore integration time:
-
Permalink:
ayoubanlouf/qurancom-py@151b091a885b7245753b7010a403ca3735731cc7 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ayoubanlouf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@151b091a885b7245753b7010a403ca3735731cc7 -
Trigger Event:
release
-
Statement type: