Skip to content

sok.apis.music.spotify_api

Spotify API Implementation

SpotifyApi

class SpotifyApi(client_id: str, client_secret: str)

Bases: BaseAPI

Spotify API implementation using Client Credentials Flow.

Initialize Spotify API.

Parameters

NameTypeDescription
client_idstrSpotify application client ID.
client_secretstrSpotify application client secret.
Source

Attributes

NameTypeDescription
access_tokenOptional[str]

Current OAuth access token.

client_id

Spotify application client ID.

client_secret

Spotify application client secret.

supported_content_typesproperty

List[ContentType]

Return supported content types.

supported_media_typesproperty

List[MediaType]

Return supported media types.

get_detailsasync

async def get_details(
item_id: str,
content_type: ContentType,
**kwargs,
) -> Dict[str, Any]:

Get details for a Spotify item.

Parameters

NameTypeDescription
item_idstrSpotify item ID.
content_typeContentTypeType of item (ALBUM, TRACK, ARTIST).
**kwargsAdditional parameters.

Returns

  • Dict[str, Any]Dictionary with item metadata.
Source
async def get_related_items(
item_id: str,
content_type: ContentType,
**kwargs,
) -> List[Dict[str, Any]]:

Get related items (tracks for albums).

Parameters

NameTypeDescription
item_idstrSpotify item ID.
content_typeContentTypeContent type (only ALBUM supported).
**kwargsAdditional parameters.

Returns

  • List[Dict[str, Any]]List of track dictionaries for ALBUM, empty list otherwise.
Source
async def search(
query: str,
content_type: ContentType,
**kwargs,
) -> Dict[str, Any]:

Search on Spotify.

Parameters

NameTypeDescription
querystrSearch query string.
content_typeContentTypeType to search (ALBUM, TRACK, ARTIST).
**kwargsAdditional parameters including 'limit'.

Returns

  • Dict[str, Any]Dictionary with 'results' list of matches.
Source

Attributes

NameValue
loggerlogging.getLogger(__name__)
Built with Kiln