Skip to main content

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 API
  • LIBRETRANSLATE_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

  1. Crie o repositório no GitHub e faça push.
  2. No PyPI, configure Trusted Publishing apontando para o workflow publish.yml.
  3. Crie uma release/tag vX.Y.Z — o GitHub Actions publica automaticamente.

Licença

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libretranslate_aio-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libretranslate_aio-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

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

Hashes for libretranslate_aio-0.1.0.tar.gz
Algorithm Hash digest
SHA256 318f71e2afec8d7a4e11432abe107d3391fa1f2bdbc30118e584edfbbd492525
MD5 d3716a5b9ad834548c896fcf6c198fb5
BLAKE2b-256 7e18cf4db56f2ea8748c74fb1925ad162e17fa3d7ae187d38a047df810ea1d31

See more details on using hashes here.

Provenance

The following attestation bundles were made for libretranslate_aio-0.1.0.tar.gz:

Publisher: publish.yml on jbsanf/libretranslate-aio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file libretranslate_aio-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for libretranslate_aio-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d24269a27e5f39585f2cf0a1968eb6741a481654bfa68494cba5b31352da353e
MD5 125c4c96ccef1342c99af672ee4bd176
BLAKE2b-256 9bc238fb4b4743a99d9a495c3a926403a984d79d177e52261ff7e6de37ad5c18

See more details on using hashes here.

Provenance

The following attestation bundles were made for libretranslate_aio-0.1.0-py3-none-any.whl:

Publisher: publish.yml on jbsanf/libretranslate-aio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page