Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

API Wrapper for the Merriam-Webster Collegiate Thesaurus API.

Project description

mwthesaurus

Small wrapper around the Merriam-Webster API. Has both a sync and async interface thanks to httpx.

Installation

pip install mwthesaurus

Usage

Basic usage:

>>> from mwthesaurus import MWClient
>>> client = MWClient(key="YOUR-KEY-HERE")
>>> client.get("python")
[Word(word='python', wordtype='noun', shortdef=['as in anaconda, boa'], synonyms=['adder', 'anaconda', 'asp', 'black racer', 'blacksnake', 'blue racer', 'boa', 'bull snake', 'bushmaster', 'chicken snake', 'cobra', 'constrictor', 'copperhead', 'coral snake', 'cottonmouth moccasin', 'diamondback rattlesnake', 'fer-de-lance', 'garter snake', 'gopher snake', 'green snake', 'hognose snake', 'horned viper', 'indigo snake', 'king cobra', 'king snake', 'krait', 'mamba', 'milk snake', 'moccasin', 'pine snake', 'pit viper', 'puff adder', 'racer', 'rat snake', 'rattlesnake', 'sea serpent', 'sea snake', 'sidewinder', 'taipan', 'water moccasin', 'water snake', 'worm snake', 'serpent', 'snake', 'viper'], antonyms=[], stems=['python'])]
...
>>> import asyncio
>>> asyncio.run(client.aget("python"))
[Word(word='python', wordtype='noun', shortdef=['as in anaconda, boa'], synonyms=['adder', 'anaconda', 'asp', 'black racer', 'blacksnake', 'blue racer', 'boa', 'bull snake', 'bushmaster', 'chicken snake', 'cobra', 'constrictor', 'copperhead', 'coral snake', 'cottonmouth moccasin', 'diamondback rattlesnake', 'fer-de-lance', 'garter snake', 'gopher snake', 'green snake', 'hognose snake', 'horned viper', 'indigo snake', 'king cobra', 'king snake', 'krait', 'mamba', 'milk snake', 'moccasin', 'pine snake', 'pit viper', 'puff adder', 'racer', 'rat snake', 'rattlesnake', 'sea serpent', 'sea snake', 'sidewinder', 'taipan', 'water moccasin', 'water snake', 'worm snake', 'serpent', 'snake', 'viper'], antonyms=[], stems=['python'])]

MWClient.get() returns a list of definitions for a given word.

If you want the definitions as dictionaries, just pass the results to dataclasses.asdict():

>>> from dataclasses import asdict
>>> [asdict(w) for w in client.get("python")]  
[{'word': 'python', 'wordtype': 'noun', 'shortdef': ['as in anaconda, boa'], 'synonyms': ['adder', 'anaconda', 'asp', 'black racer', 'blacksnake', 'blue racer', 'boa', 'bull snake', 'bushmaster', 'chicken snake', 'cobra', 'constrictor', 'copperhead', 'coral snake', 'cottonmouth moccasin', 'diamondback rattlesnake', 'fer-de-lance', 'garter snake', 'gopher snake', 'green snake', 'hognose snake', 'horned viper', 'indigo snake', 'king cobra', 'king snake', 'krait', 'mamba', 'milk snake', 'moccasin', 'pine snake', 'pit viper', 'puff adder', 'racer', 'rat snake', 'rattlesnake', 'sea serpent', 'sea snake', 'sidewinder', 'taipan', 'water moccasin', 'water snake', 'worm snake', 'serpent', 'snake', 'viper'], 'antonyms': [], 'stems': ['python']}]

Project details


Download files

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

Files for mwthesaurus, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size mwthesaurus-0.1.2-py3-none-any.whl (4.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size mwthesaurus-0.1.2.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page