Add Dictionary Services to Projects with the Oxford Dictionary API

This tutorial will demonstrate how to include the Oxford Dictionary API in your application. Though the number of projects that need dictionary features may be somewhat limited, I found that having the ability to integrate a dictionary feature very useful.

 

Getting Started

Like most APIs, you need to sign up for a dev account in order to make the calls. You can sign up for an account at https://developer.oxforddictionaries.com/?tag=#plans . If your application needs to make more than three-thousand requests per month you will need to sign up for a paid plan. However, I feel that the free account offers more than enough calls for a personal application. Once your account is created, you should be given an app id and application key. You will need both of these to make requests.

Configuring Your Application to make request

Once we have the account set up, it is time to code! Though I found this api to be one of the easiest ones to use, there is some setup. To get started open up a new python script.

 

The only library needed to make calls is requests. Since it is not installed by default you will need to pip install requests to continue. We also have a great tutorial on requests here. Once this is done add:

 

import requests

import json

 

Next, add the app_id and app_key given to you when you created your account. You can retrieve both pieces from https://developer.oxforddictionaries.com/admin/applications if you did not save this information. Add it to the script with something like:

 

id = ‘enter_your_id_here’

key = ‘enter_your_key_here

 

Finally, we need to add information about the API to make getting information easier. Since most services the API offers follows the base url of https://od-api.oxforddictionaries.com:443/api/v1/ it would be best practice to store it as a variable and append the different services later.  We also need to include what language to use and the word itself. This can be done with the lines of:

 

base = https://od-api.oxforddictionaries.com:443/api/v1/

word = ‘Obfuscation’

language = ’en’

 

Finally, we need to specify what service to call. For most services like the dictionary feature this will be ‘entries’. However, https://developer.oxforddictionaries.com/documentation gives a list of all services offered and how it should be appended to the base url. In our script add:

 

service = ‘entries

 

Concatenate all the parts together to make the url for the request

 

requestUrl = base + service + language + ‘/’ + word

 

And that’s it! We are ready to make call the API and get the result. Following the requests format make the call with the following

 

request = requests.get(requestUrl, headers = {‘app_id’: id’, ‘app_key’: key})

 

If setup correctly, you should receive a JSON object with the result. Print the standard result with

 

print(request.text)

 

Results  

 Project Code

You can download the code for the project here.

 

Contact Us To Setup A Meeting

Feel free to call or email anytime to setup a meeting. We would love to discuss your project to see if we can help!

contact us