PyArud (پَايْعَرُوضْ)
PyArud is a deterministic, high-performance, zero-dependency Python engine for Classical & Modern Arabic Prosody (علم العروض والقافية). It delivers formal Farahidian grammar scansion across all 16 classical meters (البحور الستة عشر) and their authentic sub-meters (التام، المجزوء، المشطور، المنهوك، المخلّع), opt-in support for the 6 neglected Farahidian circle meters (البحور المهملة), an extensible API for custom user-defined & modern free-verse (التفعيلة) meters, foot-by-foot Zihaf & 'Ilal diagnosis, and complete rhyme (القافية) & rhyme-fault (عيوب القافية) analysis.
✨ Features
- 🚀 Zero Runtime Dependencies: 100% pure Python 3.12+ standard library. No
pyarabicor heavy C extensions. - ⚡ High Throughput:
- Phonetic Arudi Alignment (
1:1letter-to-bit bijection): ~10,000 hemistichs/second - Full Deterministic Multi-Meter Verse Scansion: >2,200 verses/second
- Phonetic Arudi Alignment (
- 🎼 Full 16-Meter Farahidian Coverage + Opt-In Muhmal Pack: All 16 classical meters (29 authentic forms across Tam, Majzoo, Mashtoor, Manhook, Mukhalla'), enforcing المراقبة (Muraqabah), المعاقبة (Mu'aqabah), الاعتماد (I'timad), and التصريع (Tasri'), plus an opt-in pack (
include_muhmal=True) for the 6 neglected circle meters (المستطيل، الممتد، المتوفر، المتئد، المنسرد، المطرد). - 🧩 Custom User-Defined & Free-Verse Meters: Declarative, immutable
MeterSpec,TafeelaSpec,ProsodicRule, fluentMeterBuilder, JSON/TOML loading, and persistent non-mutatingMeterRegistryfor modern التفعيلة free verse, asymmetric Andalusian الموشحات, and personal meters. - 🔬 Granular Slot-Viterbi Foot Scansion: Exact per-foot status (
ok,broken,missing,extra_bits), real surface Arabic foot forms (actual_tafeelavsbase_tafeela), per-foot Arudi text slices (foot.arudi_text), and exact Arabic & English Zihaf/'Ilal diagnosis. - 📜 Complete Qafiyah & Rhyme-Fault Analysis: Identifies Rawi (الروي), Wasl (الوصل), Khuruj (الخروج), Ridf (الردف), Ta'sees (التأسيس), Dakhil (الدخيل), all 6 classical movements (المجرى، النفاذ، الحذو، الإشباع، الرس، التوجيه), rhythmic & structural types, opening-verse Tasri', and poem-level rhyme faults (الإقواء، الإصراف، الإكفاء، الإجازة، السناد، الإيطاء).
- 🎨 Bilingual Formatters, CLI & Agent Skill:
format_verse_report/format_poem_report(ar/en,pretty/compact/markdown), zero-deppyarud/arudCLI,.to_dict()/.to_json(), plus a bundled AI Agent Skill atskills/arud/SKILL.md. - 🛡️ Strict Typing (PEP 561): Verified with
mypy --strictacross the entire package.
🚀 Installation
Requires Python 3.12+.
pip install pyarud
Or with uv:
uv add pyarud
⚡ Quick Start
from pyarud import ArudProcessor, format_verse_report
processor = ArudProcessor()
# 1. Analyze a classical verse (Sadr & Ajuz)
verse = ("أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى", "فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا")
analysis = processor.analyze_verse(*verse)
print(f"Meter: {analysis.meter_name_ar} ({analysis.meter_key}, {analysis.bahr_type})")
print(f"Score: {analysis.score:.2%} | Valid: {analysis.is_valid} | Tasri': {analysis.is_tasri}")
# Foot-by-foot breakdown with Arudi slices
if analysis.sadr:
print(f"Sadr Arudi: {analysis.sadr.arudi_text} [{analysis.sadr.pattern}]")
for foot in analysis.sadr.feet:
print(
f" [{foot.status.upper()}] {foot.actual_tafeela} ({foot.actual_segment}) "
f"«{foot.arudi_text}» — {foot.zihaf_name_ar}"
)
# Rhyme (Qafiyah)
if analysis.qafiyah:
print(f"Rawi: {analysis.qafiyah.rawi} | Type: {analysis.qafiyah.qafiyah_type_ar}")
# Rich terminal or Markdown report (Arabic or English)
print(format_verse_report(analysis, lang="ar", style="pretty"))
Analyzing Complete Poems & Rhyme Faults
from pyarud import ArudProcessor
processor = ArudProcessor()
verses = [
("قِفَا نَبْكِ مِنْ ذِكْرَى حَبِيبٍ وَمَنْزِلِ", "بِسِقْطِ اللِّوَى بَيْنَ الدَّخُولِ فَحَوْمَلِ"),
("فَتُوضِحَ فَالْمِقْرَاةِ لَمْ يَعْفُ رَسْمُهَا", "لِمَا نَسَجَتْهَا مِنْ جَنُوبٍ وَشَمْأَلِ"),
]
poem = processor.analyze_poem(verses)
print(f"Global Meter: {poem.meter_name_ar} ({poem.bahr_type})")
print(f"Homogeneous: {poem.is_homogeneous} | Tasri': {poem.has_tasri}")
print(f"Dominant Rawi: {poem.dominant_rawi} | Rhyme Faults: {len(poem.rhyme_faults)}")
print(f"Average Confidence: {poem.average_score:.2%}")
Custom User-Defined & Free-Verse Meters
from pyarud import ArudProcessor, MeterSpec
from pyarud.meters.specs import EDMAAR, HATHATH, MUTAFAELON, QATAA, SALIM
# 1. Opt-in 6 neglected Farahidian meters (البحور المهملة)
muhmal_proc = ArudProcessor(include_muhmal=True)
res = muhmal_proc.analyze_verse(
"لَقَدْ هَاجَ اشْتِيَاقِي غَزَالٌ فِي المَرَاعِي",
"أَمِيرُ الحُسْنِ يَزْهُو عَلَى كُلِّ البِقَاعِ",
)
print(res.meter_name_ar, res.meter_key, res.is_valid) # بحر المستطيل mustateel True
# 2. Modern Arabic free-verse (شعر التفعيلة) with variable foot count
free_kamel = MeterSpec.free_verse(
key="tafeela_kamel",
name_ar="تفعيلة الكامل",
name_en="Free-Verse Kamel",
foot=MUTAFAELON,
min_feet=1,
max_feet=8,
ending_rules=(SALIM, EDMAAR, QATAA, HATHATH),
)
free_proc = ArudProcessor().with_meters(free_kamel, prefer_custom=True)
line = free_proc.analyze_verse("مُتَفَاعِلُنْ مُتَفَاعِلُنْ مُتَفَاعِلُنْ مُتَفَاعِلُنْ مُتَفَاعِلُنْ")
print(line.meter_name_ar, len(line.sadr.feet) if line.sadr else 0, line.is_valid)
💻 Command-Line Interface (pyarud / arud)
PyArud includes a zero-dependency CLI (pyarud, arud, or python -m pyarud) with UTF-8 JSON stdout, stderr error reporting, and CI-friendly --strict exit codes (0 valid, 1 broken/rhyme fault, 2 error):
# Scan a classical verse (pretty, compact, markdown, or json)
pyarud scan "قِفَا نَبْكِ مِنْ ذِكْرَى حَبِيبٍ وَمَنْزِلِ ... بِسِقْطِ اللِّوَى بَيْنَ الدَّخُولِ فَحَوْمَلِ" --format json --strict
# Phonetic Kitabah 'Arudiyyah & classical //0 scansion
pyarud arudi "أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى" --notation classical
# Rhyme (Qafiyah) & poem-level rhyme-fault analysis
pyarud qafiyah -f poem.txt --format json
# Inspect meters (with opt-in Muhmal or custom TOML/JSON) & zihafs
pyarud meters --show taweel
pyarud zihafs --tafeela "فَعُولُنْ"
# Step-by-step pedagogical explanation
pyarud explain "أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى ... فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا" --lang en
🤖 Arud AI Agent Skill (skills/arud/)
LLMs struggle with deterministic Arabic syllable counting and Kitabah 'Arudiyyah natively. This repository ships an open-standard Arud Agent Skill at skills/arud/SKILL.md (with concise prosody, phonetics/Qafiyah, and custom-meter reference sheets under skills/arud/references/) that pairs any coding/writing agent with the pyarud CLI for a verified Compose → Diacritize → Scan (--strict --format json) → Repair loop.
Installable directly from this repo with Agent Skills tooling (excluded from the PyPI wheel to keep runtime packaging lean).
📊 Benchmarks & Test Coverage
Verified across 234 unit, classical, custom-meter, Qafiyah, CLI, Agent Skill, and real-world benchmark tests (including 27 curated classical meter/sub-meter entries and 80 real diacritized poems from Al-Diwan across all 16 meters):
| Metric | Result |
|---|---|
| Full Test Suite | 234 / 234 passed (~1.2s) |
| Classical & Unseen Meter Benchmarks | 100.0% (27/27 curated + 80/80 unseen) |
| Arudi ↔ Binary 1:1 Alignment Invariant | 100.0% (0 mismatches) |
| Phonetic Conversion Throughput | ~10,000 hemistichs / sec |
| Full Verse Scansion Throughput | >2,200 verses / sec |
| External Runtime Dependencies | 0 (Zero) |
🛠️ Testing & Development
git clone https://github.com/cnemri/pyarud.git
cd pyarud
# Install dev dependencies (PEP 735 dependency-groups)
uv sync --group dev
# Run complete test suite
uv run pytest
# Lint & strict type check
uv run ruff check .
uv run mypy .
📄 Changelog & License
See CHANGELOG.md for full release notes (latest: v2.0.0).
This project is licensed under the MIT License.
Metadata
Release files for pyarud 2.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyarud-2.0.0.tar.gz | 261.7 kB | Without provenance | Details for pyarud-2.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyarud-2.0.0-py3-none-any.whl | Python 3 | none | any | Details for pyarud-2.0.0-py3-none-any.whl |
Total release size: 386.2 kB
Release files / pyarud-2.0.0.tar.gz
| Download URL | pyarud-2.0.0.tar.gz |
|---|---|
| Size | 261.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74f06981a938ccb5657fc67cbd39e1dd55eacf1d7d05a788c870776abc0cf996
|
|
BLAKE2b-256 checksum How to use checksums |
4aafd21575d0267cb2d3a8e4565b5fc6c731c317d8c06899621632de77118717
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / pyarud-2.0.0-py3-none-any.whl
| Download URL | pyarud-2.0.0-py3-none-any.whl |
|---|---|
| Size | 124.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0bf3b3a6e3840ff08b24fe0689d8f3f41d6e6c53807ff504db7d4bd6d639f2eb
|
|
BLAKE2b-256 checksum How to use checksums |
12edf6d94240854a189d5eb15d32b5f7a8b6ee9de65ad91e7c0d5c796e10c7c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for pyarud 2.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.