gpytranslate
A Python3 library for translating text using Google Translate API.
Features
- Both Synchronous and Asynchronous
- Dot accessible values
- Supports emoji
- Type hinted
- Free to use
- Easy
Quick Start
Installation
Install using pip:
python3 -m pip install -U gpytranslate
Or install with poetry:
poetry add gpytranslate
Usage
from gpytranslate import Translator
import asyncio
async def main():
t = Translator()
translation = await t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
language = await t.detect(translation.text)
print(f"Translation: {translation.text}\nDetected language: {language}")
if __name__ == "__main__":
asyncio.run(main())
from gpytranslate import SyncTranslator
t = SyncTranslator()
translation = t.translate("Ciao come stai? Io bene ahah.", targetlang="en")
language = t.detect(translation.text)
print(f"Translation: {translation.text}\nDetected language: {language}")
❓ Note: you could also check tests folder for extra examples.
Output:
Translation: Hello how are you? I'm fine, haha.
Detected language: en
Text to Speech
import asyncio, aiofiles
from gpytranslate import Translator
async def main():
translator = Translator()
async with aiofiles.open("test.mp3", "wb") as file:
await translator.tts("Hello world!", file=file)
if __name__ == "__main__":
asyncio.run(main())
from gpytranslate import SyncTranslator
translator = SyncTranslator()
with open("test.mp3", "wb") as file:
translator.tts("Hello world!", file=file)
Useful Resources
https://danpetrov.xyz/programming/2021/12/30/telegram-google-translate.html https://vielhuber.de/en/blog/google-translation-api-hacking/ https://github.com/OwlGramDev/OwlGram/blob/b9bb8a247758adbf7be7aaf3eb150f680bec1269/TMessagesProj/src/main/java/it/owlgram/android/translator/GoogleAppTranslator.java
Language Codes
The library uses ISO 639-1 two-letter language codes. Some common examples:
- English: 'en'
- Spanish: 'es'
- French: 'fr'
- German: 'de'
- Italian: 'it'
- Japanese: 'ja'
- Chinese (Simplified): 'zh'
Error Handling
The library raises TranslationError when translation fails:
from gpytranslate import Translator, TranslationError
translator = Translator()
try:
result = await translator.translate("Hello", targetlang="invalid")
except TranslationError as e:
print(f"Translation failed: {e}")
Development
Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run the tests (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to update tests as appropriate and follow the existing code style.
License
Licensed under the MIT License.
Click here for further information.
Metadata
Release files for gpytranslate 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gpytranslate-2.1.0.tar.gz | 9.0 kB | Without provenance | Details for gpytranslate-2.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gpytranslate-2.1.0-py3-none-any.whl | Python 3 | none | any | Details for gpytranslate-2.1.0-py3-none-any.whl |
Total release size: 20.8 kB
Release files / gpytranslate-2.1.0.tar.gz
| Download URL | gpytranslate-2.1.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48eb86726f6ce9dedd84203955d1a5d1b8d06ca06026fa7ad321a76856e3b9f4
|
|
BLAKE2b-256 checksum How to use checksums |
9ec930f2e73c92113fd6ffac19bee76c5854f881b1a1e836853c277e0df3bef6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.11 Linux/6.17.7-ba20.fc43.x86_64
|
Release files / gpytranslate-2.1.0-py3-none-any.whl
| Download URL | gpytranslate-2.1.0-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f85a81d22cb8341c417c7dad4ded7dcf5058b7e4a1c88c668ebbf3f3a7fb2e0b
|
|
BLAKE2b-256 checksum How to use checksums |
5d891d49a43811dde29e37638566dfb58120322703095e53976e07a6904c54ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.4 CPython/3.13.11 Linux/6.17.7-ba20.fc43.x86_64
|
Security for gpytranslate 2.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.