Khaya SDK
Python SDK for the Khaya AI Khaya API — providing translation, automatic speech recognition (ASR), and text-to-speech (TTS) for African languages.
Installation
pip install khaya
Authentication
Get an API key at https://translation.ghananlp.org and set it as an environment variable:
export KHAYA_API_KEY=your_api_key_here
Quick Start
import os
from khaya import KhayaClient
with KhayaClient(os.environ["KHAYA_API_KEY"]) as khaya:
# Translate text from English to Twi
result = khaya.translate("Hello, how are you?", "en-tw")
print(result.text)
# Transcribe a Twi audio file
result = khaya.transcribe("path/to/audio.wav", "tw")
print(result.text)
# Synthesize speech in Twi
result = khaya.synthesize("Me ho yɛ", "twi")
result.save("output.wav")
Each method returns a typed result object rather than a raw HTTP response:
TranslationResult and TranscriptionResult expose .text, and
SynthesisResult exposes .audio bytes plus a .save(path) helper.
Async Usage
import asyncio
import os
from khaya import KhayaClient
async def main():
async with KhayaClient(os.environ["KHAYA_API_KEY"]) as khaya:
result = await khaya.atranslate("Hello", "en-tw")
print(result.text)
result = await khaya.atranscribe("path/to/audio.wav", "tw")
print(result.text)
result = await khaya.asynthesize("Me ho yɛ", "twi")
result.save("output.wav")
asyncio.run(main())
Error Handling
All errors raise exceptions — never return error dicts. Catch the appropriate exception:
from khaya import KhayaClient
from khaya.exceptions import (
AuthenticationError,
RateLimitError,
TranslationError,
APIError,
)
khaya = KhayaClient(api_key="your-key")
try:
result = khaya.translate("Hello", "en-tw")
print(result.text)
except AuthenticationError:
print("Invalid API key. Check your KHAYA_API_KEY.")
except RateLimitError as e:
print(f"Rate limit hit: {e.message}")
except TranslationError as e:
print(f"Translation failed ({e.status_code}): {e.message}")
except APIError as e:
print(f"API error ({e.status_code}): {e.message}")
Supported Languages
Translation pairs
| Code | Language |
|---|---|
en |
English |
tw |
Twi |
ee |
Ewe |
gaa |
Ga |
fat |
Fante |
yo |
Yoruba |
dag |
Dagbani |
ki |
Kikuyu |
gur |
Gurene |
luo |
Luo |
mer |
Kimeru |
kus |
Kusaal |
Language pair format: "<source>-<target>", e.g. "en-tw" or "tw-en". All pairs are bidirectional with English as the pivot language.
ASR languages
| Code | Language |
|---|---|
eng |
African English |
fra |
African French |
atw |
Akuapem Twi |
bwu |
Buli |
dga |
Dagaare |
dag |
Dagbani |
ada |
Dangme |
ewe |
Ewe |
fat |
Fante |
gaa |
Ga |
gjn |
Gonja |
gur |
Gurene |
hau |
Hausa |
ibo |
Igbo |
xsm |
Kasem |
kik |
Kikuyu |
kin |
Kinyarwanda |
xon_likoonli |
Konkomba-Likoonli |
xon_likpakpaanl |
Konkomba-Likpakpaanl |
kri |
Krio |
kus |
Kusaal |
luo |
Luo |
maw |
Mampruli |
men |
Mende |
mer |
Meru |
pcm |
Naija Pidgin |
nzi |
Nzema |
sna |
Shona |
swa |
Swahili |
tem |
Temne |
twi |
Twi |
wlx |
Wali |
wol |
Wolof |
yor |
Yoruba |
TTS languages
| Code | Language |
|---|---|
atw |
Akuapem Twi |
twi |
Asante Twi |
dga |
Dagaare |
dag |
Dagbani |
ada |
Dangme |
eng |
English |
ewe |
Ewe |
fat |
Fante |
fra |
French |
gaa |
Ga |
gjn |
Gonja |
gur |
Gurene |
hau |
Hausa |
ibo |
Igbo |
xsm |
Kasem |
kik |
Kikuyu |
lxn |
Konkomba (Likoonli) |
xon |
Konkomba (Likpakpaanl) |
kri |
Krio |
kus |
Kusaal |
luo |
Luo |
maw |
Mampruli |
men |
Mende |
mer |
Meru/Kimeru |
nzi |
Nzema |
pcm |
Pidgin |
sna |
Shona |
swa |
Swahili |
tem |
Temne |
wlx |
Wali |
wol |
Wolof |
yor |
Yoruba |
Configuration
from khaya import KhayaClient
from khaya.config import Settings
config = Settings(
api_key="your-key",
timeout=60, # seconds (default: 30)
retry_attempts=5, # retries on transient failures (default: 3)
)
khaya = KhayaClient(api_key="your-key", config=config)
Development
# Install all dependency groups
uv sync --extra test --extra dev
# Run unit tests (no API key required)
uv run pytest -m "not integration"
# Run with coverage
uv run pytest -m "not integration" --cov=src/khaya --cov-report=term-missing
# Lint and type-check
uv run ruff check src/khaya
uv run mypy src/khaya
# Install pre-commit hooks
uv run pre-commit install
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file khaya-0.2.0.tar.gz.
File metadata
- Download URL: khaya-0.2.0.tar.gz
- Upload date:
- Size: 146.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8a2333aa3d0d874773927d64ae492ee50a3603f47f796af09eb1f95fcab60f4
|
|
| MD5 |
b7d27551469d8c97af303e1b330d5749
|
|
| BLAKE2b-256 |
1871ba44df67957427253286b9ad2ffac5f9269846fac7c1241dfdbdd20924df
|
Provenance
The following attestation bundles were made for khaya-0.2.0.tar.gz:
Publisher:
release.yml on Khaya-AI/khaya-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
khaya-0.2.0.tar.gz -
Subject digest:
f8a2333aa3d0d874773927d64ae492ee50a3603f47f796af09eb1f95fcab60f4 - Sigstore transparency entry: 2370427668
- Sigstore integration time:
-
Permalink:
Khaya-AI/khaya-sdk@7ff0d188d0f276308c9a5ceaf90d772fbf6b5f18 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Khaya-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7ff0d188d0f276308c9a5ceaf90d772fbf6b5f18 -
Trigger Event:
push
-
Statement type:
File details
Details for the file khaya-0.2.0-py3-none-any.whl.
File metadata
- Download URL: khaya-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d96f79052ea2317df045f3c514c383159a8a369da94af923b5d4749dd9aba773
|
|
| MD5 |
dfceb962d50f5217b88ccbe6b9b01b8b
|
|
| BLAKE2b-256 |
1db6a1d229111623660b77737b124e7036cd1f51dc806fa8203d13b8ba4813f4
|
Provenance
The following attestation bundles were made for khaya-0.2.0-py3-none-any.whl:
Publisher:
release.yml on Khaya-AI/khaya-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
khaya-0.2.0-py3-none-any.whl -
Subject digest:
d96f79052ea2317df045f3c514c383159a8a369da94af923b5d4749dd9aba773 - Sigstore transparency entry: 2370427759
- Sigstore integration time:
-
Permalink:
Khaya-AI/khaya-sdk@7ff0d188d0f276308c9a5ceaf90d772fbf6b5f18 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Khaya-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7ff0d188d0f276308c9a5ceaf90d772fbf6b5f18 -
Trigger Event:
push
-
Statement type: