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.1

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.1
File Size Uploaded Provenance Actions
tarjamli-0.1.1.tar.gz 8.1 kB Without provenance Details for tarjamli-0.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 15.7 kB

Release files / tarjamli-0.1.1.tar.gz

Download URL tarjamli-0.1.1.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
90eeecab7095fa1ba52ae5c267cee069f05c8445af305ebf0a8e0100c218297f
BLAKE2b-256 checksum
How to use checksums
56d8f8112106a784991fc143b8124c7fc289776cf1e79d722b0db6dee7700ab6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

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

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

Security for tarjamli 0.1.1

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