Skip to main content

NAWA API SDK - Arabic-first AI comment classification

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
)

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


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.0.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nawa_sdk-1.0.0-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file nawa_sdk-1.0.0.tar.gz.

File metadata

  • Download URL: nawa_sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for nawa_sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1b01531c6e68d58f7bc6a61d9f8e9b3269da2ef85701a240b8c90d0acb57c8be
MD5 1731c4079412dff12d05adc2a918e127
BLAKE2b-256 6506414204c4e01d8998e3ce02b1ca65a0faa011f32c50727aa3848d93560299

See more details on using hashes here.

File details

Details for the file nawa_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nawa_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for nawa_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ef155c2779a04837af113971f7d911b1c9ecb5b506c5c1e3626479050605db17
MD5 a77f46f679dd1852b7b13100dd5018ae
BLAKE2b-256 964d7e0f14bed5003898e2118fe8a7bcfebc476999d5308add2e30644a1c2f06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page