gpytranslate


Namegpytranslate JSON
Version 2.0.0 PyPI version JSON
download
home_pageNone
SummaryA Python3 library for translating text using Google Translate API.
upload_time2024-12-03 19:29:13
maintainerDavide Galilei
docs_urlNone
authorDavide Galilei
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # gpytranslate

[![PyPI version](https://badge.fury.io/py/gpytranslate.svg)](https://badge.fury.io/py/gpytranslate)
[![Python Versions](https://img.shields.io/pypi/pyversions/gpytranslate.svg)](https://pypi.org/project/gpytranslate/)
[![License](https://img.shields.io/github/license/DavideGalilei/gpytranslate.svg)](https://github.com/DavideGalilei/gpytranslate/blob/master/LICENSE)

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

Requirements:
- Python 3.9 or higher
- httpx[socks] >= 0.28.0
- aiofiles >= 24.1.0
- typing-extensions >= 4.12.2

Install using pip:
```bash
python3 -m pip install -U gpytranslate
```

Or install with poetry:
```bash
poetry add gpytranslate
```
----
### Usage

[Async Example:](/examples/async/example.py)
```python
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())
```

[Sync Example:](/examples/sync/example.py)
```python
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](/tests) folder for extra examples.

Output:
```
Translation: Hello how are you? I'm fine, haha.
Detected language: en
```

### Text to Speech
[Async Example:](/examples/async/tts.py)
```python
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())
```

[Sync Example:](/examples/sync/tts.py)
```python
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:

```python
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:

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Run the tests (`pytest`)
5. Commit your changes (`git commit -m 'Add amazing feature'`)
6. Push to the branch (`git push origin feature/amazing-feature`)
7. 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](/LICENSE) for further information.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "gpytranslate",
    "maintainer": "Davide Galilei",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "davidegalilei2018@gmail.com",
    "keywords": null,
    "author": "Davide Galilei",
    "author_email": "davidegalilei2018@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2b/23/a482f6e51bfc1812d9f624dff71273d3000b3263626ab1b1ff93dc82a480/gpytranslate-2.0.0.tar.gz",
    "platform": null,
    "description": "# gpytranslate\n\n[![PyPI version](https://badge.fury.io/py/gpytranslate.svg)](https://badge.fury.io/py/gpytranslate)\n[![Python Versions](https://img.shields.io/pypi/pyversions/gpytranslate.svg)](https://pypi.org/project/gpytranslate/)\n[![License](https://img.shields.io/github/license/DavideGalilei/gpytranslate.svg)](https://github.com/DavideGalilei/gpytranslate/blob/master/LICENSE)\n\nA Python3 library for translating text using Google Translate API.\n## Features\n - **Both Synchronous and Asynchronous**\n - **Dot accessible values**\n - **Supports emoji**\n - **Type hinted**\n - **Free to use**\n - **Easy**\n\n----\n## Quick Start\n\n### Installation\n\nRequirements:\n- Python 3.9 or higher\n- httpx[socks] >= 0.28.0\n- aiofiles >= 24.1.0\n- typing-extensions >= 4.12.2\n\nInstall using pip:\n```bash\npython3 -m pip install -U gpytranslate\n```\n\nOr install with poetry:\n```bash\npoetry add gpytranslate\n```\n----\n### Usage\n\n[Async Example:](/examples/async/example.py)\n```python\nfrom gpytranslate import Translator\nimport asyncio\n\n\nasync def main():\n    t = Translator()\n    translation = await t.translate(\"Ciao come stai? Io bene ahah.\", targetlang=\"en\")\n    language = await t.detect(translation.text)\n    print(f\"Translation: {translation.text}\\nDetected language: {language}\")\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n[Sync Example:](/examples/sync/example.py)\n```python\nfrom gpytranslate import SyncTranslator\n\nt = SyncTranslator()\ntranslation = t.translate(\"Ciao come stai? Io bene ahah.\", targetlang=\"en\")\nlanguage = t.detect(translation.text)\nprint(f\"Translation: {translation.text}\\nDetected language: {language}\")\n```\n\u2753 **Note:** you could also check [tests](/tests) folder for extra examples.\n\nOutput:\n```\nTranslation: Hello how are you? I'm fine, haha.\nDetected language: en\n```\n\n### Text to Speech\n[Async Example:](/examples/async/tts.py)\n```python\nimport asyncio, aiofiles\nfrom gpytranslate import Translator\n\nasync def main():\n    translator = Translator()\n    async with aiofiles.open(\"test.mp3\", \"wb\") as file:\n        await translator.tts(\"Hello world!\", file=file)\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n[Sync Example:](/examples/sync/tts.py)\n```python\nfrom gpytranslate import SyncTranslator\n\ntranslator = SyncTranslator()\n\nwith open(\"test.mp3\", \"wb\") as file:\n    translator.tts(\"Hello world!\", file=file)\n```\n\n----\n## Useful Resources\nhttps://danpetrov.xyz/programming/2021/12/30/telegram-google-translate.html\nhttps://vielhuber.de/en/blog/google-translation-api-hacking/\nhttps://github.com/OwlGramDev/OwlGram/blob/b9bb8a247758adbf7be7aaf3eb150f680bec1269/TMessagesProj/src/main/java/it/owlgram/android/translator/GoogleAppTranslator.java\n\n### Language Codes\n\nThe library uses ISO 639-1 two-letter language codes. Some common examples:\n\n- English: 'en'\n- Spanish: 'es' \n- French: 'fr'\n- German: 'de'\n- Italian: 'it'\n- Japanese: 'ja'\n- Chinese (Simplified): 'zh'\n\n### Error Handling\n\nThe library raises `TranslationError` when translation fails:\n\n```python\nfrom gpytranslate import Translator, TranslationError\n\ntranslator = Translator()\ntry:\n    result = await translator.translate(\"Hello\", targetlang=\"invalid\")\nexcept TranslationError as e:\n    print(f\"Translation failed: {e}\")\n```\n\n## Development\n\n### Contributing\n\nContributions are welcome! Here's how you can help:\n\n1. Fork the repository\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Make your changes\n4. Run the tests (`pytest`)\n5. Commit your changes (`git commit -m 'Add amazing feature'`)\n6. Push to the branch (`git push origin feature/amazing-feature`)\n7. Open a Pull Request\n\nPlease make sure to update tests as appropriate and follow the existing code style.\n## License\nLicensed under the MIT License.\n\nClick [here](/LICENSE) for further information.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python3 library for translating text using Google Translate API.",
    "version": "2.0.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "38f26bde3b4962a2360756b0d97df28aa4b5043c55c75f9fe0c912efa26a60de",
                "md5": "57ab917d990e816ad8b395680149f480",
                "sha256": "1b4817f87f2cb0358db5c3d42c187886fb5cb47717ec225685adf3d851bb73be"
            },
            "downloads": -1,
            "filename": "gpytranslate-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "57ab917d990e816ad8b395680149f480",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 11795,
            "upload_time": "2024-12-03T19:29:12",
            "upload_time_iso_8601": "2024-12-03T19:29:12.077650Z",
            "url": "https://files.pythonhosted.org/packages/38/f2/6bde3b4962a2360756b0d97df28aa4b5043c55c75f9fe0c912efa26a60de/gpytranslate-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b23a482f6e51bfc1812d9f624dff71273d3000b3263626ab1b1ff93dc82a480",
                "md5": "c11e5034e021c6265547b33b4c9e5799",
                "sha256": "2865a31567a8c3d9ce85c3ac1feda6c4b9a6462517b9464b1453d06f31c75680"
            },
            "downloads": -1,
            "filename": "gpytranslate-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c11e5034e021c6265547b33b4c9e5799",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9421,
            "upload_time": "2024-12-03T19:29:13",
            "upload_time_iso_8601": "2024-12-03T19:29:13.609595Z",
            "url": "https://files.pythonhosted.org/packages/2b/23/a482f6e51bfc1812d9f624dff71273d3000b3263626ab1b1ff93dc82a480/gpytranslate-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-03 19:29:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "gpytranslate"
}
        
Elapsed time: 0.68012s