Introducing Britannica Dictionary: Your Python-Powered Dictionary and Word of the Day Fetcher

Esubalew ChekolEsubalew Chekol
3 min read

As developers, we often find ourselves in need of quick access to definitions or dictionary entries for a wide range of tasks—be it for natural language processing, chat bots, or simply expanding vocabulary in an application. That's why I'm thrilled to introduce the britannica-dictionary package—a Python tool designed to make dictionary look ups effortless, fetching definitions, parts of speech, and even the "Word of the Day" directly from Britannica Dictionary.

In this blog, I'll walk you through how to install the package, use its main features, and some fun examples showcasing its flexibility.

1. Installation

Before diving into the functionality, let's get the package installed. It's simple—just run the following command in your terminal:

pip install britannica-dictionary

2. Fetching the Word of the Day

Who doesn't love a good "Word of the Day"? With britannica-dictionary, grabbing it is as easy as calling a single function:

from dictionary import britannica

# Fetch the Word of the Day
word_of_the_day = britannica.get_word_of_the_day()
print(word_of_the_day)

This function returns the word, part of speech, a beautiful image (if available), and the meaning.

You can fetch the Word of the Day from Britannica Dictionary with a simple call:

from dictionary import britannica

wod = britannica.get_word_of_the_day()
print(wod['word'])

Output:(this is might be different )

'serene (adjective)'

You can also get the associated image and its description:

print(wod['image']['src'])
print(wod['image']['alt'])

3. Digging Into Meanings and Examples

The package allows you to dive deeper into the definitions and examples provided for the Word of the Day. For example, here’s how to extract a specific definition and example:

definition = wod['meanings'][1]['definition']
example = wod['meanings'][1]['examples'][0].strip()
print(definition)
print(example)

Output: (note that this output will hopefully different when you run unless you tried on the same day i publish this article)

'— serenely adverb'
'She smiled serenely.'

4. Fetching Definitions and Examples for Any Word

You can use britannica.get_definitions() to retrieve meanings and examples for any word. Here’s how to retrieve definitions for the word "head":

from dictionary.britannica import get_definitions

definitions = get_definitions('head')
print(definitions[0]['meaning'])
print(definitions[0]['examples'][0].strip())

5. Extracting Parts of Speech

The britannica.get_parts() function allows you to extract the parts of speech for a word:

from dictionary import britannica

parts = britannica.get_parts('head')
print(parts)

Output:

['1head (noun)', '2head (verb)']

or who knows, you may need to get the first part

print(parts[0]) # `1head (noun)'

or you know how slicing do the magic

print(parts[0][1:]) # `head (noun)`

6. Traversing Deeply Nested Data

For more complex data traversal, such as extracting specific examples or definitions, you can drill down with code like this:

example = britannica.get_word_of_the_day()['meanings'][1]['examples'][0].strip()
print(example)

Output:

'She smiled serenely.'

This demonstrates how you can easily fetch and manipulate data using this package, making it an excellent choice for chatbots, educational applications, or any language-related tool.

Conclusion

With the britannica-dictionary package, you have access to a wealth of language information directly from Britannica. It's flexible enough for basic look-ups, yet powerful enough for deep data traversal. Start integrating it into your Python projects today!

If you wanted to contribute to this project please visit package on PyPi

0
Subscribe to my newsletter

Read articles from Esubalew Chekol directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Esubalew Chekol
Esubalew Chekol

Experienced Developer in Python, Javascript, Django, Node.js React, React Natvie Jetpack Compose and Telegram bot development.