A FastAPI service that sorts your Spotify playlists by track name, artist, album, duration, date added, popularity, or release date.
- A Spotify Developer account
- A registered app with redirect URI:
http://127.0.0.1:8000/auth/callback - Python 3.11+
cd Projects/spotify-playlist-sorter
python -m venv .venv
# Windows
.venv\Scripts\activate
pip install -r requirements.txt
copy .env.example .envEdit .env with your Spotify client credentials and a random SESSION_SECRET.
uvicorn app.main:app --reload --host 127.0.0.1 --port 8000Open http://127.0.0.1:8000/docs for interactive API docs.
- Visit
GET /auth/loginin your browser to authorize with Spotify. - After redirect, your session cookie is set automatically.
- Use
GET /auth/meto verify authentication.
| Endpoint | Description |
|---|---|
GET /health |
Health check |
GET /auth/login |
Start Spotify OAuth |
GET /auth/me |
Current auth status |
GET /auth/logout |
Clear session |
GET /playlists |
List your playlists |
GET /playlists/{id} |
Playlist details |
POST /playlists/{id}/sort |
Sort a playlist |
Preview without modifying:
POST /playlists/{playlist_id}/sort
{
"by": "artist",
"order": "asc",
"dry_run": true
}Apply the sort:
POST /playlists/{playlist_id}/sort
{
"by": "release_date",
"order": "desc",
"dry_run": false
}name— track titleartist— primary artistalbum— album nameduration— track length (ms)added_at— when the track was added to the playlistpopularity— Spotify popularity scorerelease_date— album release date
asc— ascendingdesc— descending
- Only track items are sorted; podcast episodes and other non-track entries are skipped.
- You can only sort playlists you own or collaborative playlists — followed playlists owned by others will return 403.
- Spotify's 2026 API uses
/playlists/{id}/items(not/tracks). If you previously authenticated, visit/auth/logoutthen/auth/loginagain after updating. - Large playlists are rewritten in batches of 100 tracks per Spotify API limits.
- Use
dry_run: truefirst to preview the new order before applying changes. - The
popularitysort field may return identical values — Spotify removed popularity from playlist item responses in 2026.