Skip to main content

A convenience package for creating datasets of track features from self-requested Spotify data.

Project description

Spotify Rehydrator

Recreate a full dataset of audio features of songs downloaded through Spotify’s download my data facility.

This requires the files named StreamingHistory{n}.json where {n} represents the file number that starts at 0, and goes up to however many files were retrieved.

Quick start

Extended documentation is available on ReadTheDocs. An example of using the package to rehydrate a folder of json files is:

# main.py
from spotifyrehydrator import Rehydrator
import os
import pathlib

if __name__ == "__main__":
    Rehydrator(
        os.path.join(pathlib.Path(__file__).parent.absolute(), "input"),
        os.path.join(pathlib.Path(__file__).parent.absolute(), "output"),
        client_id=os.getenv("SPOTIFY_CLIENT_ID"),
        client_secret=os.getenv("SPOTIFY_CLIENT_SECRET"),
    ).run(return_all=True)

Run takes boolean arguments for audio_features and artist info, or for return_all which then returns both. These will determine how much information is retrieved to make up the full dataset that is saved into the output folder.

How it works

  1. The files for each person are read from the specified input folder.
  2. The name and artist provided are searched with the Spotify API. The first result is taken to be the track, and the track ID is recorded.
  3. Additional information is searched on other endpoints if audio_features, artist info or return_all were set to True.
  4. The matched track ID and audio features are saved as one tab delimited .tsv file per person into the specified output folder.

Good to know

  • Not all tracks can be retreived from the API. In our experience about 5% of tracks cannot be found on the API. These will have a value of NONE in the output files.
  • There is not a guaranteed match between the first returned item in a search and the track you want. Comparing msPlayed with the track length is a good way to test this since msPlayed should not exceed the track length.

P.S. Thanks to Pixel perfect for the title icon. 🙂

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for spotifyrehydrator, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size spotifyrehydrator-0.1.0-py3-none-any.whl (25.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size spotifyrehydrator-0.1.0.tar.gz (10.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page