Python SDK
عميل Python متزامن وغير متزامن. يدعم Python 3.9+. مبني على httpx.
التثبيت
pip install kalimalabاستخدم بيئة افتراضية:
python -m venv .venv && source .venv/bin/activateتهيئة العميل
import osfrom kalimalab import KalimaLabclient = KalimaLab(api_key=os.environ["KALIMALAB_API_KEY"])الطرق
client.words.searchابحث في الكلمات العربية مع فلاتر اختيارية.
client.words.search( q: str, limit: int = 20, offset: int = 0, root: str | None = None, pos: str | None = None, letters: int | None = None,) -> SearchResult| Param | Type | Req | Description |
|---|---|---|---|
q | str | Yes | استعلام البحث |
limit | int | No | 1-100. الافتراضي: 20 |
offset | int | No | الإزاحة. الافتراضي: 0 |
root | str | None | No | فلتر بالجذر |
pos | str | None | No | فلتر تصنيف الكلام |
letters | int | None | No | عدد الأحرف المحدد |
result = client.words.search(q="كتب", limit=5)print(result.total) # 47print(result.data[0].word) # 'كتب'client.words.getجلب التفاصيل الكاملة لكلمة واحدة.
client.words.get(slug: str) -> Word| Param | Type | Req | Description |
|---|---|---|---|
slug | str | Yes | slug الكلمة أو معرّفها |
word = client.words.get("كتب")print(word.meaning_en) # 'to write'client.words.dailyاحصل على كلمة اليوم.
client.words.daily() -> Wordword = client.words.daily()print(word.word) # 'الأَمَل'client.words.validateتحقق من صحة الكلمات العربية في قاعدة البيانات.
client.words.validate(words: list[str]) -> ValidationResult| Param | Type | Req | Description |
|---|---|---|---|
words | list[str] | Yes | حتى 100 كلمة |
result = client.words.validate(["كتب", "xyz", "مدرسة"])print(result.valid) # ['كتب', 'مدرسة']print(result.invalid) # ['xyz']client.text.analyzeحلّل مقطعاً من النص العربي.
client.text.analyze(text: str) -> TextAnalysis| Param | Type | Req | Description |
|---|---|---|---|
text | str | Yes | نص عربي (حد أقصى 5,000 حرف) |
analysis = client.text.analyze("بسم الله الرحمن الرحيم")print(analysis.word_count) # 4الاستخدام غير المتزامن
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())معالجة الأخطاء
from kalimalab import KalimaLabErrortry: result = client.words.search(q="كتب")except KalimaLabError as e: print(e.status) print(e.code) print(e.message)