Skip to main content

Yandex translate async api wrapper

Project description

aio_yandex_translate

Async yandex.translate api wrapper for python

Example of usage

import asyncio
from aio_yandex_translate.translator import Translator
key = "TOKEN"

async def main():
    text = 'Hello world'
    print(text)
    t = Translator(key)
    r = await t.translate(text, to_language='ru')
    print(r)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

If you need to use proxies

import asyncio
from aio_yandex_translate.translator import Translator
key = "TOKEN"

async def main():
    text = 'Hello world'
    t = Translator(key, proxy="http://user:password@127.0.0.1:1080")
    r = await t.translate(text, to_language='ru')
    print(r)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

See aiohttp-proxy, it should also support socks proxies

Changing proxies on a go

import asyncio
from aio_yandex_translate.translator import Translator
key = "TOKEN"

async def main():
    text = 'Hello world'
    t = Translator(key, proxy="http://user:password@127.0.0.1:1080")
    r = await t.translate(text, to_language='ru')

    t.proxy = "http://user:password@localhost:1080"
    r = await t.translate(text, to_language='ru')
    print(r)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Detecting language

async def main():
    text = 'Hello world'
    t = Translator(key, proxy="http://user:password@127.0.0.1:1080")
    r = await t.detect_lang(text)
    print(r)


loop = asyncio.get_event_loop()
loop.run_until_complete(main())

You also may use keyword argument hint to give a list of languages, that should be preffered when detecting langs
To add new hint you should use function add_hint with passed lang parameter in return you'll get bool value representing if it was added
To remove lang from hints:

from aio_yandex_translate.translator import Translator
key = "TOKEN"
translator = Translator(key)
translator.add_hint("en")
translator.hints.remove("en")

Explaining some details

To get to exceptions that module can throw you may go to Translator.exc and see classes of exceptions (TranslatorError is base)
The code is really short but i hope it will help you!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aio_yandex_translate-1.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

aio_yandex_translate-1.1.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file aio_yandex_translate-1.1.0.tar.gz.

File metadata

  • Download URL: aio_yandex_translate-1.1.0.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for aio_yandex_translate-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0fc1f8d5c9ea4a2d1882a43a95be00425f183a07197b3cbcec9f12b0f49d36c2
MD5 930b0fd67ffef5474a86915ab8b13ced
BLAKE2b-256 fefd6458da71b00c8271d608cd569f70ab20282761cd20c81802b3ed92bb48ea

See more details on using hashes here.

File details

Details for the file aio_yandex_translate-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: aio_yandex_translate-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for aio_yandex_translate-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b6db0b815ad9820a68ef634cc3d3bb09db417c6fe4eb8bacd1b6e6143fecca4
MD5 923e3fd370577f1da14a289c06679679
BLAKE2b-256 1ea254c42fb8b3a200e44f91c6c78b5b23e2f7457754ffb25a9f52541d523e51

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page