Spotify Web API for Python
raw JSON → 1.2.8 verified Sat May 09 auth: no python
A simple Python wrapper for the Spotify Web API. Current version 1.2.8, supports Python >=3.6. Released under MIT license, maintained on GitHub. Release cadence is irregular.
pip install spotifywebapi Common errors
error ModuleNotFoundError: No module named 'spotifywebapi' ↓
cause Library not installed or wrong environment.
fix
Run pip install spotifywebapi in the correct Python environment.
error spotifywebapi.exceptions.InvalidTokenError: Token is invalid or expired ↓
cause Forgot to call authenticate() before making requests, or token expired.
fix
Call api.authenticate() and do not reuse expired tokens.
error TypeError: __init__() missing 2 required positional arguments: 'client_id' and 'client_secret' ↓
cause Missing credentials when creating SpotifyAPI instance.
fix
Provide both client_id and client_secret as arguments.
Warnings
gotcha Always call authenticate() before making API calls. The library does not auto-refresh tokens. ↓
fix Make sure to call api.authenticate() after creating the instance.
gotcha The library uses Spotify's Client Credentials Flow only. It does not support Authorization Code flow for user-specific endpoints. ↓
fix Use another library like spotipy if you need user authorization.
deprecated Python 3.6 support may be deprecated in future releases. ↓
fix Upgrade to Python 3.8+ for future compatibility.
Imports
- SpotifyAPI wrong
from spotifywebapi import Clientcorrectfrom spotifywebapi import SpotifyAPI
Quickstart
from spotifywebapi import SpotifyAPI
api = SpotifyAPI(client_id='YOUR_CLIENT_ID', client_secret='YOUR_CLIENT_SECRET')
api.authenticate()
track = api.get_track('6y0igZArWVi3k3N9S20QXN')
print(track)