Getting started with Wordnik’s word & worldlist API

Getting started with Wordnik's Word & Worldlist API
Published: by
Last updated:
Categories
Website Development

In today’s world where language is somewhat neglected modern ‘word-related’ services are a welcome edition to the struggle against illiteracy. One such service provider, Wordnik, offers unique word and other English language related services.

Introducing Wordnik

Wordnik bills itself as “a place for all the words, and everything known about them.” They allow users to look up definitions, add new words to their online database and provide example sentences pulled from the internet. Unlike many online dictionaries, Wordnik’s content can be accessed through their API.

From their website:

“Wordnik has amassed an incredible amount of data… one of our core principles is that you shouldn’t have to come to any particular web site to learn about words: the word data should come to you wherever you are.”

Wordnik’s API

Wordnik’s RESTful API allows developers to look up definitions, display the use of words in example sentences and return data about how frequently the word appears in Wordnik’s corpus. The Wordnik API also gives developers access to an auto complete function, and both a ‘random word’ and a ‘word of the day’ listing. Data for each function is accessed by GET request, and data can be returned in either XML or JSON format.

For Python

For the official Python library see Github and follow the instructions there. Other code libraries can be obtained here.

Pip needs to be installed:

sudo apt-get install python-pip
sudo pip install --upgrade pip --index-url=https://pypi.python.org/simple/

After installation, sign up for a Wordnik account and and get an API key.

Wordnik API Python sample script

Create a new Python script in a desired location. For the Word Of The Day script I will use /home/pi/wotd/wotd.py for explanation purposes. In a freshly booted Raspberry Pi terminal use:

mkdir /home/pi/wotd
nano /home/pi/wotd/wotd.py

and copy the following code into it:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from wordnik import *
apiUrl = 'http://api.wordnik.com/v4'
apiKey = 'your-api-key-here'
client = swagger.ApiClient(apiKey, apiUrl)

wordsApi = WordsApi.WordsApi(client)
wotd = wordsApi.getWordOfTheDay()

print wotd.word
print wotd.definitions[0].text
print wotd.note
print wotd.examples[0].text

Change the API details to the one from your own account, exit and save (Ctrl + X & Y).

To run the script use:

python /home/pi/wotd/wotd.py

You can see more Words functions on the official Python development page (https://github.com/wordnik/wordnik-python).

About the author
Renier busies himself with improving his English writing, creative web design and his websites, photoshopping, micro-electronics, multiple genres of music, superhero movies and badass series.
Behind the Scenes is a free, informative website. If you find value in any of our content, please consider making a donation to our cause.
Donate via PayPal

Save, share & Disqus

Use the buttons below, on the left or the bottom of this page to share this post. Your comment is important, but don't be a knob. Keep it constructive and polite.

Comment via Disqus

Disqus is a worldwide comment hosting service for web sites and online communities. This secure platform ensures a pleasant commenting environment which is manageable from one account. Use the Login button to sign up.

More website development related posts

Try one of Lynda.com’s online software and skills learning courses
Try one of Lynda.com’s online software and skills learning courses
21 November 2019
Ad: Improve your knowledge on anything from programming to business skills with Lynda.com’s huge range of professional video courses. More…
Getting started with private projects on Raspbian and Bitbucket
Getting started with private projects on Raspbian and Bitbucket
28 October 2018
Bitbucket is a great alternative to Github to start, store and track simple programming dependant project files. On a Raspberry Pi it can be simply done using Raspbian. In addition to Github, projects uploaded to Bitbucket with less than 6 contributors can be kept private and won’t cost a cent. More…
Using Cron to schedule tasks
Using Cron for scheduling tasks
30 June 2017 | Updated 11 July 2017
Cron is an Unix-like operating system software utility used to schedule automatic time-based commands. Entered commands can be in the form of Bash or Bash scripts that are meant to be automatically executed periodically at fixed times, dates or intervals. More…