AsyncSpotifyClient
TheAsyncSpotifyClient class is the main asynchronous client for interacting with the Spotify Web API. It provides async 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 async 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
TheAsyncSpotifyClient provides access to all Spotify API services through the following async service attributes:
Async service for interacting with album endpoints. Get album details, tracks, and more.
Async service for interacting with artist endpoints. Get artist details, albums, top tracks, and related artists.
Async service for interacting with audiobook endpoints. Get audiobook details and chapters.
Async service for interacting with audiobook chapter endpoints. Get chapter details.
Async service for interacting with podcast episode endpoints. Get episode details.
Async service for managing the user’s library. Save and retrieve albums, tracks, audiobooks, episodes, and shows.
Async service for managing playlists. Create, update, and retrieve playlists and their items.
Async service for searching Spotify content. Search for albums, artists, playlists, tracks, shows, episodes, and audiobooks.
Async service for interacting with podcast show endpoints. Get show details and episodes.
Async service for interacting with track endpoints. Get track details, audio features, and audio analysis.
Async 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 newAsyncSpotifyClient instance configured with client credentials authentication.
Example
Instance Methods
close
Example
Async Context Manager Support
TheAsyncSpotifyClient supports the async context manager protocol, allowing you to use it with Python’s async with statement. The client will automatically close when the context exits.
Example
Usage Examples
Performance Benefits
TheAsyncSpotifyClient is ideal for applications that need to make multiple concurrent API requests or integrate with async frameworks like FastAPI, aiohttp, or Starlette. Key benefits include:
- Concurrent request execution with
asyncio.gather() - Non-blocking I/O for better resource utilization
- Seamless integration with async web frameworks
- Improved throughput for batch operations