arabic-dictionary
A modern, open-source Arabic dictionary toolkit for Python.
from arabic_dictionary.application.dictionary import Dictionary
from arabic_dictionary.providers import WiktionaryProvider
from arabic_dictionary.repository import InMemoryRepository
d = Dictionary(
repository=InMemoryRepository(),
provider=WiktionaryProvider(),
)
entry = d.lookup("كتاب")
print(entry.root) # كتب
print(entry.plural) # كتب
print(entry.senses[0].meaning)
Features
- Look up Arabic words from Arabic Wiktionary with automatic parsing
- Load a local word list from a JSON file using
StaticProvider - Combine multiple providers with
CompositeProvider(first-match, with fallback) - Cache looked-up entries automatically in a repository (in-memory or SQLite)
- Extract root, plural, word type, examples, synonyms, and antonyms
- Normalize Arabic text (diacritics, alef variants, tā' marbūṭa, etc.)
- Supports both legacy and modern Arabic Wiktionary page formats
Installation
Requires Python 3.11+.
pip install arabic-dictionary
To install from source:
git clone https://github.com/rammo15/Arabic_Dictionary.git
cd Arabic_Dictionary
pip install -e ".[dev]"
Quick Start
Online lookup via Wiktionary
from arabic_dictionary.application.dictionary import Dictionary
from arabic_dictionary.providers import WiktionaryProvider
from arabic_dictionary.repository import InMemoryRepository
d = Dictionary(
repository=InMemoryRepository(),
provider=WiktionaryProvider(),
)
entry = d.lookup("كتاب")
if entry:
print(entry.text) # كتاب
print(entry.root) # كتب
print(entry.plural) # كتب
for sense in entry.senses:
print(sense.word_type) # WordType.NOUN
print(sense.meaning)
print(sense.examples)
print(sense.synonyms)
print(sense.antonyms)
The first call fetches the entry from Wiktionary and saves it to the repository. Subsequent calls for the same word are served from the repository (cache-aside).
Offline lookup from a JSON file
Prepare a JSON file (words.json):
{
"كتاب": {
"root": "كتب",
"plural": "كتب",
"senses": [
{
"meaning": "وعاء للمعرفة يُقرأ.",
"word_type": "noun",
"examples": ["هذا كتاب مفيد."],
"synonyms": ["سِفر"],
"antonyms": []
}
]
}
}
from arabic_dictionary.providers import StaticProvider
provider = StaticProvider.from_file("words.json")
entry = provider.lookup("كتاب")
Combining providers
Use CompositeProvider to try providers in order, returning the first match:
from arabic_dictionary.application.dictionary import Dictionary
from arabic_dictionary.providers import CompositeProvider, StaticProvider, WiktionaryProvider
from arabic_dictionary.repository import InMemoryRepository
provider = CompositeProvider([
StaticProvider.from_file("custom.json"), # checked first
WiktionaryProvider(), # fallback
])
d = Dictionary(
repository=InMemoryRepository(),
provider=provider,
)
entry = d.lookup("كتاب")
Architecture
Dictionary
│
┌────────┴────────┐
│ │
Repository (cache) Provider
│ │
SQLite / CompositeProvider
InMemory ├── StaticProvider
└── WiktionaryProvider
Dictionary is the main entry point. It owns a Repository for caching and an
optional Provider for live lookups. The Provider layer is composable and
independent — advanced users can inject any combination without touching Dictionary.
Domain model
| Class | Description |
|---|---|
Entry |
A single dictionary word with all its metadata |
Sense |
One meaning of a word |
WordType |
Grammatical category (NOUN, VERB, …) |
Providers
| Provider | Source |
|---|---|
WiktionaryProvider |
Arabic Wiktionary (online) |
StaticProvider |
Local JSON file (offline) |
CompositeProvider |
Ordered list of providers |
Repositories
| Repository | Description |
|---|---|
InMemoryRepository |
In-memory dict (tests / dev) |
SQLiteRepository |
Persistent SQLite database |
Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests including live network calls
pytest --run-network
# Lint
ruff check .
# Type check
mypy src/arabic_dictionary/domain tests
License
MIT
Metadata
Release files for arabic-dictionary 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| arabic_dictionary-0.2.0.tar.gz | 20.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| arabic_dictionary-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 40.1 kB
Release files / arabic_dictionary-0.2.0.tar.gz
| Download URL | arabic_dictionary-0.2.0.tar.gz |
|---|---|
| Size | 20.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c4a39ccf0529d9526b36205426136cb8b7ee8ccea8df0d1c05390f7a860d81e3
|
|
BLAKE2b-256 checksum How to use checksums |
4d528c83cccc001ddf66bf3667d0f57d5eabbae4e3ff409534e6559a959d9900
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / arabic_dictionary-0.2.0-py3-none-any.whl
| Download URL | arabic_dictionary-0.2.0-py3-none-any.whl |
|---|---|
| Size | 19.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25d10f8012a583073341764a9fbc1ca63798eadec68c80646084deca572ed450
|
|
BLAKE2b-256 checksum How to use checksums |
5f9a0df86703812690739d8e224ed629ce5c691d90c515fb7194d8df230951c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|