Synchronous and asynchronous Python client for the Translatarr API.
Project description
translatarr-client
A typed Python client for the Translatarr API — synchronous and asynchronous, with pydantic response models generated from the server's OpenAPI spec.
Install
pip install translatarr-client
Published to PyPI for each v*
tag (the version matches the app's tag). The same wheel + sdist are also
attached to the corresponding GitHub Release, and you can install straight from
this repo:
# from a published GitHub Release (version matches the app's v* tag)
pip install https://github.com/joshrmcdaniel/translatarr/releases/download/v1.2.3/translatarr_client-1.2.3-py3-none-any.whl
# or straight from this repo
pip install -e clients/python
Requires Python 3.10+.
Authentication
Mint a personal API key in the web UI under Settings → API keys (tokens are
prefixed tra_ and shown only once). Pass it as token:
from translatarr import TranslatarrClient
with TranslatarrClient("https://translatarr.example", token="tra_…") as tra:
result = tra.translate("Good morning", source_lang="en", target_lang="ja")
best = result.translations[0]
print(best.text, best.romanization)
A browser session cookie works too, via session_cookie="…" instead of token.
Async
AsyncTranslatarrClient mirrors the sync client method-for-method:
import asyncio
from translatarr import AsyncTranslatarrClient
async def main() -> None:
async with AsyncTranslatarrClient("https://translatarr.example", token="tra_…") as tra:
result = await tra.translate("Bonjour", source_lang="auto", target_lang="en")
print(result.detected_source_language, result.translations[0].text)
asyncio.run(main())
What you can do
| Area | Methods |
|---|---|
| Translate | translate |
| Chats | list_chats, create_chat, get_chat, rename_chat, clear_chat, delete_chat |
| Turns | add_turn, select_option, retranslate_turn, switch_branch |
| Speech | transcribe, synthesize |
| API keys | list_keys, create_key, revoke_key |
Persisting a chat without paying for a second translation
translate does not store anything; add_turn translates and persists. To
avoid a duplicate LLM call, pass the result you already have:
chat = tra.create_chat(source_lang="en", target_lang="ja")
preview = tra.translate("Let's ship it", source_lang="en", target_lang="ja", chat_id=chat.id)
chat = tra.add_turn(chat.id, "Let's ship it", source_lang="en", target_lang="ja", result=preview)
Errors
Failures raise a subclass of translatarr.APIError, each carrying status_code,
the server's code (when present), and the raw response:
| Exception | Status |
|---|---|
InvalidRequestError |
400 |
AuthenticationError |
401 |
ForbiddenError |
403 |
NotFoundError |
404 |
ConflictError |
409 |
MalformedResponseError |
422 |
ProviderError |
502 |
from translatarr import NotFoundError
try:
tra.get_chat("does-not-exist")
except NotFoundError:
...
Development
The response models in src/translatarr/_models.py are generated from the
server's OpenAPI document — do not edit them by hand. To regenerate after the
API schema changes:
# one-time tooling install
python -m venv clients/python/.venv
clients/python/.venv/bin/pip install -e 'clients/python[codegen]'
# regenerate openapi.json + _models.py
clients/python/scripts/regenerate.sh
The script dumps the spec via bun scripts/dump-openapi.ts (the same document
served at /api/docs/openapi.json) and runs datamodel-codegen over it. Only
_models.py is committed, so the client builds and installs without a running
server; openapi.json is a regenerated, gitignored artifact.
Project details
Release history Release notifications | RSS feed
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 translatarr_client-0.2.1.tar.gz.
File metadata
- Download URL: translatarr_client-0.2.1.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94337ec4bb1dc75805784f649e7f9566683e5a5659c9776d2ef8a96bbe1f9499
|
|
| MD5 |
6774c4e7e548e44570451869814e5890
|
|
| BLAKE2b-256 |
86cbf01be17c887154bc88272a1d2fc8d1644817ea53e26d1f47fc6800fea654
|
Provenance
The following attestation bundles were made for translatarr_client-0.2.1.tar.gz:
Publisher:
publish-python.yml on joshrmcdaniel/translatarr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
translatarr_client-0.2.1.tar.gz -
Subject digest:
94337ec4bb1dc75805784f649e7f9566683e5a5659c9776d2ef8a96bbe1f9499 - Sigstore transparency entry: 1997742374
- Sigstore integration time:
-
Permalink:
joshrmcdaniel/translatarr@619b3721253cf7e70eeb0a8f0c130c2544bf4fcb -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/joshrmcdaniel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@619b3721253cf7e70eeb0a8f0c130c2544bf4fcb -
Trigger Event:
push
-
Statement type:
File details
Details for the file translatarr_client-0.2.1-py3-none-any.whl.
File metadata
- Download URL: translatarr_client-0.2.1-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1faa66d647c5d7a6788bff77bfee0df4d0bd5056b080cac7c52bbd46aa16bca2
|
|
| MD5 |
2af5cfa8f1563b46e127afc722dbcb2b
|
|
| BLAKE2b-256 |
08126a659d2ba0e30b0115ed2a8cc30e267e8079bde3df024e814a1f2cd4287c
|
Provenance
The following attestation bundles were made for translatarr_client-0.2.1-py3-none-any.whl:
Publisher:
publish-python.yml on joshrmcdaniel/translatarr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
translatarr_client-0.2.1-py3-none-any.whl -
Subject digest:
1faa66d647c5d7a6788bff77bfee0df4d0bd5056b080cac7c52bbd46aa16bca2 - Sigstore transparency entry: 1997742629
- Sigstore integration time:
-
Permalink:
joshrmcdaniel/translatarr@619b3721253cf7e70eeb0a8f0c130c2544bf4fcb -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/joshrmcdaniel
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@619b3721253cf7e70eeb0a8f0c130c2544bf4fcb -
Trigger Event:
push
-
Statement type: