Sync and async Python client for the LibreTranslate API (httpx)
Project description
libretranslate-aio
Synchronous and asynchronous Python client for the LibreTranslate API, built on httpx.
Installation
pip install libretranslate-aio
Quick start (sync)
from libretranslate_aio import LibreTranslate
with LibreTranslate() as client:
result = client.translate("Hello world!", source="en", target="pt")
print(result.translated_text) # Olá mundo!
Quick start (async)
import asyncio
from libretranslate_aio import AsyncLibreTranslate
async def main():
async with AsyncLibreTranslate() as client:
result = await client.translate("Hello world!", source="en", target="pt")
print(result.translated_text)
asyncio.run(main())
Configuration
LibreTranslate(
base_url="https://libretranslate.com", # or your self-hosted instance
api_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", # optional
timeout=30.0,
)
Environment variables (used by the CLI):
LIBRETRANSLATE_URL— API base URLLIBRETRANSLATE_API_KEY— API key
API
| Method | Description |
|---|---|
translate(q, source, target, format="text", alternatives=0) |
Translate text (str or list[str]) |
translate_file(file, source, target) |
Translate a file |
detect(q) |
Detect the text language |
languages() |
List supported languages |
suggest(q, s, source, target) |
Submit a translation suggestion |
frontend_settings() |
Frontend settings |
health() |
Health check (True if ok) |
CLI
# Translate
libretranslate translate "Hello world!" --source en --target pt
# Detect language
libretranslate detect "Bonjour le monde"
# List languages
libretranslate languages
# Translate a file
libretranslate translate-file document.txt --source en --target es -o output.txt
# Global options
libretranslate --url https://my-instance.local --api-key KEY translate "Hi" -t pt
Development
uv sync --all-extras
uv run ruff check .
uv run pytest
uv build
Publishing to PyPI
- Create the repository on GitHub and push.
- On PyPI, configure Trusted Publishing pointing to the
publish.ymlworkflow. - Create a
vX.Y.Zrelease/tag — GitHub Actions publishes automatically.
License
MIT
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 libretranslate_aio-0.1.3.tar.gz.
File metadata
- Download URL: libretranslate_aio-0.1.3.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe7dbc482cd322dcb757b2d162a82cc9fadaab3712d487e6cbf8b0690317d3be
|
|
| MD5 |
1cc9f726ddba965903a1b22f9e21b733
|
|
| BLAKE2b-256 |
cf313fe106e8f545a6b4ff7133931b189ebf29293d2ead24da214c8f581bd8e0
|
Provenance
The following attestation bundles were made for libretranslate_aio-0.1.3.tar.gz:
Publisher:
publish.yml on jbsanf/libretranslate-aio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libretranslate_aio-0.1.3.tar.gz -
Subject digest:
fe7dbc482cd322dcb757b2d162a82cc9fadaab3712d487e6cbf8b0690317d3be - Sigstore transparency entry: 2325584814
- Sigstore integration time:
-
Permalink:
jbsanf/libretranslate-aio@3ccca1470556450a5e671f7c4ca6e3e04696457d -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/jbsanf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ccca1470556450a5e671f7c4ca6e3e04696457d -
Trigger Event:
push
-
Statement type:
File details
Details for the file libretranslate_aio-0.1.3-py3-none-any.whl.
File metadata
- Download URL: libretranslate_aio-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.1 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 |
2e0f7ef332824a48537eb6db6ad75fb807dc42b5ed4bd083cdaf7835cdc8ae76
|
|
| MD5 |
8bf36da64f037cc196348d4bbfc773cd
|
|
| BLAKE2b-256 |
514518a5ecf6a63a7622067ad45a96cc34f90db2a5ba11d2d1b9294f5817db7c
|
Provenance
The following attestation bundles were made for libretranslate_aio-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on jbsanf/libretranslate-aio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
libretranslate_aio-0.1.3-py3-none-any.whl -
Subject digest:
2e0f7ef332824a48537eb6db6ad75fb807dc42b5ed4bd083cdaf7835cdc8ae76 - Sigstore transparency entry: 2325584975
- Sigstore integration time:
-
Permalink:
jbsanf/libretranslate-aio@3ccca1470556450a5e671f7c4ca6e3e04696457d -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/jbsanf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ccca1470556450a5e671f7c4ca6e3e04696457d -
Trigger Event:
push
-
Statement type: