{"id":23808,"library":"gpytranslate","title":"gpytranslate","description":"An async-first Python library for translating text using the Google Translate API. Currently at version 2.1.0, it requires Python >=3.12 and uses aiohttp for async HTTP requests. The library provides both async (Translator) and sync (SyncTranslator) interfaces, along with language detection and text-to-speech (TTS) support. Releases are sporadic, with the last major update in 2025.","status":"active","version":"2.1.0","language":"python","source_language":"en","source_url":"https://github.com/DavideGalilei/gpytranslate","tags":["translation","google-translate","async","text-to-speech"],"install":[{"cmd":"pip install gpytranslate","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Async HTTP client for API calls","package":"aiohttp","optional":false},{"reason":"Async file I/O for TTS audio saving","package":"aiofiles","optional":true}],"imports":[{"note":"Translator is re-exported at the package level.","wrong":"from gpytranslate.translator import Translator","symbol":"Translator","correct":"from gpytranslate import Translator"},{"note":"SyncTranslator is re-exported at the package level.","wrong":"from gpytranslate.sync import SyncTranslator","symbol":"SyncTranslator","correct":"from gpytranslate import SyncTranslator"}],"quickstart":{"code":"import asyncio\nfrom gpytranslate import Translator\n\nasync def main():\n    async with Translator() as t:\n        result = await t.translate(\"Hello world\", sourcelang=\"en\", targetlang=\"es\")\n        print(result.text)  # Output: Hola mundo\n\nasyncio.run(main())","lang":"python","description":"Basic async translation example using Translator as an async context manager."},"warnings":[{"fix":"Upgrade to Python 3.12+ or pin to gpytranslate==1.5.1 if you need older Python.","message":"Version 2.0.0 dropped support for Python <3.12. Install with pip will fail on older interpreters.","severity":"breaking","affected_versions":"<4.0,>=3.12"},{"fix":"Wrap usage in `async with Translator() as t:` or explicitly call `await t.close()` when done.","message":"The Translator class now uses an async context manager (async with) for proper resource cleanup. Using it without a context manager may leak connections in older code.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Catch `gpytranslate.TranslateError` specifically and implement retry logic with exponential backoff.","message":"Google Translate may rate-limit requests. The library raises TranslateError in such cases, not JSON errors. Catching generic Exception may hide the cause.","severity":"gotcha","affected_versions":">=1.4.0"},{"fix":"Use: `t = SyncTranslator(); result = t.translate(...)`","message":"The sync translator (SyncTranslator) is not a context manager; you must create and use it directly. Attempting `async with SyncTranslator()` will raise AttributeError.","severity":"gotcha","affected_versions":">=1.1.0"},{"fix":"Replace `translator.__version__` with `from gpytranslate import __version__`","message":"The `__version__` attribute on Translator instances is deprecated; use `gpytranslate.__version__` instead.","severity":"deprecated","affected_versions":">=1.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Reinstall: `pip install --upgrade gpytranslate`. Verify import in a fresh Python session.","cause":"The library was not correctly installed or imported due to a broken installation.","error":"AttributeError: module 'gpytranslate' has no attribute 'Translator'"},{"fix":"Add delays between requests or use a proxy rotation. Reduce request frequency.","cause":"Google Translate API rate limit exceeded.","error":"gpytranslate.TranslateError: Too many requests"},{"fix":"Use `await` directly in async context or use `asyncio.run()` only from sync entry points.","cause":"Trying to use asyncio.run() inside an async context (e.g., Jupyter notebook or another async function).","error":"RuntimeError: asyncio.run() cannot be called from a running event loop"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}