
Spotify API: Build a Music Discovery Tool in 50 Lines of Python
Spotify's API is one of the most generous free APIs available. You get access to 100 million tracks, audio features, recommendations, and playlist data — all for free. Here's how to build a music discovery tool in 50 lines. Setup (2 Minutes) Go to developer.spotify.com Create an app (free) Copy your Client ID and Client Secret pip install httpx Authentication Spotify uses Client Credentials flow for public data: import httpx import base64 CLIENT_ID = ' your_client_id ' CLIENT_SECRET = ' your_client_secret ' def get_token (): auth = base64 . b64encode ( f ' { CLIENT_ID } : { CLIENT_SECRET } ' . encode ()). decode () r = httpx . post ( ' https://accounts.spotify.com/api/token ' , headers = { ' Authorization ' : f ' Basic { auth } ' }, data = { ' grant_type ' : ' client_credentials ' } ) return r . json ()[ ' access_token ' ] token = get_token () headers = { ' Authorization ' : f ' Bearer { token } ' } Search for Artists def search_artist ( name ): r = httpx . get ( ' https://api.spotify.
Continue reading on Dev.to
Opens in a new tab




