NAWA API SDK - Arabic language intelligence
Project description
nawa-sdk
Official Python SDK for the NAWA API — Arabic-first AI comment classification.
Install
pip install nawa-sdk
Quickstart
from nawa import Nawa
client = Nawa(api_key="nawa_live_sk_xxx")
data, error = client.classify(text="متى الجزء الثاني؟")
print(data.dialect) # "gulf"
print(data.sentiment) # "neutral"
print(data.suggested_reply.text) # "قريب إن شاء الله! 🙏"
NAWA is the only API that detects Gulf, Egyptian, Levantine, and MSA Arabic dialects.
Configuration
client = Nawa(
api_key="nawa_live_sk_xxx", # required
base_url="https://api.trynawa.com", # default
max_retries=2, # default
timeout=30.0, # 30s default
throw_on_error=False, # default — use (data, error) tuple
)
Methods
Classify
data, error = client.classify(
text="متى الجزء الثاني؟",
context={"video_title": "Dubai Vlog"},
provider="claude", # optional
)
Translate
data, error = client.translate(
text="Hello, how are you?",
target="ar",
dialect="gulf",
tone="casual",
)
print(data.translated_text) # "هلا، كيف حالك؟"
Detect
data, error = client.detect(text="وش رايكم بالمحتوى الجديد؟")
print(data.language) # "ar"
print(data.dialect) # "gulf"
print(data.script) # "arabic"
Moderate
data, error = client.moderate(
text="هذا محتوى رائع جدا",
strictness="medium",
)
print(data.is_safe) # True
print(data.verdict) # "safe"
Rubric Classify
data, error = client.rubric.classify(
text="أحتاج مساعدة في طلبي رقم ١٢٣٤",
rubric={
"categories": [
{"name": "support", "description": "Customer support requests"},
{"name": "billing", "description": "Billing questions"},
],
"multi_label": True,
"confidence_threshold": 0.6,
},
)
Reply
data, error = client.comments.reply(
text="هذا المنتج سيء جداً ولا أنصح به",
tone="professional",
max_length=500,
)
Feedback (free)
data, error = client.feedback.create(
classification_id="cls_nw_a1b2c3d4e5f6",
rating="incorrect",
corrected_intent=["question"],
corrected_sentiment="neutral",
)
Webhooks
# Create
data, error = client.webhooks.create(
url="https://example.com/webhook",
events=["classification.completed", "credits.low"],
)
# List
data, error = client.webhooks.list()
# Delete
data, error = client.webhooks.delete("webhook-uuid")
# Verify signature
is_valid = client.webhooks.verify(
payload=raw_body,
headers={
"webhook-id": request.headers["webhook-id"],
"webhook-timestamp": request.headers["webhook-timestamp"],
"webhook-signature": request.headers["webhook-signature"],
},
secret=NAWA_WEBHOOK_SECRET,
tolerance=300,
)
Async Usage
from nawa import AsyncNawa
client = AsyncNawa(api_key="nawa_live_sk_xxx")
data, error = await client.classify(text="ماشاء الله الفيديو حلو مرة")
Error Handling
data, error = client.classify(text="test")
if error:
print(error.message) # Human-readable error
print(error.code) # Machine-readable code
print(error.status) # HTTP status
print(error.suggested_action) # What to do next
else:
print(data.dialect)
Exception Mode
from nawa import Nawa, NawaRateLimitError, NawaAuthError
client = Nawa(api_key="xxx", throw_on_error=True)
try:
data, error = client.classify(text="test")
except NawaRateLimitError as e:
print(f"Retry after {e.retry_after}s")
except NawaAuthError:
print("Check your API key")
Docs
Full API reference: developers.trynawa.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nawa_sdk-1.1.0.tar.gz
(16.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
nawa_sdk-1.1.0-py3-none-any.whl
(18.2 kB
view details)
File details
Details for the file nawa_sdk-1.1.0.tar.gz.
File metadata
- Download URL: nawa_sdk-1.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb5d357ca08e6e2e4b8221389106ffb9b7723a6f8ed5c617cb538bb3706f0125
|
|
| MD5 |
57f59d6305988c752b66d434a273839f
|
|
| BLAKE2b-256 |
bee495fafe8a34948a167239aa09b3835d475f33f497f0cae8b6ed1af3325143
|
File details
Details for the file nawa_sdk-1.1.0-py3-none-any.whl.
File metadata
- Download URL: nawa_sdk-1.1.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef8361ef337cdd5e10d3fbe86b1b3c114a1eeebff711a676029b97cc692ac9e9
|
|
| MD5 |
be2481a0a1f9ed32416e8eb5c23b6871
|
|
| BLAKE2b-256 |
1f49c0724dde3ec2f98c3d0dac62e33ae8f6fb415a4ce7c8afc5e322e6187cf5
|