# don't do this in practice
client_access_token = "INSERT YOUR CLIENT ACCESS TOKEN IN THESE QUOTATION MARKS"API Keys
Get access to Genius Lyrics
Tutorial Overview
This tutorial walks you through obtaining an API Key for the Genius API. This tutorial is adapted from Intro to Cultural Analytics by Melanie Walsh.
Application Programming Interfaces (APIs)
In the previous lesson, we collected internet data by scraping the surface of web pages. But there’s another way of collecting internet data called Application Programming Interfaces (APIs).
What is an API?
An API allows you to programmatically extract and interact with data under the hood of websites like Genius as well as other social networks, applications, and projects that make their data publicly available, such as Twitter and The Smithsonian museums.
An API is something that a project or company explicitly designs for data-sharing purposes. Why do companies or projects go to all this trouble? One reason is that it helps to promote the use and further development of an application and its data. For example, Twitter wants other developers to use, integrate, and build upon Twitter tools and data. The Twitter API is the main conduit by which these developers can do so.
Pros
Because APIs are explicitly designed for data-sharing purposes, working with an API is often a cleaner, more reliable, and more streamlined process than web scraping.
Cons
One of the downsides is that the companies and projects that design the APIs get to decide exactly which kinds of data they want to share. *Spoiler alert* They often choose not to share their most lucrative and desirable data. For example, the Genius API does not provide access to lyrics data, and the Twitter API does not provide free access to tweets more than 14 days in the past. To get that Twitter data, you need to pay for special API access.
Genius API: API Keys
To use the Genius Lyrics API, you need a special API key, specifically a “Client Access Token”, which is kind of like a password. Many APIs require authentication keys to gain access to them. To get your necessary Genius API keys, you need to navigate to the following URL: https://genius.com/api-clients.
You’ll be prompted to sign up for a Genius account, which is required to gain API access. Signing up for a Genius account is free and easy. You just need a Genius nickname (which must be one word), an email address, and a password.
Once you’re signed in, you should be taken to https://genius.com/api-clients, where you need to click the button that says “New API Client.”
After clicking “New API Client,” you’ll be prompted to fill out a short form about the “App” that you need the Genius API for. You only need to fill out “App Name” and “App Website URL.”
It doesn’t really matter what you type in. You can simply put “Data 6 Fall 2025 Project 2” for the “App Name” and the URL for our course website “https://data6.org/fa25/” for the “App Website URL.”
When you click “Save,” you’ll be given a series of API Keys: a “Client ID” and a “Client Secret.” To generate your “Client Access Token,” which is the API key that we’ll be using in this notebook, you need to click “Generate Access Token”.
Finally, you could copy and paste your “Client Access Token” into a Python cell and assign it to a name, client_access_token.
If you are the only one accessing your notebook, you should be fine if you just copy and paste your Genius API into your Jupyter notebook. But that’s actually not the best way of storing your API keys—in fact, it’s incredibly insecure. If you published this notebook to GitHub, for example, other people might be able to read and use/steal your API key.
Protect Your API Key
API keys are like passwords. Where possible, we should not share them publicly in plaintext.
For this reason, it’s best practice to keep your API keys away from your code, such as in another file that we store locally. We will do this by making a new Python file called “api_key.py” that contains just one line my_client_access_token = "MY_API_KEY".
To do this on DataHub, first save whatever notebook you’re in. Then:
- Navigate to the file explorer on DataHub.
- Save your changes in your notebook.
- In the top-right, on the menu bar, click on the dropdown “Open with…” and select “NBClassic.” This should open your notebook in a new tab.
- In the new tab of your notebook, click the Jupyter logo in the top left of your screen. If a pop-up appears saying you have unsaved changes, continue to leave the page (this is because you should still have your original tab with your notebook in it.)
- Navigate to the appropriate folder with your assignment in it.
- Open the
api_key.pyfile. You can open files by clicking on them. - Paste your Client Access Token as a string, assigning it to the name
my_client_access_token. - The resulting
api_key.pyshould exactly have one line in it. In our example, our Client Access Token isMY_API_TOKEN, so our singular line ismy_client_access_token = "MY_API_KEY". - Save and exit.
- Return to your assignment file by closing this tab. You should still have your original tab with your notebook in it; if not, navigate to the notebook from the course website.
We can then import my_client_access_token into my notebook with import api_key.
import api_keyapi_key.my_client_access_token'MY_API_KEY'
By importing this Python file as a module, we get access to my_client_access_token without ever having to explicitly type our secret API token into this notebook. If we were to publish this notebook to GitHub, then we can ignore or leave out the api_key.py file that actually contains the API token.
Finally, we can load this value into our client_access_token:
client_access_token = api_key.my_client_access_token