Skip to main content

QuranMediaLib

Media producing library for Quranic texts. Generates beautifully formatted images of Quranic verses with Arabic text and translations.

Installation

From source (development)

# Clone the repository
git clone https://github.com/yourusername/quranmedialib.git
cd quranmedialib

# Install with uv (recommended)
uv pip install -e .

# Or with pip
pip install -e .

From PyPI (coming soon)

pip install quranmedialib

Quick Start

from quranmedialib import DatabaseManager, LayoutConfig, TextConfig, WordConfig
from quranmedialib.modules.wimage import get_wimage
from quranmedialib.modules.framer import frame
from quranmedialib.presets import LANDSCAPE_PRESET

# Initialize database manager (auto-loads packaged databases)
db = DatabaseManager()

# Get preset configuration for 1080p landscape
layout_config, text_config, word_config = LANDSCAPE_PRESET["default"]["1080p"]

# Render a single Arabic word
word_img = get_wimage("الله", word_config)

# Get verses from a surah
verses = db.get_verses_from_surah(1)  # Al-Fatiha
print(f"Surah 1 has {len(verses)} verses")

# Get word-by-word translation
wbw = db.get_wbw_from_verse(1, 1)  # First verse, word-by-word
print(f"First verse has {len(wbw)} words")

# Don't forget to close the database when done
db.close()

Usage with Workflows

from quranmedialib import DatabaseManager, SurahWorkflow, LANDSCAPE_PRESET
from quranmedialib.modules.image import glow

db = DatabaseManager()

# Create workflow with preset configuration
layout_config, text_config, word_config = LANDSCAPE_PRESET["default"]["1080p"]

workflow = SurahWorkflow(
    layout_config=layout_config,
    text_config=text_config,
    word_config=word_config,
)

# Process Surah Al-Fatiha (surah 1)
data = {"surah": 1}
iterator = workflow.get_iterator(data, annotate=True)

# Save generated pages
for page_num, page_images in enumerate(iterator, 1):
    for img, suffix in page_images:
        # Apply glow effect
        final_img = glow(img)
        final_img.save(f"output/surah1_page{page_num}_{suffix}.png")

db.close()

Package Structure

quranmedialib/
├── types.py           # Configuration dataclasses (LayoutConfig, WordConfig, etc.)
├── presets.py         # Pre-configured layouts (LANDSCAPE_PRESET, STORY_PRESET, etc.)
├── database_manager.py # Stateful database connection manager
├── resources.py       # Asset path resolution
├── modules/
│   ├── wimage.py      # Arabic word rendering
│   ├── timage.py      # Translation text rendering
│   ├── framer.py      # Multi-page layout engine
│   ├── image.py       # Image effects (glow, color, pad)
│   ├── annotation.py  # Word-by-word annotation
│   └── verse_number.py # Verse number rendering
└── workflows/
    ├── surah.py       # Surah-level processing
    ├── verse_range.py # Verse range processing
    └── isolate_words.py # Word isolation workflows

Presets

The library includes pre-configured presets for common formats:

  • LANDSCAPE_PRESET: 16:9 aspect ratio (1280x720, 1920x1080, etc.)
  • STORY_PRESET: 9:16 aspect ratio (720x1280, 1080x1920, etc.)
  • SQUARE_PRESET: 1:1 aspect ratio (720x720, 1080x1080, etc.)

Each preset supports multiple resolutions: 720p, 1080p, 1440p, 2160p

And three modes per format:

  • default: Arabic text with annotations + translation
  • arabic: Arabic text only (no translation)
  • translation: Translation only (no Arabic)
from quranmedialib.presets import LANDSCAPE_PRESET

# Access preset by mode and resolution
config = LANDSCAPE_PRESET["default"]["1080p"]
layout_config, text_config, word_config = config

Custom Database Configuration

Add your own translation databases:

from quranmedialib import DatabaseManager, DatabaseConfig, WbwDatabaseConfig

db = DatabaseManager()

# Add a custom translation database
custom_config = DatabaseConfig(
    filepath="/path/to/custom_translation.db",
    tablename="verses",
    surah_col="sura",
    ayah_col="ayah",
    text_col="text",
)
db.add_connection("my_translation", custom_config)

# Switch to custom translation
db.set_active_translation("my_translation")
verses = db.get_verses_from_surah(1)

# Add custom word-by-word database
wbw_config = WbwDatabaseConfig(
    filepath="/path/to/custom_wbw.db",
    tablename="wbw",
    surah_col="surah",
    ayah_col="ayah",
    text_col="translation",
    word_id_col="word",
)
db.add_connection("my_wbw", wbw_config)

Development

# Install with dev dependencies
uv pip install -e ".[dev]"

# Run tests
pytest tests/

# Lint with ruff
ruff check .

License

Apache License 2.0 - see LICENSE for details.

Release files for quranmedialib 1.0.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 quranmedialib 1.0.0
File Size Uploaded
quranmedialib-1.0.0.tar.gz 4.2 MB Details

Built distribution (wheel)

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

Total release size: 8.5 MB

Release files / quranmedialib-1.0.0.tar.gz

Download URL quranmedialib-1.0.0.tar.gz
Size 4.2 MB
Tags Source
SHA-256 checksum
How to use checksums
724e9ca4394cebebae7cbcb5afa58a1ad0064932f8ca8052bc01e6c931f3e7ba
BLAKE2b-256 checksum
How to use checksums
3cded800427231b7c18888e9a3042aa69734798ba82f2e8209b729b915a384db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.17

Release files / quranmedialib-1.0.0-py3-none-any.whl

Download URL quranmedialib-1.0.0-py3-none-any.whl
Size 4.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
c8fd25d9a6f0f9b9f2ac3641285a6a49d28d67bcabe1fd8bffcbe679249b618f
BLAKE2b-256 checksum
How to use checksums
66e3693780447e5540e74db5d06efa4fc4ef5edebefe74f358bf55d670deb7a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.17

Release history Release notifications | RSS feed

5.0.0

2 release files

4.2.0

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

This release

1.0.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