Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 1.5 KB

File metadata and controls

61 lines (44 loc) · 1.5 KB

Larousse API

This package is an upgrade of the GitHub project larousse_api.

It scrapes larousse.fr to look up definitions, synonyms, citations and locutions of French words.

Installation

pip install .

Usage

from larousse_api import Larousse, LarousseError

try:
    larousse = Larousse("Fromage")
except LarousseError as error:
    # Raised when the word cannot be found or the request fails
    print(error)
else:
    # Each getter returns a tuple (normalized_texts, raw_li_nodes).
    # Both values are None when the section is missing for the word.
    definitions, _ = larousse.get_definitions()
    locutions, _ = larousse.get_locutions()
    synonymes, _ = larousse.get_synonymes()
    citations, _ = larousse.get_citations()

    print(definitions)
    print(locutions)
    print(synonymes)
    print(citations)

Multi-word entries and accented words are handled automatically (Larousse("pomme de terre"), Larousse("être")), and a custom request timeout can be passed with Larousse("Fromage", timeout=5).

Why?

Because the Larousse website doesn't supply an API to look up definitions :(

How?

Development

pip install -r requirements.txt
python -m pytest -q

Possible improvements

  • Suggest words if the word is misspelled