Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rtix/pyyandextranslateapi
[DEPRECATED] Python library for Yandex Translate API
https://github.com/rtix/pyyandextranslateapi
python python-2 python-3 python-library requests translate yandex yandex-translate yandex-translate-api
Last synced: 5 days ago
JSON representation
[DEPRECATED] Python library for Yandex Translate API
- Host: GitHub
- URL: https://github.com/rtix/pyyandextranslateapi
- Owner: rtix
- License: mit
- Archived: true
- Created: 2018-09-30T17:07:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-01T10:30:25.000Z (almost 5 years ago)
- Last Synced: 2024-09-29T16:23:00.659Z (4 months ago)
- Topics: python, python-2, python-3, python-library, requests, translate, yandex, yandex-translate, yandex-translate-api
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyYandexTranslateAPI
Python library for Yandex Translate API. Available for both Python 2 and Python 3# Get pyYandexTranslateAPI
```
pip install pyyandextranslateapi
```# Usage
It's very simple to use. There is only one class: Translate## Import
``` python
from Yandex import Translate
```## Initialize
Initialize your Translate with your API key for Yandex.Translate.
You can get it for free on https://translate.yandex.com/developers/keys.
``` python
t = Translate(api_key=API_KEY)
```
Just in case, you can change your key any moment:
``` python
t.set_key(OTHER_API_KEY)
```## Use it
### Get list of supported languages
``` python
t.get_langs()
# {'af': 'Afrikaans', 'am': 'Amharic', 'ar': 'Arabic', ...}
```
There is an optional parameter `ui` here which is for language of definitions of language codes:
``` python
t.get_langs(ui='ru')
# {'af': 'Африкаанс', 'am': 'Амхарский', 'ar': 'Арабский', ...}
```### Detect the language of text
``` python
t.detect(text='Здравствуйте!')
# ru
```
There is an optional parameter `hint` where you can pass list of hints, if you have suggestions about text language:
``` python
t.detect('Здравствуйте!', hint=['ru', 'tt'])
# ru
```
But it's not the list from where API will choose language! API can ingore your hints if he thinks that you are wrong:
``` python
t.detect('Hello!', ['ru', 'tt'])
# en
```### Translate text
``` python
t.translate(text='Hello!', lang_to='ru')
# Здравствуйте!
```
There is an optional parameter `lang_from` where you can pass language of original text:
``` python
t.translate('Hello!', 'ru', lang_from='en')
# Здравствуйте!
```## Exceptions
If something went wrong, you will face exceptions:
- `InvalidAPIKeyError` : Invalid API key
- `BlockedAPIKeyError` : Blocked API key
- `DailyLimitExceededError` : Exceeded the daily limit on the amount of translated text
- `TextSizeExceededError` : Exceeded the maximum text size
- `UntranslatableTextError` : The text cannot be translated
- `DirectionNotSupportedError` : The specified translation direction is not supported
- `YandexTranslateError` : Other kind of error## For more information
### About API
https://tech.yandex.com/translate/doc/dg/concepts/about-docpage/### About this library
[email protected]