How To Access and Use the Spotify and LyricGenius API

Spotify and LyricGenius

Spotify is a music streaming service. To use Spotify’s API you must have a Spotify account. The ad free account has a monthly fee as opposed to the free account. However, either version will allow you to get an API key. On the other hand, LyricGenius is a cite of song lyrics. To retrieve information from either one must update their terminal.

Step 1: Terminal

In the terminal write …


Once on the website (link above) click My Dashboard

Sign into your Spotify account after clicking My Dashboard. Once logged in you’ll be given a Client_ID and a Client_Secret. It should look like this:

With the IDs the coding process may begin! Open Jupyter notebook, Python, Vscode, or another place of your choosing to code. The README on the following link lays out the code.

Use the following as a template for your code:


Now we’re going to walk through how to access the LyricGenius API just like we did above with the Spotify API.

Once on the website (link above) click the Genius API (in blue) to receive your Client IDs.

LyricGenius asks for an APP WEBSITE URL. Inserting your GitHub account is one option. Once the Genius account provides you with an access token run this code, to find songs based on the artist of your choosing:

Run this code to find song lyrics:

“Am I throwing you off?” Nelly Furtado

“Nope” Timbaland

“Didn’t think so” Nelly Furtado

Spotify Examples

Lets continue with some examples, demonstrating how to apply this knowledge.

Some of these imports should have already been applied. After importing and running the steps from above, a song dictionary was created to hold an accumulation of different songs and their popularities.

Within the dictionary, the song name is the key, and the popularity of the song is the value.

Spotify uses it’s own algorithm to figure out the song popularity.

One can use matplotlib to take the song dictionary and visualize it with a bar graph.

The artist dictionary will be used to keep a record of song names and their corresponding popularities. As you can see below, Beyoncé’s limit is larger because a couple of her songs repeated.

The artist dictionary is made into a DataFrame.

The column, artists, is added to the DataFrame.

How often do I work with DataFrames? The Weeknd asked, “Asked me if I do this every day, I said often.” I work with DataFrames on weekdays too.

Spotify Examples (continuation)

In matplotlib, plt.subplots() was used to create multiple graphs from the DataFrame df_artists. For loops can also be implemented.

From the Beyonce graph we can infer by the popularity power of her songs that she was able to shut down part of a Superbowl.

LyricGenius Examples

Last but not least, how to get song lyrics.

Aspiring Data Scientist