Skip to main content

Pawa AI Python SDK

CI PyPI version Python versions License: MIT

Official Python library for the Pawa AI API.

Pawa AI provides African-built small language models for chat, voice, embeddings, document parsing, agents, and knowledge bases.

Installation

pip install pawa-ai

Quickstart

Set your API key:

export PAWA_AI_API_KEY="your_api_key_here"

Get your key from the Builders Dashboard.

See examples/ for a full walkthrough from pip install to API responses.

Chat

from pawa_ai import PawaAI

client = PawaAI()

response = client.chat.create(
    model="pawa-v1-ember-20240924",
    messages=[
        {
            "role": "user",
            "content": [{"type": "text", "text": "Hello! How can I use AI in my app?"}],
        }
    ],
    stream=False,
)

# Always a dict matching the API JSON
print(response["success"])
print(response["data"]["request"][0]["message"]["content"])
print(response["data"].get("usage"))

Streaming

with client.chat.create(
    model="pawa-v1-ember-20240924",
    messages=[
        {"role": "user", "content": [{"type": "text", "text": "Explain RAG in simple terms"}]}
    ],
    stream=True,
) as stream:
    for delta in stream.text_deltas():
        print(delta, end="", flush=True)

    # Or collect the full response after streaming
    completion = stream.collect()
    print(completion["data"]["request"][0]["message"]["content"])

Async streaming:

stream = await client.chat.create(..., stream=True)
text = await stream.collect_text()

Text-to-Speech

audio = client.voice.text_to_speech.create(
    model="pawa-tts-v1-20250704",
    text="Hello, this is Pawa AI speaking!",
    voice="liora",
)

with open("output.mp3", "wb") as f:
    f.write(audio)

Embeddings

response = client.vectors.create(
    model="pawa-embeddings-v1-20241001",
    sentences=["Embed this sentence.", "And this one too."],
    lang="multi",
)

embeddings = response.embeddings

Retries with exponential backoff

from pawa_ai import PawaAI, RetryConfig

client = PawaAI(
    retry_config=RetryConfig(
        max_retries=3,
        initial_delay=0.5,
        max_delay=8.0,
        exponential_base=2.0,
        jitter=0.1,
    )
)

Retries automatically apply to rate limits (429), server errors (500/502/503/504), and connection failures. The SDK respects Retry-After response headers when present.

Async

import asyncio
from pawa_ai import AsyncPawaAI

async def main():
    async with AsyncPawaAI() as client:
        response = await client.chat.create(
            model="pawa-v1-ember-20240924",
            messages=[
                {"role": "user", "content": [{"type": "text", "text": "Habari yako?"}]}
            ],
        )
        print(response["data"]["request"][0]["message"]["content"])

asyncio.run(main())

API coverage

Resource Methods
client.chat create, completions
client.models list, retrieve
client.voice.text_to_speech create
client.voice.speech_to_text create, transcribe
client.vectors create, embeddings
client.documents parse
client.agents create, update, delete, list, retrieve
client.agents.chat create
client.storage.knowledge_base CRUD, list_files, semantic_retrieval
client.transcribe.workspaces CRUD, transcription management

Error handling

from pawa_ai import PawaAI, AuthenticationError, RateLimitError

client = PawaAI()

try:
    response = client.chat.create(model="pawa-v1-ember-20240924", messages=[...])
except AuthenticationError as e:
    print(f"Auth failed: {e.message}")
except RateLimitError as e:
    print(f"Rate limited: {e.status_code}")

Documentation

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pawa_ai-0.2.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

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

pawa_ai-0.2.1-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file pawa_ai-0.2.1.tar.gz.

File metadata

  • Download URL: pawa_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pawa_ai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0aef3a0f2be23435981cf587523debd362cd3c3d18b25e46d0a9f8c48223b05d
MD5 684334a24f6b9e2908eaabb929bd519c
BLAKE2b-256 9b3495ac476b5cc507d7217c6a9d711070131195f4afbca1c9dd9caa0a9b050a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pawa_ai-0.2.1.tar.gz:

Publisher: publish.yml on Sartify/pawa-ai-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pawa_ai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pawa_ai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pawa_ai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29c49cb7ee0f944dc99dac310cdb26523cdd838e87a1f302beeed7532254cca0
MD5 663a540088d28dbff659d3b21f6b175a
BLAKE2b-256 56e6324dba4d41784cab95e663a56184b08c21d17374ce5007c50afa6b46afe7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pawa_ai-0.2.1-py3-none-any.whl:

Publisher: publish.yml on Sartify/pawa-ai-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

Supported by

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