Skip to main content

shamy-arabic-nlp

PyPI version Python versions License: MIT tests

Arabic text tools in pure Python: normalization, Arabizi (Latin chat Arabic) to Arabic script, and a trainable dialect classifier baseline. No dependencies, no models to download.

مكتبة بايثون للغة العربية بدون اعتماديات: توحيد النص، تحويل الفرانكو/العربيزي إلى حروف عربية، ونموذج أساسي لتصنيف اللهجة.

>>> from shamy_arabic import normalize, arabizi_to_arabic, predict_dialect
>>> normalize("أَحْمَد جداااا ٣")
'احمد جدا 3'
>>> arabizi_to_arabic("ezayak ya 7abibi")
'ازيك يا حبيبي'
>>> predict_dialect("ازيك يا باشا عامل ايه")
'EGY'

What is in here

  1. Normalizer (shamy_arabic.normalize): strips tashkeel and tatweel, unifies alef forms, converts Arabic-Indic and Persian digits to 0-9, maps Arabic punctuation, collapses stretched letters and extra whitespace. Every rule is a keyword argument you can turn off.
  2. Arabizi to Arabic (shamy_arabic.arabizi_to_arabic): rule based conversion tuned for Egyptian, Levantine and Gulf chat spelling. Handles the digit letters (2 3 5 6 7 8 9), digraphs (sh kh gh th dh ch), the el/al definite article, word-final -a as ta marbuta (madrasa -> مدرسة), and a lexicon of common Egyptian, Levantine and Gulf words (3ayez -> عايز, a2ol -> اقول, 7aga -> حاجة). is_arabizi() tells you whether a string looks like Arabizi at all.
  3. Dialect classifier (shamy_arabic.DialectClassifier): multinomial Naive Bayes over word and character n-grams for MSA, Egyptian (EGY), Gulf (GLF), Levantine (LEV) and Maghrebi (MAG). Ships with a small seed corpus, trains on your own data in a few lines, and serializes to JSON.

Install

pip install shamy-arabic-nlp

Python 3.8 or newer. No dependencies.

Quick start

from shamy_arabic import (
    normalize, strip_diacritics, to_ascii_digits, squeeze_repeats,
    arabizi_to_arabic, is_arabizi,
    DialectClassifier, default_classifier, predict_dialect, DIALECTS,
)

normalize("أَحْمَد  إبراهيم آمن؟")        # 'احمد ابراهيم امن?'
normalize("مصرررر ٣")                     # 'مصر 3'
normalize("على", ya=True)                 # 'علي'
normalize("مدرسة", ta_marbuta=True)       # 'مدرسه'
normalize("مدرسة")                        # 'مدرسة'  (left alone by default)

strip_diacritics("مُحَمَّدٌ")              # 'محمد'
to_ascii_digits("٢٠٢٤ و۱۲")                # '2024 و12'
squeeze_repeats("جداااا", 1)               # 'جدا'

arabizi_to_arabic("ana 3ayez a2ol 7aga")  # 'انا عايز اقول حاجة'
arabizi_to_arabic("ahlan, ezayak?")       # 'اهلا، ازيك؟'
is_arabizi("ana 3ayez a2ol 7aga")         # True

predict_dialect("ازيك يا باشا عامل ايه")   # 'EGY'

API

Name Signature What it does
normalize (text, *, alef=True, ya=False, ta_marbuta=False, digits=True, punct=True, repeats=1, diacritics=True) Full pipeline. repeats=0 disables collapsing; ya and ta_marbuta are off because they change meaning in dialects.
strip_diacritics (text) Removes harakat, shadda, sukun, dagger alef and tatweel.
to_ascii_digits (text) Arabic-Indic and Persian digits to 0-9.
squeeze_repeats (text, keep=2) Collapses runs of 3+ identical characters.
arabizi_to_arabic (text) Converts Arabizi words, leaves Arabic text and numbers alone.
is_arabizi (text) Heuristic: Latin letters plus Arabizi digits or known words.
DialectClassifier (alpha=0.3) .fit(data), .predict(text), .predict_proba(text), .accuracy(data), .save(path), DialectClassifier.load(path).
default_classifier () Lazily trained classifier over the built-in corpus.
predict_dialect (text) One of DIALECTS = ("MSA", "EGY", "GLF", "LEV", "MAG").

Training on your own data

fit() accepts either a dict of label -> [sentences] or an iterable of (text, label) pairs:

from shamy_arabic import DialectClassifier

clf = DialectClassifier().fit({
    "EGY": ["ازيك يا باشا عامل ايه", "انا رايح الشغل دلوقتي"],
    "GLF": ["شلونك يا طويل العمر", "وين رايح الحين"],
})
clf.predict("شلونك عساك بخير")     # 'GLF'
clf.predict_proba("ازيك")          # {'EGY': 1.0, 'GLF': 0.0}  (sharp on a tiny training set)
clf.save("dialect.model.json")
clf2 = DialectClassifier.load("dialect.model.json")

For real work, retrain on a proper dataset. MADAR and NADI are the usual starting points; check their licences first.

Honest limits

  • Arabizi is ambiguous. Short vowels are not written, so kitab could be several words. The digit 2 is both hamza and qaf: the letter rule maps it to ء, and the lexicon covers the common qaf words (a2ol -> اقول, 2alb -> قلب, 2ahwa -> قهوة). Word-final -a is treated as ta marbuta, which is right for most nouns (madrasa -> مدرسة) and wrong for a few particles. The converter leans on a lexicon for common words and on letter rules otherwise: good on common chat words, rough elsewhere. Extend LEXICON in shamy_arabic/arabizi.py for your own domain.
  • The dialect model is a baseline, not a product. It is trained on about 100 short sentences written for this repository (shamy_arabic/_corpus.py) and tested on 15 held-out ones. High accuracy there does not mean it works on real social media text.
  • Normalization is deliberately conservative. ya and ta_marbuta are opt-in because Egyptian spelling distinguishes ى/ي and ة/ه in ways that matter for matching.

Development

git clone https://github.com/omarelshamy25x/shamy-arabic-nlp.git
cd shamy-arabic-nlp
pip install -e .
pip install pytest
pytest -q

Contributing

Contributions are welcome. Read CONTRIBUTING.md first, and look at the issues labelled good first issue. Small, focused pull requests that come with a test are the easiest to merge.

License

MIT. See LICENSE. Copyright (c) 2026 Omar Elshamy.

Metadata

Release files for shamy-arabic-nlp 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shamy-arabic-nlp 0.1.3
File Size Uploaded Provenance Actions
shamy_arabic_nlp-0.1.3.tar.gz 17.6 kB Without provenance Details for shamy_arabic_nlp-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shamy-arabic-nlp 0.1.3
File Interpreter ABI Platform Actions
shamy_arabic_nlp-0.1.3-py3-none-any.whl Python 3 none any Details for shamy_arabic_nlp-0.1.3-py3-none-any.whl

Total release size: 32.1 kB

Release files / shamy_arabic_nlp-0.1.3.tar.gz

Download URL shamy_arabic_nlp-0.1.3.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b1e4f338e40ca577d0c5c55179e555e3ad220a85c2a2b7e670e8d80bee9b2c70
BLAKE2b-256 checksum
How to use checksums
31ae48cae23477bc2c1ad5141aed4ba41e4de5bbb6c28e323c143d83ad679a6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Release files / shamy_arabic_nlp-0.1.3-py3-none-any.whl

Download URL shamy_arabic_nlp-0.1.3-py3-none-any.whl
Size 14.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca953ae9eef62c4d9c6ce9d743bbd2005646dabbd4719a90d2c1361bd8d2af94
BLAKE2b-256 checksum
How to use checksums
e3be25cdbd921f4d944fd93b82ea5665c92d5dfe704dacd57315c66b7141a7ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.12

Security for shamy-arabic-nlp 0.1.3

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.

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