Skip to content

Words (تفقيط)

Guide: Amounts in words.

arapy.words.tafqeet

The Tafqeet config object and the to_words shortcut.

Tafqeet dataclass

Write numbers in Arabic words (تفقيط), optionally counting a noun or a currency.

from arapy import Currency, Gender, Noun, Tafqeet, to_words

qirsh = Noun.create("قرش", "قرشان", "قروش", gender=Gender.MASCULINE)

SYP = Currency.create(
    code="SYP",
    singular="ليرة سورية",
    dual="ليرتان سوريتان",
    plural="ليرات سورية",
    gender=Gender.FEMININE,
    subunit=qirsh,
)

cheque = Tafqeet(prefix="فقط", suffix="لا غير")

print(to_words(125))  # مئة وخمسة وعشرون
print(cheque("1250.50", SYP))  # فقط ألف ومئتان وخمسون ليرةً سوريةً وخمسون قرشًا لا غير
print(to_words.parse("مائة وخمسة وعشرون"))  # 125

parse

parse(text: str, unit: Noun | None = None) -> Decimal

Read words back into a number: to_words.parse("مئة وخمسة وعشرون") → 125.

Accepts مئة and مائة, every case, and text with or without this object's prefix and suffix; tashkeel is ignored. Pass the unit that was counted so its words (and, for a currency, its subunit words) can be read.

arapy.words.nouns

Counted nouns and currencies: gender, plural forms and the CLDR plural category.

PluralForm

Bases: StrEnum

Arabic CLDR plural categories.

Noun dataclass

A counted noun. Adjective agreement lives in each form.

dual_oblique (accusative/genitive dual, «ليرتين سوريتين») is derived from the dual when every word of it ends in ان.

create classmethod

create(
    singular: str,
    dual: str,
    plural: str,
    *,
    gender: Gender,
    many: str | None = None,
) -> Noun

Noun.create("ساعة", "ساعتان", "ساعات", gender=Gender.FEMININE)

Currency dataclass

Bases: Noun

A currency: a noun with an ISO 4217 code and a subunit worth 1/ratio of it.

arapy ships no built-in currencies; define the ones you need once and pass them around. symbol («ل.س», «$») is used by format_money; when empty, the code is shown instead.

create classmethod

create(
    *,
    code: str,
    singular: str,
    dual: str,
    plural: str,
    gender: Gender,
    subunit: Noun,
    ratio: int = 100,
    symbol: str = "",
    many: str | None = None,
) -> Currency

Define a currency from its three main forms.

from arapy import Currency, Gender, Noun
from arapy.words import PluralForm

qirsh = Noun.create("قرش", "قرشان", "قروش", gender=Gender.MASCULINE)

SYP = Currency.create(
    code="SYP",
    singular="ليرة سورية",
    dual="ليرتان سوريتان",
    plural="ليرات سورية",
    gender=Gender.FEMININE,
    subunit=qirsh,
    symbol="ل.س",
)

print(SYP.form(PluralForm.MANY))  # ليرةً سوريةً
print(SYP.dual_oblique)  # ليرتين سوريتين

plural_form

plural_form(n: int) -> PluralForm

CLDR category of n: 0 zero, 1 one, 2 two, n%100 in 3–10 few, 11–99 many, else other.

noun_forms

noun_forms(
    singular: str,
    dual: str,
    plural: str,
    *,
    many: str | None = None,
) -> Mapping[PluralForm, str]

Build all six forms from three: «ليرة سورية», «ليرتان سوريتان», «ليرات سورية».

many (the تمييز after 11–99) defaults to singular with tanween on every word: «ليرةً سوريةً», «دولارًا أمريكيًا».

arapy.words.grammar

Integer → Arabic words engine: gender agreement, case endings and hundreds spelling.

integer_to_words

integer_to_words(
    n: int,
    *,
    gender: Gender = Gender.MASCULINE,
    case: Case = Case.NOMINATIVE,
    hundreds: Hundreds = "مئة",
    construct: bool = False,
) -> str

Write an integer in Arabic words: 125000 → «مئة وخمسة وعشرون ألفًا».

gender sets agreement for the last group (below 1000); scale words are masculine. construct writes the last word as it stands before a counted noun: «ألفا», «مئتا», and «ألف» instead of «ألفًا».

arapy.words.parse

Arabic words → number: the inverse of Tafqeet.

parse_words

parse_words(
    text: str,
    unit: Noun | None = None,
    *,
    prefix: str = "",
    suffix: str = "",
) -> Decimal

Read an amount written in Arabic words.

Accepts مئة and مائة, every case, text with or without prefix/suffix, and ignores tashkeel. With a Currency, subunit words are read as fractions of unit.ratio.

arapy.words.money

Amounts in digits with a currency symbol: «١٢٬٥٠٠ ل.س».

format_money

format_money(
    value: int | Decimal | str,
    currency: Currency,
    *,
    digits: DigitSet = "arabic",
    grouping: str | None = "٬",
    decimal: str = "٫",
    places: int | None = None,
) -> str

Format an amount with the currency symbol (or its code when it has none).

Without places, whole amounts show no decimals and others are padded to the subunit places (2, or 3 for 1000-subunit currencies). Amounts finer than that raise InvalidNumberError: money is never rounded.