Skip to main content

wrpy

This is a Python package to obtain translations from wordreference.com transforming returned data into normalized and structured datatypes.

Installation

$ pip install wrpy

Usage

You can get the available dictionaries using the following function:

>>> from wrpy import get_available_dicts

>>> get_available_dicts()
{'enes': {'from': 'English', 'to': 'Spanish'},
 'esen': {'from': 'Spanish', 'to': 'English'},
 'esfr': {'from': 'Spanish', 'to': 'French'},
 'espt': {'from': 'Spanish', 'to': 'Portuguese'},
 'esit': {'from': 'Spanish', 'to': 'Italian'},
 'esde': {'from': 'Spanish', 'to': 'German'},
 'esca': {'from': 'Spanish', 'to': 'Catalan'},
 'enfr': {'from': 'English', 'to': 'French'},
 'fren': {'from': 'French', 'to': 'English'},
 'fres': {'from': 'French', 'to': 'Spanish'},
 'enit': {'from': 'English', 'to': 'Italian'},
 'iten': {'from': 'Italian', 'to': 'English'},
 'ites': {'from': 'Italian', 'to': 'Spanish'},
 'ende': {'from': 'English', 'to': 'German'},
 'deen': {'from': 'German', 'to': 'English'},
 'dees': {'from': 'German', 'to': 'Spanish'},
 'ennl': {'from': 'English', 'to': 'Dutch'},
 'nlen': {'from': 'Dutch', 'to': 'English'},
 'ensv': {'from': 'English', 'to': 'Swedish'},
 'sven': {'from': 'Swedish', 'to': 'English'},
 'enru': {'from': 'English', 'to': 'Russian'},
 'ruen': {'from': 'Russian', 'to': 'English'},
 'enpt': {'from': 'English', 'to': 'Portuguese'},
 'pten': {'from': 'Portuguese', 'to': 'English'},
 'ptes': {'from': 'Portuguese', 'to': 'Spanish'},
 'enpl': {'from': 'English', 'to': 'Polish'},
 'plen': {'from': 'Polish', 'to': 'English'},
 'enro': {'from': 'English', 'to': 'Romanian'},
 'roen': {'from': 'Romanian', 'to': 'English'},
 'encz': {'from': 'English', 'to': 'Czech'},
 'czen': {'from': 'Czech', 'to': 'English'},
 'engr': {'from': 'English', 'to': 'Greek'},
 'gren': {'from': 'Greek', 'to': 'English'},
 'entr': {'from': 'English', 'to': 'Turkish'},
 'tren': {'from': 'Turkish', 'to': 'English'},
 'enzh': {'from': 'English', 'to': 'Chinese'},
 'zhen': {'from': 'Chinese', 'to': 'English'},
 'enja': {'from': 'English', 'to': 'Japanese'},
 'jaen': {'from': 'Japanese', 'to': 'English'},
 'enko': {'from': 'English', 'to': 'Korean'},
 'koen': {'from': 'Korean', 'to': 'English'},
 'enar': {'from': 'English', 'to': 'Arabic'},
 'aren': {'from': 'Arabic', 'to': 'English'}}

⚠️  Next dicts are not working properly since their response is not structured in the same way as the others:

  • Spanish to Catalan
  • Russian to English

In order to translate a word, you can follow this workflow:

>>> from wrpy import WordReference

>>> wr = WordReference('es', 'en')  # same as WordReference('esen')

>>> wr.translate('teclado')
{'word': 'teclado',
 'from_lang': 'Spanish',
 'to_lang': 'English',
 'url': 'https://www.wordreference.com/esen/teclado',
 'translations': [{'title': 'Principal Translations',
   'entries': [{'from_word': {'source': 'teclado', 'grammar': 'nm'},
     'to_word': [{'meaning': 'keyboard', 'notes': None, 'grammar': 'n'},
      {'meaning': 'keypad, touchpad', 'notes': None, 'grammar': 'n'}],
     'context': 'tablero con teclas',
     'from_example': 'No me funciona bien el teclado del portátil.',
     'to_example': ["The laptop keyboard isn't working well."]}]},
  {'title': 'Additional Translations',
   'entries': [{'from_word': {'source': 'teclado', 'grammar': 'nm'},
     'to_word': [{'meaning': 'keyboard', 'notes': 'music', 'grammar': 'n'}],
     'context': 'piano electrónico',
     'from_example': 'Aprendí a tocar el teclado de adolescente.',
     'to_example': ['I learned to play the keyboard when I was a teenager.']},
    {'from_word': {'source': 'teclado', 'grammar': 'nm'},
     'to_word': [{'meaning': 'keyboard', 'notes': 'piano', 'grammar': 'n'},
      {'meaning': 'keys', 'notes': None, 'grammar': 'npl'}],
     'context': 'teclas del piano',
     'from_example': 'Este señor viene a afinar el teclado del piano de cola.',
     'to_example': ["This man has come to fine tune the grand piano's keyboard"]}]},
  {'title': 'Compound Forms',
   'entries': [{'from_word': {'source': 'atajo de teclado',
      'grammar': 'nm + loc adj'},
     'to_word': [{'meaning': 'keyboard shortcut',
       'notes': None,
       'grammar': 'n'}],
     'context': 'Informática: grupo de teclas',
     'from_example': '¿Cuál es el atajo de teclado para guardar los cambios en un documento?',
     'to_example': []}]}]}

Response

Response fields from calling translate() method:

response {}
    ├ word
    ├ from_lang
    ├ to_lang
    ├ url  # hitted url
    └ translations []
        ├ title  # title of each section
        └ entries []
            ├ context
            ├ from_word {}
            │    ├ source   # source word
            │    └ grammar  # grammar tips about source word
            ├ to_word []
            │    ├ meaning
            │    ├ notes    # clarification about meaning
            │    └ grammar  # grammar tips about meaning
            ├ from_example
            └ to_example []

Response is composed by sections (inside the translations list) as they appear in wordreference.com

Number of entries is limited to 100 results.

Disclaimer

The workflow of this package is based on scraping of wordreference.com. Thus, future changes on the structure of html response may affect the results.

Metadata

Release files for wrpy 0.1.4

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

Source distribution (sdist)

Source distribution for wrpy 0.1.4
File Size Uploaded
wrpy-0.1.4.tar.gz 28.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wrpy 0.1.4
File Interpreter ABI Platform
wrpy-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 34.8 kB

Release files / wrpy-0.1.4.tar.gz

Download URL wrpy-0.1.4.tar.gz
Size 28.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8ca2934498dca5dc93264bf9a36bdd6ad601ebb7902d35db339d5dd3157bcdf7
BLAKE2b-256 checksum
How to use checksums
69c401bb3c24a3153a481bb46b20c53893df97a48788562d236d3c6a8cb54787
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / wrpy-0.1.4-py3-none-any.whl

Download URL wrpy-0.1.4-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1be1b6776c638f193900c2d81b69c0264bc3f4698c0af8674e460cf6f10cd1fd
BLAKE2b-256 checksum
How to use checksums
64f2a4f468df46076e0e9552532631427ef97e6a4f3b3a982deb2588da79a89a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.4 {"installer":{"name":"uv","version":"0.11.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.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