Skip to main content

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


Download files

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

Source Distribution

Reverso_API-0.0.1a0.tar.gz (7.5 kB view hashes)

Uploaded Source

Built Distribution

Reverso_API-0.0.1a0-py3-none-any.whl (9.2 kB view hashes)

Uploaded Python 3

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