A Python package for interacting with Google Translate services. Supports text (with transliteration), image, document, website, and voice translation.
Three modes available:
- Browser (headless) — default, full features, no visible window
- Browser (headed) — full features with visible Chrome window (enables transliteration)
- Direct HTTP — text-only, no browser required, fastest
- Text Translation: Translate text with auto-detect, transliteration, and suggestions
- Image Translation: Extract and translate text from images
- Document Translation: Translate images and documents
- Website Translation: Translate entire web pages via Google proxy
- Text to Speech: Convert text into audio (direct HTTP, no browser)
pip install -r requirements.txtRequires Chrome/Chromium installed for browser mode. Direct mode needs only requests.
from google_translate import translate_text
# Browser mode (headless) — full features
result = translate_text("Hello", "en", "es")
print(result['translated']) # "Hola"
# Browser mode (headed) — shows window, enables transliteration
result = translate_text("Привет", "ru", "en", headless=False)
print(result['translated']) # "Hello"
print(result['target_transliteration']) # "Privet"
# Direct HTTP mode — no browser needed
result = translate_text("Hello", "auto", "am", mode="direct")
print(result['translated']) # Amharic translation
print(result['source_lang']) # "en" (auto-detected)from google_translate import translate_image
result = translate_image("image.png", "auto", "es")
if result.get('success'):
with open("translated.png", "wb") as f:
f.write(result['image_data'])from google_translate import translate_document
# Images are routed through the image tab
result = translate_document("photo.png", "auto", "es")
# PDF/DOCX files use the docs tab + CDP download
result = translate_document("document.pdf", "auto", "es")from google_translate import translate_website
result = translate_website("https://example.com", "auto", "es")
print(result['title']) # Translated page title
print(result['html'][:500]) # Translated HTMLfrom google_translate import translate_voice
result = translate_voice("hello", "en", "es")
with open("output.mp3", "wb") as f:
f.write(result['audio_data'])Parameters:
text(str): Text to translatesource_lang(str): Source language code or "auto"target_lang(str): Target language codemode(str):"browser"(default) or"direct"(no browser)headless(bool): Run Chrome hidden (defaultTrue). Only applies in browser mode.
Returns: dict with original, translated, source_lang, target_lang, source_transliteration, target_transliteration, suggestions
Parameters:
image_path(str): Path to image filesource_lang,target_lang,mode,headless: Same as above
Returns: dict with image_data (bytes), success, translated_size, original_size
Parameters:
file_path(str): Path to document or image file
Returns: dict with translation result
Parameters:
url(str): URL of the website to translate
Returns: dict with title, url, html, success
Direct HTTP, no browser needed.
Returns: dict with audio_data (bytes)
- Python 3.6+
- requests
- DrissionPage>=4.0.0 (for browser mode)
- Chrome/Chromium installed (for browser mode)
- Browser mode uses DrissionPage (CDP protocol), not Selenium
- Direct mode uses Google Translate's internal
batchexecuteRPC endpoint - Rate limiting may apply
- For production, consider the official Google Cloud Translation API
- Zombie Chrome processes can accumulate — run
taskkill /f /im chrome.exeto clean up