Skip to main content

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 the 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())

To add a new hint you should use the function add_hint with passed lang parameter and 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!

Metadata

Release files for aio-yandex-translate 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aio-yandex-translate 1.1.1
File Size Uploaded
aio_yandex_translate-1.1.1.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aio-yandex-translate 1.1.1
File Interpreter ABI Platform
aio_yandex_translate-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.3 kB

Release files / aio_yandex_translate-1.1.1.tar.gz

Download URL aio_yandex_translate-1.1.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
dea30119faef609d92c6537e4e8a34e53a6465ba3bd0798a94bf0054b8dc9a4c
BLAKE2b-256 checksum
How to use checksums
77eea24b62dc97ff1fddebd03f076dcaa5e416f2c6c0fa3506a44ed7657a6720
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / aio_yandex_translate-1.1.1-py3-none-any.whl

Download URL aio_yandex_translate-1.1.1-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c493a97d7419ebebdeaa3db2fd354d0fad457df0360a0b06286e48198fa66d5b
BLAKE2b-256 checksum
How to use checksums
859768dda6a7bc0c2bb52dbead010492f3a58877854d5e4d8f77629358274e51
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page