Googletrans is a Python library that calls Google Translate’s Ajax API for detect and translate operations. It is unofficial and not affiliated with Google.
Overview
Googletrans wraps Google’s translate web endpoints so Python programs can translate text and detect languages without using Google’s paid Cloud Translation API. It targets the same servers as the public translate website and supports automatic source-language detection when none is supplied.
Features include bulk translation of string lists in one session, optional async usage, configurable translate host URLs, proxy support, type hints, and HTTP/2 through httpx. A command-line translate utility is included for quick translations from the shell.
The library generates access tokens by reverse engineering the web client; Google may block this approach at any time, and stability is not guaranteed. Documentation notes a per-text character limit and recommends Google’s official translate API when reliability matters.
Users can point Translator at translate.googleapis.com for a token-free API style endpoint. HTTP 5xx or specific error codes may indicate an IP ban from Google’s side.
Key features
- Translate and detect methods
- Bulk translation in one session
- Async Translator context manager
- Customizable service URL list
- HTTP/2 via httpx
- Proxy and timeout options
- CLI translate command
Use cases
- Quick scripts translating short text
- Batch translation of string lists
- Language detection in pipelines
- Prototyping before official APIs
- Command-line translation checks