Spotify API Data Retrieval

Build the SpotifyAPI class.

Use the class to:


source

SpotifyAPI

 SpotifyAPI (region_name)

A class for interacting with the Spotify API.

Type Details
region_name str The name of the AWS region where the secrets manager is located.

source

SpotifyAPI.get_secret

 SpotifyAPI.get_secret (secret_name)

Retrieves the specified secret from AWS Secrets Manager and sets the corresponding environment variables.

Type Details
secret_name str The name of the secret to retrieve.

source

SpotifyAPI.create_headers

 SpotifyAPI.create_headers ()

Creates the headers required for making requests to the Spotify API.


source

SpotifyAPI.refresh_token

 SpotifyAPI.refresh_token ()

Refreshes the access token required for making requests to the Spotify API.


source

SpotifyAPI.get_track_subset

 SpotifyAPI.get_track_subset (playlist_id, offset)

Retrieves a subset of tracks from the specified Spotify playlist.

Type Details
playlist_id str The ID of the Spotify playlist to retrieve tracks from.
offset int The offset to use when retrieving tracks.
Returns list A list of track items.

source

SpotifyAPI.get_subset_features

 SpotifyAPI.get_subset_features (track_items)

Given a list of track items, returns a pandas DataFrame containing information about each track, including the track ID, name, artist, artist ID, and audio features such as danceability, energy, and tempo.

Type Details
track_items list A list of track items, where each item is a dictionary containing information about a track.
Returns pandas.DataFrame A DataFrame containing information about each track, including the track ID, name, artist, artist ID, and audio features such as danceability, energy, and tempo.

source

SpotifyAPI.get_playlist_features

 SpotifyAPI.get_playlist_features (playlist_id)

Given a Spotify playlist ID, returns a pandas DataFrame containing information about all the tracks in the playlist, including the track ID, name, artist, artist ID, and audio features such as danceability, energy, and tempo.

Type Details
playlist_id str The ID of the Spotify playlist.
Returns pandas.DataFrame A DataFrame containing information about all the tracks in the playlist, including the track ID, name, artist, artist ID, and audio features such as danceability, energy, and tempo.

source

SpotifyAPI.parse_new_tracks

 SpotifyAPI.parse_new_tracks (lookback_days=7)

Sorts tracks based on when they were added and filters out tracks added more than ‘lookback_days’ ago. Returns two DataFrames: one containing the new tracks added within the lookback period, and one containing the old tracks added before the lookback period.

Type Default Details
lookback_days int 7 The number of days to look back for new tracks. Defaults to 7.
Returns pandas.DataFrame A DataFrame containing the old tracks added before the lookback period.

source

SpotifyAPI.delete_tracks

 SpotifyAPI.delete_tracks (tracks_to_delete)

Deletes a batch of tracks from a Spotify playlist.

Type Details
tracks_to_delete pandas.DataFrame A DataFrame containing the tracks to be deleted, where each row represents a track and contains a ‘uri’ column with the URI of the track.
Returns None