SpotifyClient
TheSpotifyClient class is the main synchronous client for interacting with the Spotify Web API. It provides access to all Spotify API services through dedicated service attributes.
Constructor
Parameters
Spotify API access token. Use this if you already have a valid access token.
Spotify API client ID. Use with
client_secret for client credentials flow.Spotify API client secret. Use with
client_id for client credentials flow.Custom auth provider for dynamic access token management. Provide this for advanced authentication scenarios.
Default request timeout in seconds. Controls how long to wait for API responses.
Maximum number of retries for failed requests. The client will automatically retry failed requests up to this limit.
You must provide exactly one of the following:
access_token- Both
client_idandclient_secret auth_provider
ValueError.Examples
Service Attributes
TheSpotifyClient provides access to all Spotify API services through the following attributes:
Service for interacting with album endpoints. Get album details, tracks, and more.
Service for interacting with artist endpoints. Get artist details, albums, top tracks, and related artists.
Service for interacting with audiobook endpoints. Get audiobook details and chapters.
Service for interacting with audiobook chapter endpoints. Get chapter details.
Service for interacting with podcast episode endpoints. Get episode details.
Service for managing the user’s library. Save and retrieve albums, tracks, audiobooks, episodes, and shows.
Service for managing playlists. Create, update, and retrieve playlists and their items.
Service for searching Spotify content. Search for albums, artists, playlists, tracks, shows, episodes, and audiobooks.
Service for interacting with podcast show endpoints. Get show details and episodes.
Service for interacting with track endpoints. Get track details, audio features, and audio analysis.
Service for interacting with user endpoints. Get user profiles and manage following.
Class Methods
from_client_credentials
Parameters
Spotify API client ID.
Spotify API client secret.
Default request timeout in seconds.
Maximum number of retries for failed requests.
Returns
A newSpotifyClient instance configured with client credentials authentication.
Example
Instance Methods
close
Example
Context Manager Support
TheSpotifyClient supports the context manager protocol, allowing you to use it with Python’s with statement. The client will automatically close when the context exits.