Spotify SDK

raw JSON →
0.10.0 verified Sat May 09 auth: no python

A Python SDK for the Spotify Web API. Current version is 0.10.0, requiring Python >=3.10. The library is actively maintained with a focus on async/await patterns.

pip install spotify-sdk
error TypeError: object dict can't be used in 'await' expression
cause Calling a method that is not async or forgetting await on a coroutine.
fix
Ensure you are using the async client (default) and prefix all method calls with 'await'.
error spotify_sdk.exceptions.SpotifyAuthError: (400) 'invalid_client'
cause Incorrect client_id or client_secret, or using the wrong authentication flow.
fix
Double-check your credentials in the Spotify Developer Dashboard and use the correct flow (e.g., ClientCredentialsFlow for client-only apps).
error AttributeError: 'NoneType' object has no attribute 'token'
cause Failed to fetch token or forgot to set client.token after authentication.
fix
Ensure you await flow.fetch_token() and assign the returned token to client.token.
breaking Version 0.10.0 introduces breaking changes: the async client is now the default. The synchronous client has been removed. All methods require await.
fix Update your code to use async/await. Remove any synchronous calls.
gotcha Tokens must be set explicitly on the client after authentication. Forgetting to assign client.token results in an unauthorized error.
fix After fetching a token, set client.token = token.
deprecated The use of ClientCredentialsFlow without explicit scopes is deprecated. Provide scopes parameter for future functionality.
fix Use ClientCredentialsFlow(client_id, client_secret, scopes=...).

Authenticate via client credentials and perform a track search.

import asyncio
from spotify_sdk import SpotifyClient
from spotify_sdk.auth import ClientCredentialsFlow

async def main():
    client = SpotifyClient()
    flow = ClientCredentialsFlow(client_id='your_client_id', client_secret='your_client_secret')
    token = await flow.fetch_token()
    client.token = token
    result = await client.search('Never Gonna Give You Up', types=['track'])
    print(result)

asyncio.run(main())