Skip to main content

qurancom-py

PyPI Version Python Versions License: MIT CI/CD

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 with slots=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

qurancom_py-0.1.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distribution

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

qurancom_py-0.1.0-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

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

Hashes for qurancom_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d41891af9fd41ab5559180864e5dd96ac51918d9ea031d17486092682e7366e1
MD5 6c5444cb058e3d0d62d959f10784d581
BLAKE2b-256 1b543e8e8b6affe93aabbf23e0cdf107e8307f2c45902d643f7355b4a3e4713a

See more details on using hashes here.

Provenance

The following attestation bundles were made for qurancom_py-0.1.0.tar.gz:

Publisher: publish.yml on ayoubanlouf/qurancom-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for qurancom_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f681c0664c206a784c5174fc0d59471dc1c8d76c98ebb0df4eaa58985beac5e7
MD5 47c329f613d01fd4a8a1c912f38280f9
BLAKE2b-256 59498a9ab768c7908ccdee23e6a7982a308cb6bb0baeb101bcebb90a7462fc5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for qurancom_py-0.1.0-py3-none-any.whl:

Publisher: publish.yml on ayoubanlouf/qurancom-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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