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

جلب التفاصيل الكاملة لكلمة واحدة.

client.words.get(slug: str) -> Word
ParamTypeReqDescription
slugstrYesslug الكلمة أو معرّفها
word = client.words.get("كتب")print(word.meaning_en) # 'to write'
client.words.daily

احصل على كلمة اليوم.

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

تحقق من صحة الكلمات العربية في قاعدة البيانات.

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

حلّل مقطعاً من النص العربي.

client.text.analyze(text: str) -> TextAnalysis
ParamTypeReqDescription
textstrYesنص عربي (حد أقصى 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)