Skip to main content

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("كتاب")

Examples

Runnable examples are available in the examples/ directory:

File Description
basic_lookup.py Online lookup via Wiktionary, prints all fields
static_provider.py Offline lookup from a local JSON file
composite_provider.py Local overrides with Wiktionary fallback

Project Status

Current version: 0.2.0 — the core architecture is stable and the library is usable.

What is supported

  • Arabic Wiktionary lookup (both legacy and modern page formats)
  • Offline lookup from a local JSON file (StaticProvider)
  • Composing multiple providers with fallback (CompositeProvider)
  • Automatic caching in-memory or SQLite
  • Extracted fields: root, plural, word type, meanings, examples, synonyms, antonyms
  • Arabic text normalization (diacritics, alef variants, tā' marbūṭa, yā', taṭwīl)

What is not yet supported

  • Pronunciation / transliteration
  • Verb conjugation tables
  • Word frequency or corpus data
  • Search across the full repository (partial match, root search)
  • Streaming / batch import of large word lists

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

Entry
├── text        str               the word as stored
├── root        str | None        trilateral/quadrilateral root
├── plural      str | None        broken plural form
├── source      str | None        provider name that produced this entry
└── senses      list[Sense]
      ├── meaning    str           definition text
      ├── word_type  WordType | None
      ├── examples   list[str]
      ├── synonyms   list[str]
      └── antonyms   list[str]

WordType values: NOUN, VERB, ADJECTIVE, ADVERB, PARTICLE, PRONOUN, PREPOSITION, CONJUNCTION, INTERJECTION, PHRASE.

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.2

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

Source distribution (sdist)

Source distribution for arabic-dictionary 0.2.2
File Size Uploaded
arabic_dictionary-0.2.2.tar.gz 23.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for arabic-dictionary 0.2.2
File Interpreter ABI Platform
arabic_dictionary-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 44.0 kB

Release files / arabic_dictionary-0.2.2.tar.gz

Download URL arabic_dictionary-0.2.2.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
771e38df9bc10dc6aa5facb14d4c0dccdcb2db4127ebf4c16ecbc6d0b750d327
BLAKE2b-256 checksum
How to use checksums
6554de151636619b905874a35bc8a5d4feb763601be0b5b585f82ff8a2f81996
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.2-py3-none-any.whl

Download URL arabic_dictionary-0.2.2-py3-none-any.whl
Size 20.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1911e944cf941443e3b50a0ce527522857a86dadb4f74a9a3c723aea5a64c31c
BLAKE2b-256 checksum
How to use checksums
46a49607698e7b0b84416b212ced7b40ee2a8939efe953bce065f76fb7172baa
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 history Release notifications | RSS feed

0.2.3

2 release files

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

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