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, including small ones. You do not need to ask first.

  1. Pick an issue labelled good first issue and comment that you are taking it.
  2. Fork the repo and install it with pip install -e ., then run python -m pytest.
  3. Make one focused change with a test, and open a pull request that says what it changes and why.

Details are in CONTRIBUTING.md. Arabic and English are both fine in issues and pull requests.

License

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

Metadata

Release files for shamy-arabic-nlp 0.1.4

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.4
File Size Uploaded Provenance Actions
shamy_arabic_nlp-0.1.4.tar.gz 19.3 kB Without provenance Details for shamy_arabic_nlp-0.1.4.tar.gz

Built distribution (wheel)

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

Total release size: 34.6 kB

Release files / shamy_arabic_nlp-0.1.4.tar.gz

Download URL shamy_arabic_nlp-0.1.4.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8981c6375d8b5a773dc674aac3dda07c3382151244c7f4aefbe1b4fe514051a1
BLAKE2b-256 checksum
How to use checksums
c95d19d59d1a34513b7dd505c23b5d1cd1d6c3c87687dae30d3a41ea0f0c8c5b
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.4-py3-none-any.whl

Download URL shamy_arabic_nlp-0.1.4-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7182b38f4fbfa48f2a00bc37dfaaaacb4374245452ff9a95f8c6972aacf0f10
BLAKE2b-256 checksum
How to use checksums
7cd8d8b46117d619735007b746daf42e36831c91a2194d4c5c34489c5bf14cd1
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.4

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