Spotifython
raw JSON → 0.2.12 verified Sat May 09 auth: no python
A caching Python interface to readonly parts of the Spotify API. Current version 0.2.12, requires Python >=3.10, with monthly releases. Provides simple access to Spotify data with built-in caching.
pip install spotifython Common errors
error spotifython.exceptions.SpotifythonException: Invalid client id ↓
cause Missing or incorrect SPOTIFY_CLIENT_ID or SPOTIFY_CLIENT_SECRET environment variables.
fix
Set SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET in your environment or pass them directly.
error KeyError: 'id' ↓
cause Search returned no results or malformed response.
fix
Verify the search query and ensure it's correctly spelled.
error ModuleNotFoundError: No module named 'spotifython' ↓
cause Package not installed or installed in wrong environment.
fix
Run 'pip install spotifython' in your active Python environment (Python >=3.10).
Warnings
gotcha API is readonly: only GET endpoints are supported. No playback control or playlist modification. ↓
fix Use other libraries (e.g., spotipy) for write operations.
gotcha Client credentials flow only. User-specific tokens not supported; endpoints requiring user authentication (e.g., user playlists) are limited. ↓
fix Pass a valid client_id and client_secret from Spotify Developer Dashboard.
deprecated Search endpoint may return inconsistent results due to API version changes. ↓
fix Use specific methods like spotify.track() where possible.
Imports
- Spotify
from spotifython import Spotify
Quickstart
import os
from spotifython import Spotify
client_id = os.environ.get('SPOTIFY_CLIENT_ID', '')
client_secret = os.environ.get('SPOTIFY_CLIENT_SECRET', '')
spotify = Spotify(client_id=client_id, client_secret=client_secret)
track = spotify.track('4cOdK2wGLETKBW3PvgPWqT')
print(track['name'])