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

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.1.1
File Size Uploaded
quranmedialib-1.1.1.tar.gz 4.2 MB Details

Built distribution (wheel)

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

Total release size: 8.5 MB

Release files / quranmedialib-1.1.1.tar.gz

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

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

Download URL quranmedialib-1.1.1-py3-none-any.whl
Size 4.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b7c2f337a0e7f2342d64a095ed68378d167b0f534c2c59668d589af583744b74
BLAKE2b-256 checksum
How to use checksums
1f0b1f442dc7c1cdcba7b279ccff142c9d04394068897c2d660f1801e91d3a87
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

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

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