API#

class minim.tidal.API(*, client_id: str = None, client_secret: str = None, flow: str = 'client_credentials', access_token: str = None, expiry: datetime | str = None, overwrite: bool = False, save: bool = True)[source]#

Bases: object

TIDAL API client.

The TIDAL API exposes TIDAL functionality and data, making it possible to build applications that can search for and retrieve metadata from the TIDAL catalog.

See also

For more information, see the TIDAL API Reference.

Requests to the TIDAL API endpoints must be accompanied by a valid access token in the header. Minim can obtain client-only access tokens via the client credentials flow, which requires valid client credentials (client ID and client secret) to either be provided to this class’s constructor as keyword arguments or be stored as TIDAL_CLIENT_ID and TIDAL_CLIENT_SECRET in the operating system’s environment variables.

See also

To get client credentials, see the guide on how to register a new TIDAL application.

If an existing access token is available, it and its expiry time can be provided to this class’s constructor as keyword arguments to bypass the access token retrieval process. It is recommended that all other authorization-related keyword arguments be specified so that a new access token can be obtained when the existing one expires.

Tip

The authorization flow and access token can be changed or updated at any time using set_auflow() and set_access_token(), respectively.

Minim also stores and manages access tokens and their properties. When an access token is acquired, it is automatically saved to the Minim configuration file to be loaded on the next instantiation of this class. This behavior can be disabled if there are any security concerns, like if the computer being used is a shared device.

Parameters:
client_idstr, keyword-only, optional

Client ID. Required for the client credentials flow. If it is not stored as TIDAL_CLIENT_ID in the operating system’s environment variables or found in the Minim configuration file, it must be provided here.

client_secretstr, keyword-only, optional

Client secret. Required for the client credentials flow. If it is not stored as TIDAL_CLIENT_SECRET in the operating system’s environment variables or found in the Minim configuration file, it must be provided here.

flowstr, keyword-only, optional

Authorization flow.

Valid values:

  • "client_credentials" for the client credentials flow.

access_tokenstr, keyword-only, optional

Access token. If provided here or found in the Minim configuration file, the authorization process is bypassed. In the former case, all other relevant keyword arguments should be specified to automatically refresh the access token when it expires.

expirydatetime.datetime or str, keyword-only, optional

Expiry time of access_token in the ISO 8601 format %Y-%m-%dT%H:%M:%SZ. If provided, the user will be reauthenticated using the specified authorization flow (if possible) when access_token expires.

overwritebool, keyword-only, default: False

Determines whether to overwrite an existing access token in the Minim configuration file.

savebool, keyword-only, default: True

Determines whether newly obtained access tokens and their associated properties are stored to the Minim configuration file.

Attributes:
sessionrequests.Session

Session used to send requests to the TIDAL API.

API_URLstr

Base URL for the TIDAL API.

TOKEN_URLstr

URL for the TIDAL API token endpoint.

Methods

get_album

Album API > Get single album: Retrieve album details by TIDAL album ID.

get_album_by_barcode_id

Album API > Get album by barcode ID: Retrieve a list of album details by barcode ID.

get_album_items

Album API > Get album items: Retrieve a list of album items (tracks and videos) by TIDAL album ID.

get_albums

Album API > Get multiple albums: Retrieve a list of album details by TIDAL album IDs.

get_artist

Artist API > Get single artist: Retrieve artist details by TIDAL artist ID.

get_artist_albums

Artist API > Get albums by artist: Retrieve a list of albums by TIDAL artist ID.

get_artist_tracks

Track API > Get tracks by artist: Retrieve a list of tracks made by the specified artist.

get_artists

Artist API > Get multiple artists: Retrieve a list of artist details by TIDAL artist IDs.

get_similar_albums

Album API > Get similar albums for the given album: Retrieve a list of albums similar to the given album.

get_similar_artists

Artist API > Get similar artists for the given artist: Retrieve a list of artists similar to the given artist.

get_similar_tracks

Track API > Get similar tracks for the given track: Retrieve a list of tracks similar to the given track.

get_track

Track API > Get single track: Retrieve track details by TIDAL track ID.

get_tracks

Album API > Get multiple tracks: Retrieve a list of track details by TIDAL track IDs.

get_tracks_by_isrc

Track API > Get tracks by ISRC: Retrieve a list of track details by ISRC.

get_video

Video API > Get single video: Retrieve video details by TIDAL video ID.

get_videos

Album API > Get multiple videos: Retrieve a list of video details by TIDAL video IDs.

search

Search API > Search for catalog items: Search for albums, artists, tracks, and videos.

set_access_token

Set the TIDAL API access token.

set_flow

Set the authorization flow.

get_album(album_id: int | str, country_code: str) dict[str, Any][source]#

Album API > Get single album: Retrieve album details by TIDAL album ID.

Parameters:
album_idint or str

TIDAL album ID.

Example: 251380836.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
albumdict

TIDAL catalog information for a single album.

get_album_by_barcode_id(barcode_id: int | str, country_code: str) dict[str, Any][source]#

Album API > Get album by barcode ID: Retrieve a list of album details by barcode ID.

Parameters:
barcode_idint or str

Barcode ID in EAN-13 or UPC-A format.

Example: 196589525444.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
albumdict

TIDAL catalog information for a single album.

get_album_items(album_id: int | str, country_code: str, *, limit: int = None, offset: int = None) dict[str, Any][source]#

Album API > Get album items: Retrieve a list of album items (tracks and videos) by TIDAL album ID.

Parameters:
album_idint or str

TIDAL album ID.

Examples: 251380836.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

limitint, keyword-only, optional

Page size.

Example: 10.

offsetint, keyword-only, optional

Pagination offset (in number of items).

Example: 0.

Returns:
itemsdict

A dictionary containing TIDAL catalog information for tracks and videos in the specified album and metadata for the returned results.

get_albums(album_ids: int | str | list[int | str], country_code: str) list[dict[str, Any]][source]#

Album API > Get multiple albums: Retrieve a list of album details by TIDAL album IDs.

Parameters:
album_idsint, str, or list

TIDAL album ID(s).

Examples: "251380836,275646830" or [251380836, 275646830].

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
albumsdict

A dictionary containing TIDAL catalog information for multiple albums and metadata for the returned results.

get_artist(artist_id: int | str, country_code: str) dict[str, Any][source]#

Artist API > Get single artist: Retrieve artist details by TIDAL artist ID.

Parameters:
artist_idint or str

TIDAL artist ID.

Example: 1566.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
artistdict

TIDAL catalog information for a single artist.

get_artist_albums(artist_id: int | str, country_code: str, *, limit: int = None, offset: int = None) dict[str, Any][source]#

Artist API > Get albums by artist: Retrieve a list of albums by TIDAL artist ID.

Parameters:
artist_idint or str

TIDAL artist ID.

Example: 1566.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

limitint, keyword-only, optional

Page size.

Example: 10.

offsetint, keyword-only, optional

Pagination offset (in number of items).

Example: 0.

Returns:
albumsdict

A dictionary containing TIDAL catalog information for albums by the specified artist and metadata for the returned results.

get_artist_tracks(artist_id: int | str, country_code: str, limit: int = None, offset: int = None) dict[str, Any][source]#

Track API > Get tracks by artist: Retrieve a list of tracks made by the specified artist.

Parameters:
artist_idint or str

TIDAL artist ID.

Example: 1566.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

limitint, keyword-only, optional

Page size.

Example: 10.

offsetint, keyword-only, optional

Pagination offset (in number of items).

Example: 0.

Returns:
tracksdict

A dictionary containing TIDAL catalog information for tracks by the specified artist and metadata for the returned results.

get_artists(artist_ids: int | str | list[int | str], country_code: str) dict[str, Any][source]#

Artist API > Get multiple artists: Retrieve a list of artist details by TIDAL artist IDs.

Parameters:
artist_idsint, str, or list

TIDAL artist ID(s).

Examples: "1566,7804" or [1566, 7804].

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
artistsdict

A dictionary containing TIDAL catalog information for multiple artists and metadata for the returned results.

get_similar_albums(album_id: int | str, country_code: str, *, limit: int = None, offset: int = None) dict[str, Any][source]#

Album API > Get similar albums for the given album: Retrieve a list of albums similar to the given album.

Parameters:
album_idint or str

TIDAL album ID.

Examples: 251380836.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

limitint, keyword-only, optional

Page size.

Example: 10.

offsetint, keyword-only, optional

Pagination offset (in number of items).

Example: 0.

Returns:
album_idsdict

A dictionary containing TIDAL album IDs for similar albums and metadata for the returned results.

get_similar_artists(artist_id: int | str, country_code: str, *, limit: int = None, offset: int = None) dict[str, Any][source]#

Artist API > Get similar artists for the given artist: Retrieve a list of artists similar to the given artist.

Parameters:
artist_idint or str

TIDAL artist ID.

Example: 1566.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

limitint, keyword-only, optional

Page size.

Example: 10.

offsetint, keyword-only, optional

Pagination offset (in number of items).

Example: 0.

Returns:
artist_idsdict

A dictionary containing TIDAL artist IDs for similar albums and metadata for the returned results.

get_similar_tracks(track_id: int | str, country_code: str, *, limit: int = None, offset: int = None) dict[str, Any][source]#

Track API > Get similar tracks for the given track: Retrieve a list of tracks similar to the given track.

Parameters:
track_idint or str

TIDAL track ID.

Example: 251380837.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

limitint, keyword-only, optional

Page size.

Example: 10.

offsetint, keyword-only, optional

Pagination offset (in number of items).

Example: 0.

Returns:
track_idsdict

A dictionary containing TIDAL track IDs for similar albums and metadata for the returned results.

get_track(track_id: int | str, country_code: str) dict[str, Any][source]#

Track API > Get single track: Retrieve track details by TIDAL track ID.

Parameters:
track_idint or str

TIDAL track ID.

Example: 251380837.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
trackdict

TIDAL catalog information for a single track.

get_tracks(track_ids: int | str | list[int | str], country_code: str) dict[str, Any][source]#

Album API > Get multiple tracks: Retrieve a list of track details by TIDAL track IDs.

Parameters:
track_idsint, str, or list

TIDAL track ID(s).

Examples: "251380837,251380838" or [251380837, 251380838].

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
tracksdict

A dictionary containing TIDAL catalog information for multiple tracks and metadata for the returned results.

get_tracks_by_isrc(isrc: str, country_code: str, limit: int = None, offset: int = None) dict[str, Any][source]#

Track API > Get tracks by ISRC: Retrieve a list of track details by ISRC.

Parameters:
isrcstr

Valid ISRC code (usually comprises 12 alphanumeric characters).

Example: "USSM12209515".

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

limitint, optional

Page size.

Example: 10.

offsetint, optional

Pagination offset (in number of items).

Example: 0.

Returns:
tracksdict

A dictionary containing TIDAL catalog information for tracks with the specified ISRC and metadata for the returned results.

get_video(video_id: int | str, country_code: str) dict[str, Any][source]#

Video API > Get single video: Retrieve video details by TIDAL video ID.

Parameters:
video_idint or str

TIDAL video ID.

Example: 75623239.

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
videodict

TIDAL catalog information for a single video.

get_videos(video_ids: int | str | list[int | str], country_code: str) list[dict[str, Any]][source]#

Album API > Get multiple videos: Retrieve a list of video details by TIDAL video IDs.

Parameters:
video_idsint, str, or list

TIDAL video ID(s).

Examples: "59727844,75623239" or [59727844, 75623239].

country_codestr

ISO 3166-1 alpha-2 country code.

Example: "US".

Returns:
videosdict

A dictionary containing TIDAL catalog information for multiple videos and metadata for the returned results.

search(query: str, country_code: str, *, type: str = None, limit: int = None, offset: int = None, popularity: str = None) dict[str, list[dict[str, Any]]][source]#

Search API > Search for catalog items: Search for albums, artists, tracks, and videos.

Parameters:
querystr

Search query.

Example: "Beyoncé".

country_code: `str`

ISO 3166-1 alpha-2 country code.

Example: "US".

typestr, keyword-only, optional

Target search type. Searches for all types if not specified.

Valid values: "ALBUMS", "ARTISTS", "TRACKS", "VIDEOS".

limitint, keyword-only, optional

Page size.

Example: 10.

offsetint, keyword-only, optional

Pagination offset (in number of items).

Example: 0.

popularitystr, keyword-only, optional

Specify which popularity type to apply for query result. "WORLDWIDE" is used if not specified.

Valid values: "WORLDWIDE" or "COUNTRY".

Returns:
resultsdict

A dictionary containing TIDAL catalog information for albums, artists, tracks, and videos matching the search query, and metadata for the returned results.

set_access_token(access_token: str = None, *, expiry: str | datetime = None) None[source]#

Set the TIDAL API access token.

Parameters:
access_tokenstr, optional

Access token. If not provided, an access token is obtained using an OAuth 2.0 authorization flow.

expirystr or datetime.datetime, keyword-only, optional

Access token expiry timestamp in the ISO 8601 format %Y-%m-%dT%H:%M:%SZ. If provided, the user will be reauthenticated using the default authorization flow (if possible) when access_token expires.

set_flow(flow: str, *, client_id: str = None, client_secret: str = None, save: bool = True) None[source]#

Set the authorization flow.

Parameters:
flowstr

Authorization flow.

Valid values:

  • "client_credentials" for the client credentials flow.

client_idstr, keyword-only, optional

Client ID. Required for all authorization flows.

client_secretstr, keyword-only, optional

Client secret. Required for all authorization flows.

savebool, keyword-only, default: True

Determines whether to save the newly obtained access tokens and their associated properties to the Minim configuration file.