Python SDK

Sync and async Python client. Supports Python 3.9+. Built on httpx.

Installation

bash
pip install kalimalab
Use a virtual environment: python -m venv .venv && source .venv/bin/activate

Client initialization

import osfrom kalimalab import KalimaLabclient = KalimaLab(api_key=os.environ["KALIMALAB_API_KEY"])

Methods

client.words.get

Fetch full details for a single word.

python
client.words.get(slug: str) -> Word
ParamTypeReqDescription
slugstrYesWord slug or ID
python
word = client.words.get("كتب")print(word.meaning_en) # 'to write'
client.words.daily

Get the word of the day.

python
client.words.daily() -> Word
python
word = client.words.daily()print(word.word) # 'الأَمَل'
client.words.validate

Validate Arabic words against the database.

python
client.words.validate(words: list[str]) -> ValidationResult
ParamTypeReqDescription
wordslist[str]YesUp to 100 words
python
result = client.words.validate(["كتب", "xyz", "مدرسة"])print(result.valid)   # ['كتب', 'مدرسة']print(result.invalid) # ['xyz']
client.text.analyze

Analyze a passage of Arabic text.

python
client.text.analyze(text: str) -> TextAnalysis
ParamTypeReqDescription
textstrYesArabic text (max 5,000 characters)
python
analysis = client.text.analyze("بسم الله الرحمن الرحيم")print(analysis.word_count) # 4

Async usage

python
import asynciofrom kalimalab import AsyncKalimaLabasync def main():    async with AsyncKalimaLab(api_key="...") as client:        result = await client.words.search(q="كتب")        print(result.total)asyncio.run(main())

Error handling

python
from kalimalab import KalimaLabErrortry:    result = client.words.search(q="كتب")except KalimaLabError as e:    print(e.status)    print(e.code)    print(e.message)