From registering your app through getting an access token, OAuth 2.0 with PKCE, pagination and rate limits, creating and curating playlists, an SQLite cache, testing and scheduled runs with cron. Twenty lessons that build one complete command — mymix — which turns your listening history into a weekly playlist. The code and output come from actually running Python 3.14.2 with requests 2.34.2, against the API as it stands in September 2026.
The 20 lessons are grouped into five chapters. Working through them in order is the best way, but you are welcome to dip into whatever interests you. Note: calls to the Spotify Web API cannot run inside the browser, so use your own Python. The parts that are pure computation do run in the in-page editor.
You establish what does and does not work today, register an app, and get an access token. Finally you call GET /tracks/{id} and build a helper that converts between IDs, URIs and URLs.
You pick up the three things every endpoint needs: search, pagination and error handling. Finally you write a request function that keeps going when it hits a 429, and route every later call through it.
You get access to your own data, which an app token cannot reach. You compute PKCE yourself, receive the authorisation code on 127.0.0.1, and finish by making the consent screen never appear again.
You read your top tracks, listening history and library, then create playlists, add tracks and reorder them. The endpoints rebuilt in February 2026 are covered only in their new form.
With recommendations retired, you build track selection from your own data instead. Finally you add caching and tests and turn it into a single command that runs weekly from cron.
Once you have finished all 20 lessons, switch sides and build an API yourself: FastAPI for Beginners takes one task management API from start to finish. Membership unlocks every course.