Skip to main content

aiogtrans

aiogtrans is a free and unlimited python library that implements the Google Translate API asynchronously. This uses the Google Translate Ajax API and httpx to make api calls.

Compatible with Python 3.10+.

Features

  • Fast and semi-reliable
    • Uses the same api that google translate uses
    • Reverse Engineered
  • Auto language detection
  • Bulk translations with bounded concurrency
  • Optional in-memory LRU cache
  • Automatic retries on network errors and 429/5xx responses
  • Customizable service URL
  • HTTP/2 support
  • Fully typed (ships py.typed)

HTTP/2 support

HTTP/2 is enabled by default. You can check the protocol used through the .response.http_version of a Translated or Detected object:

>>> (await translator.translate('테스트')).response.http_version
# 'HTTP/2'

How does this library work?

The translate.google.com web app talks to Google through an internal RPC endpoint (/_/TranslateWebserverUi/data/batchexecute). This library sends the same requests the web app does and parses the response. Since this is an undocumented API, Google could change or block it at any time.

Why not use googletrans?

It seems Suhun Han has abandoned the project, at the time of this writing it's been nearly a year and a half since the last commit.

I have decided to move on and update this project.

Installation

$ pip install aiogtrans

Basic Usage

If a source language is not given, google translate attempts to detect the source language. Use the translator as an async context manager so the underlying HTTP client is closed.

>>> from aiogtrans import Translator
>>> async with Translator() as translator:
...     await translator.translate('안녕하세요.')
...     await translator.translate('안녕하세요.', dest='ja')
...     await translator.translate('veritas lux mea', src='la')
# Translated(src='ko', dest='en', origin='안녕하세요.', text='hello.', pronunciation=None)
# Translated(src='ko', dest='ja', origin='안녕하세요.', text='こんにちは。', pronunciation=None)
# Translated(src='la', dest='en', origin='veritas lux mea', text='truth is my light', pronunciation=None)

Language names work as well as codes, e.g. dest='japanese'.

Customize service URL

You can use another google translate domain for translation. If multiple URLs are provided, the program will randomly choose a domain.

>>> from aiogtrans import Translator
>>> translator = Translator(service_urls=[
        'translate.google.com',
        'translate.google.co.kr',
    ])

Bulk Translations

translate_bulk translates a list of strings concurrently over a single HTTP client. At most concurrency requests (default 10) are in flight at once.

>>> translations = await translator.translate_bulk(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')
>>> for translation in translations:
...    print(translation.origin, ' -> ', translation.text)
# The quick brown fox  ->  민첩한 갈색여우
# jumps over  ->  뛰어넘다
# the lazy dog  ->  게으른 개

Language Detection

The detect method, as its name implies, identifies the language used in a given sentence. Google no longer returns a confidence score, so confidence is None.

>>> from aiogtrans import Translator
>>> async with Translator() as translator:
...     await translator.detect('이 문장은 한글로 쓰여졌습니다.')
...     await translator.detect('この文章は日本語で書かれました。')
# Detected(lang='ko', confidence=None)
# Detected(lang='ja', confidence=None)

Caching, retries and errors

>>> translator = Translator(
...     cache_capacity=1000,   # cache up to 1000 results in memory (0 disables, the default)
...     retries=3,             # attempts on network errors and 429/5xx responses
...     raise_exception=True,  # raise HTTPError on a non-200 response
... )

Failed requests raise aiogtrans.TranslationError (HTTPError is a subclass). Invalid language codes and text over 15,000 characters raise ValueError.

aiogtrans as a command line application

$ aiogtrans -h
usage: aiogtrans [-h] [-d DEST] [-s SRC] [-c] text

Python Google Translator as a command-line tool

positional arguments:
  text                  The text you want to translate.

options:
  -h, --help            show this help message and exit
  -d DEST, --dest DEST  The destination language you want to translate.
                        (Default: en)
  -s SRC, --src SRC     The source language you want to translate. (Default:
                        auto)
  -c, --detect          Detect the language of the given text instead of
                        translating.

$ aiogtrans "veritas lux mea" -s la -d en
[la] veritas lux mea
    ->
[en] truth is my light
[pron.] None

$ aiogtrans -c "안녕하세요."
[ko, None] 안녕하세요.

python -m aiogtrans works as well.

Note on Library Usage

DISCLAIMER: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.

  • The maximum character limit on a single text is 15,000.

  • Due to limitations of the web version of google translate, this API does not guarantee that the library would work properly at all times (so please use this library if you don't care about stability).

  • Important: If you want to use a stable API, it is highly recommended that you use Google's official translate API https://cloud.google.com/translate/docs.

  • If you get HTTP 5xx error or errors like #6, it's probably because Google has banned your client IP address.

Contributing

Contributions are currently discouraged, I am writing this fork as a personal project and if I ever do decide to open up to contributions I will change this.

Of course you're more then welcome to fork this and make your own changes

Development

$ uv sync              # create .venv with dev dependencies
$ uv run pytest        # tests
$ uv run ruff check .  # lint
$ uv run ruff format . # format
$ uv run mypy          # type check

License

aiogtrans is licensed under the MIT License. The terms are as follows:

The MIT License (MIT)

Copyright (c) 2022 Ben Zhou

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Release files for aiogtrans 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiogtrans 1.3.0
File Size Uploaded Provenance
aiogtrans-1.3.0.tar.gz 19.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiogtrans 1.3.0
File Interpreter ABI Platform
aiogtrans-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.1 kB

Release files / aiogtrans-1.3.0.tar.gz

Download URL aiogtrans-1.3.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6b6c33e7c83ef42ecfb240d413ed202461a83876dd8c41e228164187d0057f45
BLAKE2b-256 checksum
How to use checksums
4dbc9181b1409b7abfa772f66ad213e81e2faf83f160239d9b37155370a82030
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Release files / aiogtrans-1.3.0-py3-none-any.whl

Download URL aiogtrans-1.3.0-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f0b40ae50faf21505abcb5d3b65513f50eea42c45355595da07316d6c13be86
BLAKE2b-256 checksum
How to use checksums
be344d9c6a6d1a470d7c4119fb6047c175141cf32f50d85d9087663fad0ecff4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

Security for aiogtrans 1.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aiogtrans-1.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page