ByeByeSpotify: Spotify Library Export Tool
Overview
ByeByeSpotify is a Python command-line tool that exports your entire Spotify library to portable JSON and CSV formats. I built this tool when I decided to leave Spotify for personal reasons and realized there was no straightforward way to back up years of carefully curated playlists and listening data.
Spotify makes it difficult to leave their ecosystem. Your playlists, liked songs, and listening history are locked behind their API, with no built-in export functionality. When I needed to preserve my music library before canceling my subscription, I built ByeByeSpotify to solve that problem—and shared it so others wouldn’t have to start from scratch.
Key Features
- Comprehensive Export: Downloads liked songs, playlists, albums, followed artists, top tracks, listening statistics, podcasts, and audiobooks
- Dual Format Output: Generates both JSON (complete metadata) and CSV (spreadsheet-friendly) files for maximum compatibility
- OAuth Security: Uses modern PKCE authentication flow (no client secret needed)
- Organized Output: Creates timestamped exports in structured directories with individual playlist CSV files
- API Management: Handles rate limiting and pagination automatically
- Platform Migration: CSV format designed for easy importing to Apple Music, YouTube Music, or other services
Technical Implementation
Authentication Architecture
Implemented secure OAuth 2.0 PKCE (Proof Key for Code Exchange) flow, eliminating the need for client secret storage:
# PKCE flow configuration
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
client_id=SPOTIFY_CLIENT_ID,
redirect_uri="http://127.0.0.1:8888",
scope=SCOPES,
open_browser=True
))
This approach is more secure than traditional OAuth flows and better suited for client-side applications.
Data Export Strategy
The tool exports data in two complementary formats:
JSON Format: Complete metadata preservation
- Full track information including artist details, album data, popularity metrics
- Nested structures for complex data like playlists and albums
- Ideal for programmatic processing or custom analysis
CSV Format: Human-readable and migration-friendly
- Flattened structures for spreadsheet compatibility
- Individual CSV files per playlist for targeted imports
- Designed for importing to competing platforms
API Pagination & Rate Limiting
Spotify’s API returns results in batches (typically 50 items). The tool automatically handles pagination to retrieve complete datasets:
# Automatic pagination for large datasets
results = sp.current_user_saved_tracks(limit=50)
while results['next']:
results = sp.next(results)
all_tracks.extend(results['items'])
Rate limiting is managed by the Spotipy library, which implements exponential backoff for 429 (Too Many Requests) responses.
Use Cases
Platform Migration
Export your Spotify library before switching to Apple Music, YouTube Music, Tidal, or self-hosted solutions like Plex or Jellyfin. CSV files map cleanly to most music platform import formats.
Data Ownership
Maintain an independent backup of your music library metadata. Streaming services can remove tracks, change catalogs, or alter recommendations—your export remains unchanged.
Listening Analytics
Analyze your music preferences over time with JSON exports. Build custom visualizations, track genre trends, or create recommendation algorithms using your historical data.
Playlist Archival
Preserve collaborative playlists before members leave or playlists get deleted. Export creates a permanent record of the playlist state at export time.
Output Structure
spotify_export_YYYY-MM-DD_HHMM/
├── SUMMARY.txt # Human-readable overview
├── liked_songs.json # Full liked songs metadata
├── liked_songs.csv # Spreadsheet-friendly format
├── playlists.json # All playlists with tracks
├── playlists/
│ ├── playlist_name_1.csv
│ ├── playlist_name_2.csv
│ └── ...
├── albums.json
├── albums.csv
├── artists.json
├── artists.csv
├── top_tracks_short_term.json
├── top_tracks_medium_term.json
├── top_tracks_long_term.json
├── podcast_shows.json
└── audiobooks.json
Limitations & Considerations
Recently Played Limitation: Spotify’s API only provides approximately 50 recently played tracks, not full listening history. This is a platform limitation, not a tool limitation.
Redirect URI Requirement: OAuth redirect URI must be exactly http://127.0.0.1:8888. Changing this breaks authentication.
Rate Limits: Large libraries (10,000+ tracks) may take several minutes to export due to API pagination and rate limiting.
Technology Stack
- Python 3.7+: Core language
- Spotipy: Official Spotify Web API wrapper
- OAuth 2.0 PKCE: Secure authentication without client secrets
- CSV & JSON: Universal export formats
Real-World Impact
When I decided to leave Spotify, I faced a choice: lose years of carefully organized music data or spend days manually recreating playlists elsewhere. Neither was acceptable.
I built ByeByeSpotify in a weekend to solve my own problem. The tool successfully exported my entire library—playlists, liked songs, albums, listening stats—in under 10 minutes. What would have taken days of manual work became a simple command-line operation.
After open-sourcing the project, others in similar situations have used it to migrate to Apple Music, YouTube Music, self-hosted servers, or simply to maintain independent backups. Data portability matters. Streaming platforms create walled gardens, but your music library shouldn’t be held hostage by platform lock-in.
Source Code
The project is open source and available on GitHub: c-rw/ByeByeSpotify
Future Enhancements
Potential improvements include:
- Direct import adapters for major platforms (Apple Music, YouTube Music)
- Incremental export mode (only export new changes since last run)
- Playlist comparison tool (identify changes between exports)
- Conversion to M3U playlist format for local media players
- Integration with music recognition APIs to match tracks across platforms