Reverso.net API for Python
Project description
Reverso-API
What's this?
This is a wrapper around Reverso's (reverso.net) API for Python.
There is a very good website -- Reverso. It's a very powerful and useful tool for those people, who learn foreign languages. It consists of several sub-apps:
- Context -- translation of words and most of complex phrases. with usage examples.
- Conjugator -- a verb conjugator.
- Dictionary -- a dictionary (both definitions and translation to other languages).
- Spell Checker -- a spell checker.
- and others
It also has a pretty good "Speak" feature for different languages (Reverso Voice; here is an example of spoken text).
Once upon a time I was writing a language-learning app, and wanted to include word translation with examples (as in Reverso Context). But, unfortunately, I could not find a ready wrapper around this web-site's API. So I decided to create it on my own.
Features
Currently the wrapper supports Reverso Context API and Reverso Voice API.
Docs
Docs are not ready yet; they will be published soon. Every method of the code has docstrings,
currently you can take a look at them. Also both reverso_api.context and reverso_api.voice
contain a sample usage example (after if __name__ == "__main__"
); they are different from examples
below ("Getting started" section), and show more advanced features (such as surrounding highlighted
parts of words' usage examples in Context by *).
Getting started
Installation
First, install the package with pip. Just type in the terminal/command-line:
pip install reverso-api
Creating a simple ReversoContextAPI-based program (mini, command-line version of Reverso Context):
Import the Reverso-API module:
from reverso_api.context import ReversoContextAPI
Create an instance of ReversoContextAPI:
api = ReversoContextAPI(
input("Enter the word/phrase to be translated... "),
input("Enter the word/phrase that must be in (target) word usage examples... "),
input("Enter the source language... "),
input("Enter the target language... ")
)
Let's get the translations:
for source_word, translation, frequency, part_of_speech, inflected_forms in api.get_translations():
print(source_word, "==", translation)
print("Frequency (how many word usage examples contain this word):", frequency)
print("Part of speech:", part_of_speech if part_of_speech else "unknown")
if inflected_forms:
print("Inflected forms:", ", ".join(map(lambda form: str(form.translation), inflected_forms)))
print()
And now let's get first ten translation examples:
examples = api.get_translation_examples_pair_by_pair()
for _ in range(10):
source, target = next(examples)
print(source.text, "==", target.text)
Congratulations! You have created your first app that uses ReversoContextAPI!
Creating a simple ReversoVoiceAPI-based program ("Hello, World!" spoken by different people):
Import the Reverso-API module:
from reverso_api.voice import ReversoVoiceAPI
Create an instance of ReversoVoiceAPI:
api = ReversoVoiceAPI()
Let's find all the voices:
voices = api.get_available_voices()
for voice in voices["US English"]:
api.say("Hello, World!", voice, wait=True)
Congratulations! You have created your first app that uses ReversoVoiceAPI!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Reverso_API-0.0.1a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28366bddbfdfe71f196c57f4c31f18f1e73c719e07034eac84f76b4998c69d89 |
|
MD5 | 28a5712d70aa2c3a8e53eadc20287bc5 |
|
BLAKE2b-256 | 540941a6382dbbcafd81123d5a1e94446bbcd7aeb110fa66a35cc2e6605b9299 |