User guide¶
arapy is a set of small modules. Each page covers one of them with examples you can paste
and run: every python block in these docs is executed by the test suite, and the comment
after each print() is its output.
| Module | What it does | Page |
|---|---|---|
arapy.words |
numbers, counted nouns and money in words (تفقيط), and back | Amounts in words |
arapy.digits |
Arabic, Persian and Latin digits; exact parsing and formatting | Digits and numbers |
arapy.normalize |
composable rules that fold letters and strip marks; matching | Normalization |
arapy.sort |
Arabic alphabetical order | Sorting |
arapy.ordinals |
الأول، الأولى، الحادي عشر، أولًا | Ordinals |
arapy.dates |
ArDate, ArDateTime, HijriDate, Arabic formatting and parsing |
Dates |
arapy.dates |
«منذ ثلاثة أيام», «سنة وثلاثة أشهر» | Relative times and durations |
arapy.shape |
joined, visually ordered text for Pillow, ReportLab and ZPL | Shaping |
Conventions across the package¶
- Imports. The names you use most are importable from
arapyitself. Less common ones live in their module:arapy.words.PluralForm,arapy.normalize.rules.fold_alef,arapy.dates.HIJRI_MONTHS. - Numbers in. Functions that take a number accept
int,Decimalor a string in any digit set. Strings go throughparse_number, so"١٢٥٠٫٥"and"1,250.5"both work.floatis not accepted: it cannot hold money exactly. - Nothing is rounded. A value with more decimal places than the output allows raises
InvalidNumberErrorinstead of being rounded or cut. - Frozen config objects.
Tafqeet,Noun,Currency,NormalizerandHijriDateare immutable. Build them once, at module level, and pass them around. - No global registry. arapy ships no currencies and registers nothing. You define the currencies and nouns you need as values.
- Errors. Every error subclasses
ArapyErrorand the matching built-in exception. See Errors.