Cliente Python sync e async para a API do LibreTranslate (httpx)
Project description
libretranslate-aio
Cliente Python síncrono e assíncrono para a API do LibreTranslate, baseado em httpx.
Instalação
pip install libretranslate-aio
Uso rápido (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!
Uso rápido (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())
Configuração
LibreTranslate(
base_url="https://libretranslate.com", # ou sua instância self-hosted
api_key="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", # opcional
timeout=30.0,
)
Variáveis de ambiente (usadas pela CLI):
LIBRETRANSLATE_URL— URL base da APILIBRETRANSLATE_API_KEY— chave de API
API
| Método | Descrição |
|---|---|
translate(q, source, target, format="text", alternatives=0) |
Traduz texto (str ou list[str]) |
translate_file(file, source, target) |
Traduz um arquivo |
detect(q) |
Detecta o idioma do texto |
languages() |
Lista idiomas suportados |
suggest(q, s, source, target) |
Envia sugestão de tradução |
frontend_settings() |
Configurações do frontend |
health() |
Health check (True se ok) |
CLI
# Traduzir
libretranslate translate "Hello world!" --source en --target pt
# Detectar idioma
libretranslate detect "Bonjour le monde"
# Listar idiomas
libretranslate languages
# Traduzir arquivo
libretranslate translate-file documento.txt --source en --target es -o saida.txt
# Opções globais
libretranslate --url https://minha-instancia.local --api-key KEY translate "Hi" -t pt
Desenvolvimento
uv sync --all-extras
uv run ruff check .
uv run pytest
uv build
Publicação no PyPI
- Crie o repositório no GitHub e faça push.
- No PyPI, configure Trusted Publishing apontando para o workflow
publish.yml. - Crie uma release/tag
vX.Y.Z— o GitHub Actions publica automaticamente.
Licença
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.0.tar.gz.
File metadata
- Download URL: libretranslate_aio-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
318f71e2afec8d7a4e11432abe107d3391fa1f2bdbc30118e584edfbbd492525
|
|
| MD5 |
d3716a5b9ad834548c896fcf6c198fb5
|
|
| BLAKE2b-256 |
7e18cf4db56f2ea8748c74fb1925ad162e17fa3d7ae187d38a047df810ea1d31
|
Provenance
The following attestation bundles were made for libretranslate_aio-0.1.0.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.0.tar.gz -
Subject digest:
318f71e2afec8d7a4e11432abe107d3391fa1f2bdbc30118e584edfbbd492525 - Sigstore transparency entry: 2325208754
- Sigstore integration time:
-
Permalink:
jbsanf/libretranslate-aio@b3d1d78710a92e15786f05ad4f3aef94eea0045e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jbsanf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b3d1d78710a92e15786f05ad4f3aef94eea0045e -
Trigger Event:
push
-
Statement type:
File details
Details for the file libretranslate_aio-0.1.0-py3-none-any.whl.
File metadata
- Download URL: libretranslate_aio-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 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 |
d24269a27e5f39585f2cf0a1968eb6741a481654bfa68494cba5b31352da353e
|
|
| MD5 |
125c4c96ccef1342c99af672ee4bd176
|
|
| BLAKE2b-256 |
9bc238fb4b4743a99d9a495c3a926403a984d79d177e52261ff7e6de37ad5c18
|
Provenance
The following attestation bundles were made for libretranslate_aio-0.1.0-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.0-py3-none-any.whl -
Subject digest:
d24269a27e5f39585f2cf0a1968eb6741a481654bfa68494cba5b31352da353e - Sigstore transparency entry: 2325208944
- Sigstore integration time:
-
Permalink:
jbsanf/libretranslate-aio@b3d1d78710a92e15786f05ad4f3aef94eea0045e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/jbsanf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b3d1d78710a92e15786f05ad4f3aef94eea0045e -
Trigger Event:
push
-
Statement type: