Skip to main content

tarjamli

A small Python client for Tarjamli translation through the Sawalni API. Translate text, convert Darija between Arabic and Latin scripts, and give the translation context about tone, gender or address forms.

Python 3.10+. No runtime dependencies.

Install

pip install tarjamli

Set your Sawalni API key:

export SAWALNI_API_KEY="your-key"

Translate

from tarjamli import Tarjamli

client = Tarjamli()
result = client.translate(
    "واش تقدر تصيفط ليا الدوسي؟",
    source="ary_Arab",
    target="fra_Latn",
    instructions="Address one person formally using vous.",
)
print(result.text)

Pass your own text. Remove instructions for ordinary translation, or change it to supply context. The API field is instructions; tone and gender are not separate parameters.

Convert Darija scripts

result = client.translate(
    "سلام، كيف داير؟",
    source="ary_Arab",
    target="ary_Latn",
)
print(result.text)

Reverse the source and target for Latin → Arabic. Use client.languages() to list supported language and script codes, including shi_Latn for Tachelhit and zgh_Tfng for Tamazight in Tifinagh.

CLI

tarjamli translate --text 'واش تقدر تصيفط ليا الدوسي؟' --source ary_Arab --target fra_Latn --instructions 'Address one person formally using vous.'
tarjamli languages

Use --text - to read standard input. Add --json for the full API response.

Configuration and results

Tarjamli(api_key=None, timeout=180) reads SAWALNI_API_KEY when no key is passed. Keep keys in server-side code or your terminal environment. The package does not load .env files.

translate(text, *, source, target, instructions="", model="tarjamli-mini-v4") returns a Translation with text, source, target, model, and raw (the full response, including usage when supplied). This release supports the checked Mini model only.

Each call sends one request to POST https://api.sawalni.com/v1/language/translate. Live requests use your API balance. There are no automatic retries.

Errors

from tarjamli import AuthenticationError, RateLimitError, TranslationError

try:
    result = client.translate("Hello", source="eng_Latn", target="ary_Arab")
except AuthenticationError:
    # Check your key and model access.
    raise
except RateLimitError:
    # Decide when to retry in your application.
    raise
except TranslationError:
    # Includes incomplete responses, connection errors and unexpected identities.
    raise

Invalid local input raises ValueError. Incomplete output raises IncompleteTranslationError, a subclass of TranslationError. The client checks the returned model and language codes before returning a result.

More examples · API documentation · MIT license.

Metadata

Release files for tarjamli 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tarjamli 0.1.0
File Size Uploaded Provenance Actions
tarjamli-0.1.0.tar.gz 8.1 kB Without provenance Details for tarjamli-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tarjamli 0.1.0
File Interpreter ABI Platform Actions
tarjamli-0.1.0-py3-none-any.whl Python 3 none any Details for tarjamli-0.1.0-py3-none-any.whl

Total release size: 15.8 kB

Release files / tarjamli-0.1.0.tar.gz

Download URL tarjamli-0.1.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6b986ea5850e29af057b638b0ccc06db4ef153fdcc44b62dc08f9a036c3da8e2
BLAKE2b-256 checksum
How to use checksums
85693a1790e930c2e8b3898163c89836ee90a66ed82ffb1915a72a54cf3312f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / tarjamli-0.1.0-py3-none-any.whl

Download URL tarjamli-0.1.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f52d96108c2058e4cd4b7f16e9132be3b03bb5a7f5523a558d9be1b3edebd66c
BLAKE2b-256 checksum
How to use checksums
c56e95bbdb01d3ac66f9ac8268fcd5f5a9f1a52d4786b6380667508f219b30b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Security for tarjamli 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page