A python library for easily graphing and visualizing your Spotify data.
Project description
splotify
A python library for easily graphing and visualizing your Spotify data.
Installation
Install the library by running:
pip install splotify
Usage
-
First, you need to get your
SPOTIPY_CLIENT_ID
,SPOTIPY_CLIENT_SECRET
, and redirect uri. Here is a video created by Spotipy that explains how to do so. -
Declare a
SpotifyAPI
object that allows you to access data from Spotify. -
Declare a
Data
object to store all the songs which you want to plot. You can add individual or multiple tracks, albums, or playlists at a time. -
Determine the kind of data you want to plot:
- Category plots (bar charts, pie charts) allow you to plot songs by groups (i.e. artists or albums).
- Audio Feature Plots allow you to plot songs by their audio features.
-
If you need to look up the Spotify ids of tracks, albums, artists, or playlists, you can use the
search_id
(for general searches) ormy_id
(for user-specific playlists) functions.
Here is an example analyzing Spotify's "This is Radiohead" playlist:
import spotifyapi
import data
import plots.audiofeatures as af
import plots.category as c
sp = spotifyapi.SpotifyApi(
"234645624be5451eb959f0af3d9e00ac",
"a1425a973e8d4574a0dfbd3c9e20438f",
"https://localhost:8888/callback",
)
d = data.Data(sp)
# add tracks from the "This is Radiohead" playlist
d.add_playlist("37i9dQZF1DZ06evO2VxlyE")
# view data about the tracks' audio features
afp = af.AudioFeaturesPlot(sp, d.get_data(), ["energy", "loudness"])
# scatter plot of energy vs. loudness of the tracks in the playlist
afp.scatter_plot_2d(color="album")
# box plot of the tracks' energy values, grouped by album
afp.box_plot(["energy"], groupby="album")
cp = c.CategoryPlot(d.get_data())
# pie chart of albums in the playlist
cp.pie_chart()
This code produces the following plots:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.