DEV Community

Aran Services
Aran Services

Posted on

How to Export a Spotify Playlist to CSV with Python

Have you ever wanted to inspect your Spotify playlists in a spreadsheet, find repeated tracks, or build your own music analysis tool?

You can do this with Python and SpotAPI, an open-source library I maintain.

This example works with publicly accessible playlists without registering a Spotify developer application.

Getting started

Install SpotAPI:

python -m pip install spotapi
Enter fullscreen mode Exit fullscreen mode

Download the playlist auditing example from the repository:

https://github.com/Aran404/SpotAPI/blob/main/examples/playlist_audit.py

Save it as playlist_audit.py.

Export your playlist

Copy a public Spotify playlist link and run:

python playlist_audit.py "YOUR_PLAYLIST_URL" --output playlist.csv
Enter fullscreen mode Exit fullscreen mode

You can also limit the number of entries scanned:

python playlist_audit.py "YOUR_PLAYLIST_URL" \
    --output playlist.csv \
    --max-items 500
Enter fullscreen mode Exit fullscreen mode

The full example supports up to 10,000 playlist entries.

What does the CSV contain?

  • Track names
  • Artists
  • Spotify identifiers
  • Track durations
  • Dates added, when available
  • Playlist positions
  • Repeated track identifiers
  • Unavailable entries

You can open the resulting CSV in Excel, Google Sheets or a Python data analysis tool.

Duplicate detection currently identifies repeated Spotify track URIs. It doesn't assume that different releases of the same song are necessarily identical recordings.

How it works

The script reads playlist entries through SpotAPI's asynchronous pagination interface. Rather than loading an entire large playlist into memory, it processes entries incrementally.

It also preserves repeated track occurrences instead of silently discarding them.

The export is read-only. Your original Spotify playlist is not modified.

Why I built this

I started reverse-engineering Spotify's web player in high school because I was curious about what developers could build with it.

Playlist analysis is one of the more practical applications that emerged from the project.

SpotAPI uses unofficial endpoints, which may change over time. Only use it with playlists you're permitted to access.

GitHub: https://github.com/Aran404/SpotAPI

If you build an interesting playlist analysis tool with it, I'd genuinely love to see it.

Top comments (0)