aiogtrans-proxy


Nameaiogtrans-proxy JSON
Version 1.1.23 PyPI version JSON
download
home_pagehttps://github.com/ivan-khomich/aiogtrans
SummaryAn async and updated version of the googletrans package.
upload_time2024-11-01 18:57:24
maintainerNone
docs_urlNone
authorivanxo
requires_python>=3.9
licenseMIT
keywords google translate translator async
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiogtrans

aiogtrans is a **free** and **unlimited** python library that implements the Google Translate API asynchronously. This uses the [Google Translate Ajax API](https://translate.google.com>) and [httpx](https://www.python-httpx.org) to make api calls.

Compatible with Python 3.6+.

For details refer to the [API Documentation](https://aiogtrans.readthedocs.io/en/latest>).

## Features

-  Fast and semi-reliable
	- Uses the same api that google translate uses
	- Reverse Engineered
-  Auto language detection
-  Bulk translations
-  Customizable service URL
-  HTTP/2 support

## HTTP/2 support

This library uses httpx for HTTP requests so HTTP/2 is supported by default.

You can check if http2 is enabled and working by the `._response.http_version` of `Translated` or `Detected` object:

```py
>>> (await translator.translate('테스트'))._response.http_version
# 'HTTP/2'
```

### How does this library work?

You may wonder why this library works properly, whereas other approaches such like goslate won't work since Google has updated its translation service recently with a ticket mechanism to prevent a lot of crawler programs.

The original fork author [Suhun Han](https://github.com/ssut) eventually figured out a way to generate a ticket by reverse engineering the obfuscated and minified code used by Google to generate tokens [https://translate.google.com/translate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>](https://translate.google.comtranslate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>), and implemented this in Python. However, this could be blocked at any time.

### Why not use googletrans?

It seems [Suhun Han](https://github.com/ssut) has abandoned the project, at the time of this writing it's been nearly a year and a half since the last commit.

I have decided to move on and update this project.

## Installation

```bash
$ pip install aiogtrans
```

## Basic Usage

If a source language is not given, google translate attempts to detect the source language.

```python
>>> from aiogtrans import Translator
>>> translator = Translator()
>>> await translator.translate('안녕하세요.')
# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>
>>> await translator.translate('안녕하세요.', dest='ja')
# <Translated src=ko dest=ja text=こんにちは。 pronunciation=Kon'nichiwa.>
>>> await translator.translate('veritas lux mea', src='la')
# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>
```

### Customize service URL

You can use another google translate domain for translation. If multiple URLs are provided, the program will randomly choose a domain.

```python
>>> from aiogtrans import Translator
>>> translator = Translator(service_urls=[
        'translate.google.com',
        'translate.google.co.kr',
    ])
```

### Advanced Usage (Bulk Translations)

You can provide a list of strings to be used to translated in a single method and HTTP session. 

```python
>>> translations = await translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')
>>> for translation in translations:
...    print(translation.origin, ' -> ', translation.text)
# The quick brown fox  ->  빠른 갈색 여우
# jumps over  ->  이상 점프
# the lazy dog  ->  게으른 개
```

### Language Detection

The detect method, as its name implies, identifies the language used in a given sentence.

```python
>>> from googletrans import Translator
>>> translator = Translator()
>>> await translator.detect('이 문장은 한글로 쓰여졌습니다.')
# <Detected lang=ko confidence=0.27041003>
>>> await translator.detect('この文章は日本語で書かれました。')
# <Detected lang=ja confidence=0.64889508>
>>> await translator.detect('This sentence is written in English.')
# <Detected lang=en confidence=0.22348526>
>>> await translator.detect('Tiu frazo estas skribita en Esperanto.')
# <Detected lang=eo confidence=0.10538048>
```

## aiogtrans as a command line application

```bash
$ translate -h
usage: translate [-h] [-d DEST] [-s SRC] [-c] text

Python Google Translator as a command-line tool

positional arguments:
    text                  The text you want to translate.

optional arguments:
    -h, --help            show this help message and exit
    -d DEST, --dest DEST  The destination language you want to translate.
                        (Default: en)
    -s SRC, --src SRC     The source language you want to translate. (Default:
                        auto)
    -c, --detect

$ translate "veritas lux mea" -s la -d en
[veritas] veritas lux mea
    ->
[en] The truth is my light
[pron.] The truth is my light

$ translate -c "안녕하세요."
[ko, 1] 안녕하세요.
```

## Note on Library Usage

**DISCLAIMER**: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.

-  **The maximum character limit on a single text is 15,000.**

-  Due to limitations of the web version of google translate, this API does not guarantee that the library would work properly at all times (so please use this library if you don't care about stability).

-  **Important:** If you want to use a stable API, it is highly recommended that you use Google's official translate API [https://cloud.google.com/translate/docs](https://cloud.google.com/translate/docs).

-  If you get HTTP 5xx error or errors like #6, it's probably because Google has banned your client IP address.

## Contributing

Contributions are currently discouraged, I am writing this fork as a personal project and if I ever do decide to open up to contributions I will change this.

Of course you're more then welcome to fork this and make your own changes

## License

**aiogtrans** is licensed under the MIT License. The terms are as follows:

The MIT License (MIT)

Copyright (c) 2022 Ben Zhou 

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ivan-khomich/aiogtrans",
    "name": "aiogtrans-proxy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "google translate translator async",
    "author": "ivanxo",
    "author_email": "ivan.khomich@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/22/7c/a69c5fc8f4ea2a6a732922fbf610a5f8de13631f234018fe05e11c9eb7c5/aiogtrans_proxy-1.1.23.tar.gz",
    "platform": null,
    "description": "# aiogtrans\n\naiogtrans is a **free** and **unlimited** python library that implements the Google Translate API asynchronously. This uses the [Google Translate Ajax API](https://translate.google.com>) and [httpx](https://www.python-httpx.org) to make api calls.\n\nCompatible with Python 3.6+.\n\nFor details refer to the [API Documentation](https://aiogtrans.readthedocs.io/en/latest>).\n\n## Features\n\n-  Fast and semi-reliable\n\t- Uses the same api that google translate uses\n\t- Reverse Engineered\n-  Auto language detection\n-  Bulk translations\n-  Customizable service URL\n-  HTTP/2 support\n\n## HTTP/2 support\n\nThis library uses httpx for HTTP requests so HTTP/2 is supported by default.\n\nYou can check if http2 is enabled and working by the `._response.http_version` of `Translated` or `Detected` object:\n\n```py\n>>> (await translator.translate('\ud14c\uc2a4\ud2b8'))._response.http_version\n# 'HTTP/2'\n```\n\n### How does this library work?\n\nYou may wonder why this library works properly, whereas other approaches such like goslate won't work since Google has updated its translation service recently with a ticket mechanism to prevent a lot of crawler programs.\n\nThe original fork author [Suhun Han](https://github.com/ssut) eventually figured out a way to generate a ticket by reverse engineering the obfuscated and minified code used by Google to generate tokens [https://translate.google.com/translate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>](https://translate.google.comtranslate/releases/twsfe_w_20170306_RC00/r/js/desktop_module_main.js>), and implemented this in Python. However, this could be blocked at any time.\n\n### Why not use googletrans?\n\nIt seems [Suhun Han](https://github.com/ssut) has abandoned the project, at the time of this writing it's been nearly a year and a half since the last commit.\n\nI have decided to move on and update this project.\n\n## Installation\n\n```bash\n$ pip install aiogtrans\n```\n\n## Basic Usage\n\nIf a source language is not given, google translate attempts to detect the source language.\n\n```python\n>>> from aiogtrans import Translator\n>>> translator = Translator()\n>>> await translator.translate('\uc548\ub155\ud558\uc138\uc694.')\n# <Translated src=ko dest=en text=Good evening. pronunciation=Good evening.>\n>>> await translator.translate('\uc548\ub155\ud558\uc138\uc694.', dest='ja')\n# <Translated src=ko dest=ja text=\u3053\u3093\u306b\u3061\u306f\u3002 pronunciation=Kon'nichiwa.>\n>>> await translator.translate('veritas lux mea', src='la')\n# <Translated src=la dest=en text=The truth is my light pronunciation=The truth is my light>\n```\n\n### Customize service URL\n\nYou can use another google translate domain for translation. If multiple URLs are provided, the program will randomly choose a domain.\n\n```python\n>>> from aiogtrans import Translator\n>>> translator = Translator(service_urls=[\n        'translate.google.com',\n        'translate.google.co.kr',\n    ])\n```\n\n### Advanced Usage (Bulk Translations)\n\nYou can provide a list of strings to be used to translated in a single method and HTTP session. \n\n```python\n>>> translations = await translator.translate(['The quick brown fox', 'jumps over', 'the lazy dog'], dest='ko')\n>>> for translation in translations:\n...    print(translation.origin, ' -> ', translation.text)\n# The quick brown fox  ->  \ube60\ub978 \uac08\uc0c9 \uc5ec\uc6b0\n# jumps over  ->  \uc774\uc0c1 \uc810\ud504\n# the lazy dog  ->  \uac8c\uc73c\ub978 \uac1c\n```\n\n### Language Detection\n\nThe detect method, as its name implies, identifies the language used in a given sentence.\n\n```python\n>>> from googletrans import Translator\n>>> translator = Translator()\n>>> await translator.detect('\uc774 \ubb38\uc7a5\uc740 \ud55c\uae00\ub85c \uc4f0\uc5ec\uc84c\uc2b5\ub2c8\ub2e4.')\n# <Detected lang=ko confidence=0.27041003>\n>>> await translator.detect('\u3053\u306e\u6587\u7ae0\u306f\u65e5\u672c\u8a9e\u3067\u66f8\u304b\u308c\u307e\u3057\u305f\u3002')\n# <Detected lang=ja confidence=0.64889508>\n>>> await translator.detect('This sentence is written in English.')\n# <Detected lang=en confidence=0.22348526>\n>>> await translator.detect('Tiu frazo estas skribita en Esperanto.')\n# <Detected lang=eo confidence=0.10538048>\n```\n\n## aiogtrans as a command line application\n\n```bash\n$ translate -h\nusage: translate [-h] [-d DEST] [-s SRC] [-c] text\n\nPython Google Translator as a command-line tool\n\npositional arguments:\n    text                  The text you want to translate.\n\noptional arguments:\n    -h, --help            show this help message and exit\n    -d DEST, --dest DEST  The destination language you want to translate.\n                        (Default: en)\n    -s SRC, --src SRC     The source language you want to translate. (Default:\n                        auto)\n    -c, --detect\n\n$ translate \"veritas lux mea\" -s la -d en\n[veritas] veritas lux mea\n    ->\n[en] The truth is my light\n[pron.] The truth is my light\n\n$ translate -c \"\uc548\ub155\ud558\uc138\uc694.\"\n[ko, 1] \uc548\ub155\ud558\uc138\uc694.\n```\n\n## Note on Library Usage\n\n**DISCLAIMER**: this is an unofficial library using the web API of translate.google.com and also is not associated with Google.\n\n-  **The maximum character limit on a single text is 15,000.**\n\n-  Due to limitations of the web version of google translate, this API does not guarantee that the library would work properly at all times (so please use this library if you don't care about stability).\n\n-  **Important:** If you want to use a stable API, it is highly recommended that you use Google's official translate API [https://cloud.google.com/translate/docs](https://cloud.google.com/translate/docs).\n\n-  If you get HTTP 5xx error or errors like #6, it's probably because Google has banned your client IP address.\n\n## Contributing\n\nContributions are currently discouraged, I am writing this fork as a personal project and if I ever do decide to open up to contributions I will change this.\n\nOf course you're more then welcome to fork this and make your own changes\n\n## License\n\n**aiogtrans** is licensed under the MIT License. The terms are as follows:\n\nThe MIT License (MIT)\n\nCopyright (c) 2022 Ben Zhou \n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An async and updated version of the googletrans package.",
    "version": "1.1.23",
    "project_urls": {
        "Homepage": "https://github.com/ivan-khomich/aiogtrans"
    },
    "split_keywords": [
        "google",
        "translate",
        "translator",
        "async"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "de5209f8f4fea03cc4f593a84ba1e035fdb284977ed8cfbbda56e9a87399bce9",
                "md5": "5cc837b53d19a986393173e5a6bc9e03",
                "sha256": "f5dd8b4bc25e3237369264fd10b0bc553bcff739eee2492f8b70a182e427346e"
            },
            "downloads": -1,
            "filename": "aiogtrans_proxy-1.1.23-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5cc837b53d19a986393173e5a6bc9e03",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 15001,
            "upload_time": "2024-11-01T18:57:23",
            "upload_time_iso_8601": "2024-11-01T18:57:23.186308Z",
            "url": "https://files.pythonhosted.org/packages/de/52/09f8f4fea03cc4f593a84ba1e035fdb284977ed8cfbbda56e9a87399bce9/aiogtrans_proxy-1.1.23-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "227ca69c5fc8f4ea2a6a732922fbf610a5f8de13631f234018fe05e11c9eb7c5",
                "md5": "ed41e6cdcabd4f863ab7111041113a7b",
                "sha256": "bfcd958392b379afb1b3711e34fc49a8f9ceb661d234bdd1e9cb7a4ba5f37e98"
            },
            "downloads": -1,
            "filename": "aiogtrans_proxy-1.1.23.tar.gz",
            "has_sig": false,
            "md5_digest": "ed41e6cdcabd4f863ab7111041113a7b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 15177,
            "upload_time": "2024-11-01T18:57:24",
            "upload_time_iso_8601": "2024-11-01T18:57:24.375056Z",
            "url": "https://files.pythonhosted.org/packages/22/7c/a69c5fc8f4ea2a6a732922fbf610a5f8de13631f234018fe05e11c9eb7c5/aiogtrans_proxy-1.1.23.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-01 18:57:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ivan-khomich",
    "github_project": "aiogtrans",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "aiogtrans-proxy"
}
        
Elapsed time: 0.66329s