• Stars
    star
    192
  • Rank 202,019 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created about 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Proxy to convert HTML responses from linguee.com to JSON format

Linguee API

Linguee provides excellent dictionary and translation memory service. Unfortunately, there is no way you can get automated access to it. Linguee API fixes the problem. It acts as a proxy and converts their HTML responses to easy-to-use JSON API.

API endpoints

The proxy provides three API endpoints: for translations, for examples, and external sources.

Linguee API

The API documentation and the playground is available for the sample installation:

Sample installation

Sample installation is available at https://linguee-api.fly.dev.

Local installation

Install the Linguee API.

$ pip install linguee-api

Run the API server with uvicorn (installed as a dependency.)

$ uvicorn linguee_api.api:app
...
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
...

Open http://127.0.0.1:8000. You will be redirected to the API documentation page, where you can test the API.

Supported languages

API supports all the languages, supported by Linguee. As in Linguee, not all language pairs are valid though. Supported languages: bg (Bulgarian), cs (Czech), da (Danish), de (German), el (Greek), en (English), es (Spanish), et (Estonian), fi (Finnish), fr (French), hu (Hungarian), it (Italian), ja (Japan),lt (Lithuanian), lv (Latvian), mt (Maltese), nl (Dutch), pl (Polish), pt (Portuguese), ro (Romanian), ru (Russian), sk (Slovak), sl (Solvene), sv (Swedish), zh (Chinese).

Response structure

Lemmas

Every query (a random string) can match several so-called lemma objects.

According to Wikipedia, lemma is the canonical form, dictionary form, or citation form of a set of words.

In English, for example, break, breaks, broke, broken, and breaking are forms of the same lexeme, with "break" as the lemma by which they are indexed.

In the API, lemmas have the only required attribute, "text," but may have optional elements, such as part of speech ("pos") and audio links with pronunciations.

Translations

Every lemma has one or more translations. The translation is a lemma in a different language and has a similar structure with the necessary text field and optional part of speech and audio links.

Examples

In addition to lemmas, the API returns several usage examples curated by dictionary authors. Examples are the short phrases, annotated with one or more equivalents in different languages. When appropriate, examples may contain the part-of-speech form and audio links.

External Sources

On top of curated examples, Linguee provides links to external sources. The API returns objects containing the phrase snipped in the original language and an equivalent snippet in the translation.

Usage examples with Python and requests

Once installed on Heroku, Linguee API can be used as any other API service. I recommend using the requests library.

Translate a word or a phrase from one language to another with Python

A request to the sample API installation to translate the word "bacalhau" from Portuguese to English.

import requests

api_root = "https://linguee-api.fly.dev/api/v2"
resp = requests.get(f"{api_root}/translations", params={"query": "bacalhau", "src": "pt", "dst": "en"})
for lemma in resp.json():
    for translation in lemma['translations']:
        print(f"{lemma['text']} -> {translation['text']}")

This will print:

bacalhau -> cod
bacalhau -> codfish

Provide translation examples with Python

A request to the sample API installation to get all usage examples of "bacalhau" along with their translations.

import requests

api_root = "https://linguee-api.fly.dev/api/v2"

resp = requests.get(f"{api_root}/examples", params={"query": "bacalhau", "src": "pt", "dst": "en"})

for example in resp.json():
    for translation in example["translations"]:
        print(f"{example['text']} -> {translation['text']}")

This will print:

bacalhau desfiado -> shredded cod
lombo de bacalhau -> codfish fillet
...
bacalhau do Atlântico -> Atlantic cod

Get access to real world usage examples with Python

A request to the sample API installation to get all real-world usage examples of "bacalhau" along with their translations.

import requests

api_root = "https://linguee-api.fly.dev/api/v2"

resp = requests.get(f"{api_root}/external_sources", params={"query": "bacalhau", "src": "pt", "dst": "en"})
for source in resp.json():
    print(f"{source['src']} -> {source['dst']}")

This will print a long list of real-world examples like this:

É calculado o esforço de [...] pesca de todos os navios que capturam bacalhau. -> The fishing effort of all [...] the vessels catching cod will be calculated.

Bash, curl and jq usage example

Once installed on Heroku, Linguee API can be used as any other API service.

For Bash scripts you can use curl and jq, a command-line JSON parser.

Translate a word or a phrase from one language to another with Bash

A request to the sample API installation to get all usage examples of "bacalhau" along with their translations.

curl -s 'https://linguee-api.fly.dev/api/v2/translations?query=bacalhau&src=pt&dst=en' | jq -c '{text: .[].text, translation: .[].translations[].text}'

This will print

{"text":"bacalhau","translation":"cod"}
{"text":"bacalhau","translation":"codfish"}

Provide translation examples with Bash

A request to the sample API installation to get all usage examples of "bacalhau" along with their translations.

curl -s 'https://linguee-api.fly.dev/api/v2/examples?query=bacalhau&src=pt&dst=en' | jq -c '{text: .[].text, translation: .[].translations[].text}'

This will print something like this:

{"text":"bacalhau desfiado","translation":"shredded cod"}
{"text":"bacalhau desfiado","translation":"codfish fillet"}
...
{"text":"bacalhau do Atlântico","translation":"Atlantic cod"}

Get access to real world usage examples with Bash

A request to the sample API installation to get all real-world usage examples of "bacalhau" along with their translations.

curl -s 'https://linguee-api.fly.dev/api/v2/external_sources?query=bacalhau&src=pt&dst=en' | jq -c '{src: .[].src, dst: .[].dst}'

This will print a long list of real-world examples like this:

{"src":"É calculado o esforço de [...] pesca de todos os navios que capturam bacalhau.","dst":"The fishing effort of all [...] the vessels catching cod will be calculated."}
...

FAQ

The API server returns "The Linguee server returned 503"

This error means that the Linguee website temporarily blocks the API client for sending too many requests. If you use the sample API server on https://linguee-api.fly.dev, you can try to send the request later or consider installing your API server, where you won't share the same IP address with other users.

Terms and Conditions

If you use the API, make sure you comply with Linguee Terms and Conditions, and in particular with that clause:

Both private and business usage of linguee.com services is free of charge. It is however strictly prohibited to forward on our services to third parties against payment

More Repositories

1

asuggest

JQuery textarea suggestion library
JavaScript
61
star
2

vqmetrics

Python functions to convert between different speech quality metrics
Python
54
star
3

refiner

Refiner improves your writing by correcting grammar and style, adjusting tone, and offering formatting options. It is useful for non-native speakers and professionals who communicate with text.
TypeScript
40
star
4

celery-api

Celery API discovery module
Python
30
star
5

network-emulator

Utility to test how network losses affects speech quality in VoIP-based applications
C
24
star
6

django-plausible-proxy

Django application to proxy requests and send server-side events to Plausible Analytics.
Python
22
star
7

speex-quality-evaluation

Source data, scripts and makefiles of the experiment for the Speex codec quality evaluation
Python
22
star
8

alembic-enums

Support for migrating PostgreSQL enums with Alembic
Python
22
star
9

wikipedia-playground

Sample project with Redis and plot.ly Dash
Python
20
star
10

pickle-compat

Python 2/3 compatibility layer for Pickle
Python
15
star
11

wav2rtp

wav2rtp is a simple tool intended to convert speech data from wav files to RTP data stream
C
13
star
12

time-series-caching

Sample dashboard application to demonstrate practical time series caching with Python and Redis. The app shows a plot of all BTC transactions for a specific Bitcoin wallet in a specific date range.
Python
13
star
13

deescovery

Initialize modules of your Python projects on startup. Discover Flask blueprints, FastAPI endpoints, SQLAlchemy models, etc.
Python
10
star
14

gsod

Global Surface Summary of Day (GSOD) loader and parser
Python
8
star
15

django-data-management-example

Python
6
star
16

knockout-dojo-connector

Function to create bindings between Dojo / Dijit widgets and knockout js observables
JavaScript
6
star
17

rpm-packages

Fresh specs for RHEL-based and RHED-derived distributions (CentOS, Amazon Linux AMI)
Python
5
star
18

coverage-plot

A library and a script to display a summary coverage plot from coverage reports.
Python
5
star
19

pt-apartment-scraper

Scraper which periodically scans the list of apartments to rent and creates new tasks to Todoist
JavaScript
5
star
20

twitter-bookmarks-to-csv

HTML
4
star
21

sdcv

The clone of the original sdcv trunk with some improvements
C++
4
star
22

django-project-stub

my own simple stub for Django projects
Python
3
star
23

trytry

A framework for "try-whatever" web services
Python
3
star
24

kafka-playground

My playground for Apache Kafka
Python
2
star
25

django-template

My own django template
Python
2
star
26

google-api

Simple Django app demonstrating various usage scenarios of Google authentication mechanisms
Python
2
star
27

kivy-playground

PyCoffee Kivy playground repo
Python
2
star
28

celery-watcher

Celery watcher application
Python
2
star
29

docker-postgresql

PostgreSQL container with SSH access
Shell
2
star
30

admin-panels-and-dashboards

Anything which can help you to create admin or management panels, back-offices for support and engineering teams.
2
star
31

gevent-websocket

Mirror of the bitbucket repo, made for the sake of building deb packages
Python
2
star
32

docker-wordpress-ssh

Docker image for Wordpress with SSH
Shell
2
star
33

python-openid-google

Extension for Python OpenID library which supports Google extra features
Python
1
star
34

jquery-pageaction

jQuery pageaction library
JavaScript
1
star
35

nfn

A dependency-free console script to generate filenames with sequential suffixes
Python
1
star
36

flask-hello-world

Hello World Flask application, served with uwsgi
Dockerfile
1
star
37

jquery-timelimit

Tiny jquery extension which can limit the frequency of function execution
JavaScript
1
star
38

cookiecutter-python-project

Use this cookiecutter template 🍪 to start a new Python or Django project.
Python
1
star
39

zeromr

ZeroMQ based map/reduce framework
Python
1
star