Skip to main content

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

  1. Create the repository on GitHub and push.
  2. On PyPI, configure Trusted Publishing pointing to the publish.yml workflow.
  3. Create a vX.Y.Z release/tag — GitHub Actions publishes automatically.

License

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.3.tar.gz (11.2 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.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

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

Hashes for libretranslate_aio-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fe7dbc482cd322dcb757b2d162a82cc9fadaab3712d487e6cbf8b0690317d3be
MD5 1cc9f726ddba965903a1b22f9e21b733
BLAKE2b-256 cf313fe106e8f545a6b4ff7133931b189ebf29293d2ead24da214c8f581bd8e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for libretranslate_aio-0.1.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for libretranslate_aio-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2e0f7ef332824a48537eb6db6ad75fb807dc42b5ed4bd083cdaf7835cdc8ae76
MD5 8bf36da64f037cc196348d4bbfc773cd
BLAKE2b-256 514518a5ecf6a63a7622067ad45a96cc34f90db2a5ba11d2d1b9294f5817db7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for libretranslate_aio-0.1.3-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