Auth
Auth helpers live in spotify_sdk.auth. They power client credentials and
custom auth providers.
Client Credentials
Use client credentials to let the SDK fetch and refresh access tokens.
Environment Variables
If client_id or client_secret are omitted, the SDK reads:
SPOTIFY_SDK_CLIENT_IDSPOTIFY_SDK_CLIENT_SECRET
Explicit arguments override environment variables.
Limitations
Client credentials tokens cannot access user endpoints (for example, /me/*).
Token Cache
The client credentials provider caches tokens in memory by default. You can pass a custom cache implementation that follows this interface:
from typing import Protocol
from spotify_sdk.auth import TokenInfo
class TokenCache(Protocol):
def get(self) -> TokenInfo | None:
...
def set(self, token: TokenInfo) -> None:
...
TokenInfo
TokenInfo is a simple container used by caches:
from spotify_sdk.auth import TokenInfo
token = TokenInfo(access_token="...", expires_at=1700000000.0)
Auth Providers
You can supply custom providers to clients via auth_provider=.... Providers
need a get_access_token() method and an optional close().