Command-Line Interface (CLI)¶
PyArud ships a zero-dependency CLI installed automatically as both pyarud and arud (and runnable via python -m pyarud).
Contract for Shell Pipelines, CI & AI Agents
- Zero external dependencies: Built strictly on Python's standard library (
argparse,json,tomllib). - Clean stream separation: Structured UTF-8 JSON (
ensure_ascii=False) onstdout; diagnostics and errors strictly onstderr. - Deterministic exit codes:
0— Success (and valid with zero error-severity rhyme faults under--strict).1— Metrically broken verse/poem or error-severity rhyme fault under--strict.2— CLI usage error, missing file, malformed TOML/JSON, orPyArudError(MeterNotFoundError,InvalidMeterSpecError,TashkeelError).
Subcommands Overview¶
| Command | Purpose |
|---|---|
pyarud scan |
Analyze a hemistich, verse, or multi-verse poem (meter, feet, Zihafat/'Ilal, Qafiyah, rhyme faults). |
pyarud arudi |
Transcribe Arabic text to Kitabah 'Arudiyyah with binary (1/0) and classical (//0) notation. |
pyarud qafiyah |
Extract Qafiyah letters, 6 classical movements, Tasri', and poem-level rhyme faults. |
pyarud meters |
List registered meters or inspect a specific meter's feet and Arudh/Dharb matrix. |
pyarud zihafs |
List classical Zihafat & 'Ilal or inspect transformations for a specific Taf'ilah. |
pyarud explain |
Print a step-by-step pedagogical walkthrough of normalization, Arudi script, feet, alternatives, and Qafiyah. |
1. pyarud scan¶
Scan a single verse (Sadr ... Ajuz, Sadr * Ajuz, or Sadr | Ajuz), explicit --sadr / --ajuz, a poem file (-f poem.txt), or stdin (-):
# Single verse (Arabic pretty output)
pyarud scan "قِفَا نَبْكِ مِنْ ذِكْرَى حَبِيبٍ وَمَنْزِلِ ... بِسِقْطِ اللِّوَى بَيْنَ الدَّخُولِ فَحَوْمَلِ"
# Structured UTF-8 JSON + CI-friendly --strict exit code
pyarud scan --sadr "أَخِي جَاوَزَ الظَّالِمُونَ الْمَدَى" \
--ajuz "فَحَقَّ الْجِهَادُ وَحَقَّ الْفِدَا" \
--format json --strict
# Opt-in 6 Muhmal meters (circle meters)
pyarud scan --include-muhmal \
--sadr "لَقَدْ هَاجَ اشْتِيَاقِي غَزَالٌ فِي المَرَاعِي" \
--ajuz "أَمِيرُ الحُسْنِ يَزْهُو عَلَى كُلِّ البِقَاعِ"
# Custom TOML/JSON meters (repeatable --custom-meters)
pyarud scan "مُتَفَاعِلُنْ مُتَفَاعِلُنْ مُتَفَاعِلُنْ" \
--custom-meters custom_meters.toml --prefer-custom --format json
Key flags: -m/--meter KEY, --poem, --custom-meters PATH (repeatable), --include-muhmal, --prefer-custom, --validate-tashkeel, --format {pretty,json,compact,markdown}, --lang {ar,en}, --color/--no-color, --strict.
2. pyarud arudi¶
Transcribe Arabic text to phonetic Kitabah 'Arudiyyah and scansion symbols (1/0 or //0):
pyarud arudi "قِفَا نَبْكِ مِنْ ذِكْرَى حَبِيبٍ وَمَنْزِلِ" --notation classical
pyarud arudi "إِذَا الْغَيْثُ هَمَلْ" --muqayyad --format json
JSON output keys: original_text, arudi_text, pattern, classical_pattern, tashkeel_ratio, is_muqayyad, words.
3. pyarud qafiyah¶
Analyze a single hemistich, a full verse (checking Tasri' against the Sadr), or a multi-line poem file/stdin (detecting poem-level عيوب القافية):
pyarud qafiyah "قِفَا نَبْكِ مِنْ ذِكْرَى حَبِيبٍ وَمَنْزِلِ ... بِسِقْطِ اللِّوَى بَيْنَ الدَّخُولِ فَحَوْمَلِ" --format json
pyarud qafiyah -f poem.txt --lang en --format json
Poem-mode JSON keys: dominant_rawi, has_tasri, rhyme_faults, verses.
4. pyarud meters & pyarud zihafs¶
Inspect classical, Muhmal, and custom meters or per-tafeela Zihafat & 'Ilal:
pyarud meters --list --include-muhmal
pyarud meters --show taweel --format json
pyarud zihafs --list --lang en
pyarud zihafs --tafeela "فَعُولُنْ" --format json
5. pyarud explain¶
Generate a step-by-step pedagogical walkthrough (diacritization ratio → Kitabah 'Arudiyyah + binary & /0 pattern → foot-by-foot alignment → runner-up alternatives → Qafiyah):