Client
Web API endpoints.
API summary |
|
---|---|
Album information |
|
Artist information |
|
Audiobook information |
|
Spotify featured catalogue |
|
Chapter information |
|
Episode information |
|
Follow artists, playlists and users |
|
Save (like) albums, shows and tracks |
|
Spotify market information |
|
User top listens |
|
Playback operations |
|
Playlist operations |
|
Search functionality |
|
Show information |
|
Track information and analysis |
|
User information |
Each method of the client corresponds to an API call, with some exceptions. Further documentation on endpoints can be viewed in the Web API reference.
import tekore as tk
# Initialise the client
spotify = tk.Spotify(token)
# Call the API
album = spotify.album('3RBULTZJ97bvVzZLpxcB0j')
for track in album.tracks.items:
print(track.track_number, track.name)
Required and optional scopes to call any endpoint can be determined in code.
Endpoints provide required_scope
and optional_scope
attributes which return a Scope
.
A combination of the two is provided in scope
.
They can be accessed via the class itself or its instances.
scope_cls = tk.Spotify.current_user_top_tracks.scope
scope_inst = tk.Spotify().current_user_top_tracks.scope
assert scope_cls == scope_inst
- class tekore.Spotify(token=None, sender=None, asynchronous=None, max_limits_on=False, chunked_on=False)
Bases:
tekore.Client
.Client to Web API endpoints.
- Parameters:
token – bearer token for requests
sender (Sender | None) – request sender
asynchronous (bool | None) – synchronicity requirement
max_limits_on (bool) – use maximum limits in paging calls, overrided by endpoint arguments
chunked_on (bool) – use chunking when requesting lists of resources
- token
bearer token for requests
- sender
underlying sender
- max_limits_on
use maximum limits in paging calls, overrided by endpoint arguments
- chunked_on
use chunking when requesting lists of resources
Non-endpoint methods
Toggle chunking lists of resources. |
|
Toggle using maximum limits in paging calls. |
|
Use a different token with requests. |
|
Follow redirect of a short link to get the underlying resource URL. |
|
Determine if URL is a Spotify short link. |
|
Build request url and headers, and send with underlying sender. |
|
Close the underlying sender. |
- Spotify.chunked(on=True)
Toggle chunking lists of resources. Context manager, async safe.
- Parameters:
on (bool) – enable or disable chunking
- Returns:
self as context
- Return type:
Generator[Spotify, None, None]
Examples
spotify = Spotify(token) with spotify.chunked(True): tracks = spotify.tracks(many_ids) spotify = Spotify(token, chunked_on=True) with spotify.chunked(False): tracks = spotify.search(many_ids[:50])
- Spotify.max_limits(on=True)
Toggle using maximum limits in paging calls. Context manager, async safe.
- Parameters:
on (bool) – enable or disable using maximum limits
- Returns:
self as context
- Return type:
Generator[Spotify, None, None]
Examples
spotify = Spotify(token) with spotify.max_limits(True): tracks, = spotify.search('piano') spotify = Spotify(token, max_limits_on=True) with spotify.max_limits(False): tracks, = spotify.search('piano')
- Spotify.token_as(token)
Use a different token with requests. Context manager, async safe.
- Parameters:
token – access token
- Returns:
self as context
- Return type:
Generator[Spotify, None, None]
Examples
spotify = Spotify() with spotify.token_as(token): album = spotify.album(album_id) spotify = Spotify(app_token) with spotify.token_as(user_token): user = spotify.current_user()
- Spotify.follow_short_link(link)
Follow redirect of a short link to get the underlying resource URL.
Safely also accept a direct link, request a redirect and return the original URL. Also use the underlying sender for an unauthenticated request.
- Returns:
result of the short link redirect
- Return type:
url
- Parameters:
link (str) –
- tekore.is_short_link(url)
Determine if URL is a Spotify short link.
- Parameters:
url (str) –
- Return type:
bool
- Spotify.send(request)
Build request url and headers, and send with underlying sender.
Exposed to easily send arbitrary requests, for custom behavior in some endpoint e.g. for a subclass. It may also come in handy if a bugfix or a feature is not implemented in a timely manner, or in debugging related to the client or Web API.
Album API
Get an album. |
|
Get tracks on album. |
|
Get multiple albums. |
- Spotify.album(album_id, market=None)
Get an album.
- Parameters:
album_id (str) – album ID
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
- Return type:
- Spotify.album_tracks(album_id, market=None, limit=20, offset=0)
Get tracks on album.
- Parameters:
album_id (str) – album ID
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
Artist API
Get information for an artist. |
|
Get an artist's albums. |
|
Get artists similar to an identified artist. |
|
Get an artist's top 10 tracks by country. |
|
Get information for multiple artists. |
- Spotify.artist(artist_id)
Get information for an artist.
- Parameters:
artist_id (str) – artist ID
- Return type:
- Spotify.artist_albums(artist_id, include_groups=None, market=None, limit=20, offset=0)
Get an artist’s albums.
- Parameters:
artist_id (str) – the artist ID
include_groups (list[str | AlbumGroup] | None) – album groups to include in the response
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
Get artists similar to an identified artist.
Warning
This endpoint is unavailable to new third-party applications (#331)
Similarity is based on analysis of the Spotify community’s listening history.
- Parameters:
artist_id (str) – artist ID
- Return type:
list[FullArtist]
- Spotify.artist_top_tracks(artist_id, market)
Get an artist’s top 10 tracks by country.
- Parameters:
artist_id (str) – the artist ID
market (str) – an ISO 3166-1 alpha-2 country code or ‘from_token’
- Return type:
list[FullTrack]
- Spotify.artists(artist_ids)
Get information for multiple artists.
- Parameters:
artist_ids (list[str]) – list of artist IDs, max 50 without chunking
- Return type:
list[FullArtist]
Audiobook API
Get information for an audiobook. |
|
Get chapters of an audiobook. |
|
Get information for multiple audiobooks. |
- Spotify.audiobook(audiobook_id, market=None)
Get information for an audiobook.
- Parameters:
audiobook_id (str) – audiobook ID
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the show is considered unavailable.
- Return type:
- Spotify.audiobook_chapters(audiobook_id, market=None, limit=20, offset=0)
Get chapters of an audiobook.
- Parameters:
audiobook_id (str) – audiobook ID
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the show is considered unavailable.
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.audiobooks(audiobook_ids, market=None)
Get information for multiple audiobooks.
- Parameters:
audiobook_ids (list[str]) – the audiobook IDs, max 50 without chunking
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the show is considered unavailable.
- Return type:
list[FullAudiobook]
Browse API
Get a list of categories used to tag items in Spotify. |
|
Get a single category used to tag items in Spotify. |
|
Get a list of Spotify playlists tagged with a particular category. |
|
Get a list of Spotify featured playlists. |
|
Get a list of new album releases featured in Spotify. |
|
Get a list of available genre seeds. |
|
Get a list of recommended tracks for seeds. |
- Spotify.categories(country=None, locale=None, limit=20, offset=0)
Get a list of categories used to tag items in Spotify.
- Parameters:
country (str | None) – an ISO 3166-1 alpha-2 country code
locale (str | None) – the desired language, consisting of a lowercase ISO 639 language code and an uppercase ISO 3166-1 alpha-2 country code joined by an underscore
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.category(category_id, country=None, locale=None)
Get a single category used to tag items in Spotify.
- Parameters:
category_id (str) – category ID
country (str | None) – an ISO 3166-1 alpha-2 country code
locale (str | None) – the desired language, consisting of a lowercase ISO 639 language code and an uppercase ISO 3166-1 alpha-2 country code joined by an underscore
- Return type:
- Spotify.category_playlists(category_id, country=None, limit=20, offset=0)
Get a list of Spotify playlists tagged with a particular category.
Warning
This endpoint is unavailable to new third-party applications (#331)
- Parameters:
category_id (str) – category ID
country (str | None) – an ISO 3166-1 alpha-2 country code
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.featured_playlists(country=None, locale=None, timestamp=None, limit=20, offset=0)
Get a list of Spotify featured playlists.
Warning
This endpoint is unavailable to new third-party applications (#331)
- Parameters:
country (str | None) – an ISO 3166-1 alpha-2 country code
locale (str | None) – the desired language, consisting of a lowercase ISO 639 language code and an uppercase ISO 3166-1 alpha-2 country code joined by an underscore
timestamp (str | None) – Timestamp in ISO 8601 format: yyyy-MM-ddTHH:mm:ss. Used to specify the user’s local time to get results tailored for that specific date and time in the day.
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Returns:
message and playlists
- Return type:
tuple[str, SimplePlaylistPaging]
- Spotify.new_releases(country=None, limit=20, offset=0)
Get a list of new album releases featured in Spotify.
- Parameters:
country (str | None) – an ISO 3166-1 alpha-2 country code
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.recommendation_genre_seeds()
Get a list of available genre seeds.
- Return type:
list[str]
- Spotify.recommendations(artist_ids=None, genres=None, track_ids=None, limit=20, market=None, **attributes)
Get a list of recommended tracks for seeds.
Warning
This endpoint is unavailable to new third-party applications (#331)
Warning
The total number of seeds provided in
artist_ids
,genres
andtrack_ids
must be at least 1 and at most 5.- Parameters:
artist_ids (list[str] | None) – list of seed artist IDs
genres (list[str] | None) – list of seed genre names
track_ids (list[str] | None) – list of seed track IDs
limit (int) – the number of items to return (1..100)
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
attributes – min/max/target_<attribute> - For all tuneable track attributes see
model.RecommendationAttribute
, these values provide filters and targeting on results.
- Raises:
ValueError – if any attribute is not allowed
- Return type:
Chapter API
Get information for a chapter. |
|
Get information for multiple chapters. |
- Spotify.chapter(chapter_id, market=None)
Get information for a chapter.
- Parameters:
chapter_id (str) – chapter ID
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the episode is considered unavailable.
- Return type:
- Spotify.chapters(chapter_ids, market=None)
Get information for multiple chapters.
- Parameters:
chapter_ids (list[str]) – the chapter IDs, max 50 without chunking
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the episode is considered unavailable.
- Return type:
list[FullChapter]
Episode API
Get information for an episode. |
|
Get information for multiple episodes. |
- Spotify.episode(episode_id, market=None)
Get information for an episode.
- Parameters:
episode_id (str) – episode ID
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the episode is considered unavailable.
- Return type:
- Spotify.episodes(episode_ids, market=None)
Get information for multiple episodes.
- Parameters:
episode_ids (list[str]) – the episode IDs, max 50 without chunking
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the episode is considered unavailable.
- Return type:
list[FullEpisode]
Follow API
Follow artists as current user. |
|
Check if current user follows artists. |
|
Unfollow artists as current user. |
|
Get artists followed by the current user. |
|
Follow a playlist as current user. |
|
Check if users are following a playlist. |
|
Unfollow a playlist as current user. |
|
Get a list of the playlists owned or followed by the current user. |
|
Follow users as current user. |
|
Check if current user follows users. |
|
Unfollow users as current user. |
- Spotify.artists_follow(artist_ids)
Follow artists as current user.
- Parameters:
artist_ids (list[str]) – list of artist IDs, max 50 without chunking
- Return type:
None
- Spotify.artists_is_following(artist_ids)
Check if current user follows artists.
- Parameters:
artist_ids (list[str]) – list of artist IDs, max 50 without chunking
- Returns:
follow statuses in the same order that the artist IDs were given
- Return type:
list[bool]
- Spotify.artists_unfollow(artist_ids)
Unfollow artists as current user.
- Parameters:
artist_ids (list[str]) – list of artist IDs, max 50 without chunking
- Return type:
None
- Spotify.followed_artists(limit=20, after=None)
Get artists followed by the current user.
- Parameters:
limit (int) – the number of items to return (1..50)
after (str | None) – the last artist ID retrieved from the previous request
- Return type:
- Spotify.playlist_follow(playlist_id, public=True)
Follow a playlist as current user.
- Parameters:
playlist_id (str) – playlist ID
public (bool) – follow publicly
- Return type:
None
- Spotify.playlist_is_following(playlist_id, user_ids)
Check if users are following a playlist.
- Parameters:
playlist_id (str) – playlist ID
user_ids (list[str]) – list of user IDs, max 5 without chunking
- Returns:
follow statuses in the same order that the user IDs were given
- Return type:
list[bool]
- Spotify.playlist_unfollow(playlist_id)
Unfollow a playlist as current user.
- Parameters:
playlist_id (str) – playlist ID
- Return type:
None
- Spotify.followed_playlists(limit=20, offset=0)
Get a list of the playlists owned or followed by the current user.
- Parameters:
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.users_follow(user_ids)
Follow users as current user.
- Parameters:
user_ids (list[str]) – list of user IDs, max 50 without chunking
- Return type:
None
- Spotify.users_is_following(user_ids)
Check if current user follows users.
- Parameters:
user_ids (list[str]) – list of user IDs, max 50 without chunking
- Returns:
follow statuses in the same order that the user IDs were given
- Return type:
list[bool]
- Spotify.users_unfollow(user_ids)
Unfollow users as current user.
- Parameters:
user_ids (list[str]) – list of user IDs, max 50 without chunking
- Return type:
None
Library API
Get the albums saved in the current user's library. |
|
Save albums for current user. |
|
Check if user has saved albums. |
|
Remove albums for current user. |
|
Get the episodes saved in the current user's library. |
|
Save episodes for current user. |
|
Check if user has saved episodes. |
|
Remove episodes for current user. |
|
Get the shows saved in the current user's library. |
|
Save shows for current user. |
|
Check if user has saved shows. |
|
Remove shows for current user. |
|
Get the songs saved in the current user's library. |
|
Save tracks for current user. |
|
Check if user has saved tracks. |
|
Remove tracks for current user. |
- Spotify.saved_albums(market=None, limit=20, offset=0)
Get the albums saved in the current user’s library.
- Parameters:
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.saved_albums_add(album_ids)
Save albums for current user.
- Parameters:
album_ids (list[str]) – list of album IDs, max 50 without chunking
- Return type:
None
- Spotify.saved_albums_contains(album_ids)
Check if user has saved albums.
- Parameters:
album_ids (list[str]) – list of album IDs, max 50 without chunking
- Returns:
save statuses in the same order the album IDs were given
- Return type:
list[bool]
- Spotify.saved_albums_delete(album_ids)
Remove albums for current user.
- Parameters:
album_ids (list[str]) – list of album IDs, max 50 without chunking
- Return type:
None
- Spotify.saved_episodes(market=None, limit=20, offset=0)
Get the episodes saved in the current user’s library.
- Parameters:
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.saved_episodes_add(episode_ids)
Save episodes for current user.
- Parameters:
episode_ids (list[str]) – list of episode IDs, max 50 without chunking
- Return type:
None
- Spotify.saved_episodes_contains(episode_ids)
Check if user has saved episodes.
- Parameters:
episode_ids (list[str]) – list of episode IDs, max 50 without chunking
- Returns:
save statuses in the same order the episode IDs were given
- Return type:
list[bool]
- Spotify.saved_episodes_delete(episode_ids)
Remove episodes for current user.
- Parameters:
episode_ids (list[str]) – list of episode IDs, max 50 without chunking
- Return type:
None
- Spotify.saved_shows(market=None, limit=20, offset=0)
Get the shows saved in the current user’s library.
- Parameters:
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.saved_shows_add(show_ids)
Save shows for current user.
- Parameters:
show_ids (list[str]) – list of show IDs, max 50 without chunking
- Return type:
None
- Spotify.saved_shows_contains(show_ids)
Check if user has saved shows.
- Parameters:
show_ids (list[str]) – list of show IDs, max 50 without chunking
- Returns:
save statuses in the same order the show IDs were given
- Return type:
list[bool]
- Spotify.saved_shows_delete(show_ids, market=None)
Remove shows for current user.
- Parameters:
show_ids (list[str]) – list of show IDs, max 50 without chunking
market (str | None) – an ISO 3166-1 alpha-2 country code, only remove shows that are available in the specified market, overrided by token’s country
- Return type:
None
- Spotify.saved_tracks(market=None, limit=20, offset=0)
Get the songs saved in the current user’s library.
- Parameters:
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.saved_tracks_add(track_ids)
Save tracks for current user.
- Parameters:
track_ids (list[str]) – list of track IDs, max 50 without chunking
- Return type:
None
- Spotify.saved_tracks_contains(track_ids)
Check if user has saved tracks.
- Parameters:
track_ids (list[str]) – list of track IDs, max 50 without chunking
- Returns:
save statuses in the same order the track IDs were given
- Return type:
list[bool]
- Spotify.saved_tracks_delete(track_ids)
Remove tracks for current user.
- Parameters:
track_ids (list[str]) – list of track IDs, max 50 without chunking
- Return type:
None
Markets API
Get available market country codes. |
- Spotify.markets()
Get available market country codes.
- Returns:
available markets
- Return type:
list[str]
Personalisation API
Get the current user's top artists. |
|
Get the current user's top tracks. |
- Spotify.current_user_top_artists(time_range='medium_term', limit=20, offset=0)
Get the current user’s top artists.
- Parameters:
time_range (str) – Over what time frame are the affinities computed. Valid-values: short_term, medium_term, long_term
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.current_user_top_tracks(time_range='medium_term', limit=20, offset=0)
Get the current user’s top tracks.
- Parameters:
time_range (str) – Over what time frame are the affinities computed. Valid-values: short_term, medium_term, long_term
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
Player API
Get information about user's current playback. |
|
Get user's currently playing track. |
|
Get a user's available devices. |
|
Skip user's playback to next track. |
|
Pause a user's playback. |
|
Skip user's playback to previous track. |
|
Get items in a user's queue. |
|
Add a track or an episode to a user's queue. |
|
Get tracks from the current user's recently played tracks. |
|
Set repeat mode for playback. |
|
Resume user's playback. |
|
Seek to position in current playing track. |
|
Toggle shuffle for user's playback. |
|
Start playback of a context: an album, artist or playlist. |
|
Start playback of one or more tracks. |
|
Transfer playback to another device. |
|
Set volume for user's playback. |
- Spotify.playback(market=None, tracks_only=False)
Get information about user’s current playback.
- Parameters:
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
tracks_only (bool) – return only tracks in the currently playing item, if True, episodes have None as the currently playing item
- Returns:
information about current playback
- Return type:
- Spotify.playback_currently_playing(market=None, tracks_only=False)
Get user’s currently playing track.
Requiredscope
: user-read-currently-playing user-read-playback-stateOptionalscope
: user-read-currently-playing user-read-playback-stateOnly one of the scopes above is required.
- Parameters:
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
tracks_only (bool) – return only tracks in the currently playing item, if True, episodes have None as the currently playing item
- Returns:
information about the current track playing
- Return type:
- Spotify.playback_next(device_id=None)
Skip user’s playback to next track.
- Parameters:
device_id (str | None) – device to skip track on
- Return type:
None
- Spotify.playback_pause(device_id=None)
Pause a user’s playback.
- Parameters:
device_id (str | None) – device to pause playback on
- Return type:
None
- Spotify.playback_previous(device_id=None)
Skip user’s playback to previous track.
- Parameters:
device_id (str | None) – device to skip track on
- Return type:
None
- Spotify.playback_queue()
Get items in a user’s queue.
The result also include items in the current playback context even though they are not explicitly in the queue. The number of items in the queue is inconsistent, but from manual experimentation at least two items are returned.
- Return type:
- Spotify.playback_queue_add(uri, device_id=None)
Add a track or an episode to a user’s queue.
- Parameters:
uri (str) – resource to add, track or episode
device_id (str | None) – devide to extend the queue on
- Return type:
None
- Spotify.playback_recently_played(limit=20, after=None, before=None)
Get tracks from the current user’s recently played tracks.
Only
after
orbefore
should be specified at one time.- Parameters:
limit (int) – the number of items to return (1..50)
after (int | None) – a unix timestamp in milliseconds, must not be specified with ‘before’
before (int | None) – a unix timestamp in milliseconds, must not be specified with ‘after’
- Return type:
- Spotify.playback_repeat(state, device_id=None)
Set repeat mode for playback.
- Parameters:
state (str | RepeatState) – track, context, or off
device_id (str | None) – device to set repeat on
- Return type:
None
- Spotify.playback_resume(device_id=None)
Resume user’s playback.
- Parameters:
device_id (str | None) – device to start playback on
- Return type:
None
- Spotify.playback_seek(position_ms, device_id=None)
Seek to position in current playing track.
- Parameters:
position_ms (int) – position on track
device_id (str | None) – device to seek on
- Return type:
None
- Spotify.playback_shuffle(state, device_id=None)
Toggle shuffle for user’s playback.
- Parameters:
state (bool) – shuffle state
device_id (str | None) – device to toggle shuffle on
- Return type:
None
- Spotify.playback_start_context(context_uri, offset=None, position_ms=None, device_id=None)
Start playback of a context: an album, artist or playlist.
- Parameters:
context_uri (str) – context to start playing
offset (int | str | None) – offset into context by index or track ID, only available when context is an album or playlist
position_ms (int | None) – initial position of first played track
device_id (str | None) – device to start playback on
- Return type:
None
- Spotify.playback_start_tracks(track_ids, offset=None, position_ms=None, device_id=None)
Start playback of one or more tracks.
- Parameters:
track_ids (list[str]) – track IDs to start playing
offset (int | str | None) – offset into tracks by index or track ID
position_ms (int | None) – initial position of first played track
device_id (str | None) – device to start playback on
- Return type:
None
- Spotify.playback_transfer(device_id, force_play=False)
Transfer playback to another device.
- Parameters:
device_id (str) – device to transfer playback to
force_play (bool) – true: play after transfer, false: keep current state
- Return type:
None
- Spotify.playback_volume(volume_percent, device_id=None)
Set volume for user’s playback.
- Parameters:
volume_percent (int) – volume to set (0..100)
device_id (str | None) – device to set volume on
- Return type:
None
Playlist API
Get playlist of a user. |
|
Get a list of the playlists owned or followed by a user. |
|
Create a playlist. |
|
Change a playlist's details. |
|
Get cover image of a playlist. |
|
Upload a custom playlist cover image. |
|
Full details of items on a playlist. |
|
Add items. |
|
Remove all items. |
|
Remove items by URI. |
|
Reorder items. |
|
Replace all items. |
See Spotify’s guide on working with playlists for additional information.
- Spotify.playlist(playlist_id, fields=None, market=None, as_tracks=False)
Get playlist of a user.
Note
Returns a dictionary if
fields
oras_tracks
is specified.- Parameters:
playlist_id (str) – playlist ID
fields (str | None) – which fields to return, see the Web API documentation for details
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’ when using a user token to authenticate. For episodes in the playlist, if a user token is used, the country associated with it overrides this parameter. If an application token is used and no market is specified, episodes are considered unavailable and returned as None.
as_tracks (bool | Iterable[str]) – return types of items with track-like fields. If
True
, return all other types as tracks. If an iterable is passed, types contained are returned as tracks. Currently the only extra type isepisode
.
- Returns:
playlist object, or raw dictionary if
fields
oras_tracks
was specified- Return type:
FullPlaylist | dict
- Spotify.playlists(user_id, limit=20, offset=0)
Get a list of the playlists owned or followed by a user.
Collaborative playlists are only returned for the current user.
- Parameters:
user_id (str) – user ID
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.playlist_create(user_id, name, public=True, description='')
Create a playlist.
- Parameters:
user_id (str) – user ID
name (str) – the name of the playlist
public (bool) – is the created playlist public
description (str) – the description of the playlist
- Return type:
- Spotify.playlist_change_details(playlist_id, name=None, public=None, collaborative=None, description=None)
Change a playlist’s details.
- Parameters:
playlist_id (str) – playlist ID
name (str | None) – name of the playlist
public (bool | None) – is the playlist public
collaborative (bool | None) – is the playlist collaborative
description (str | None) – description of the playlist
- Return type:
None
- Spotify.playlist_cover_image(playlist_id)
Get cover image of a playlist.
Note
Returns a list of images.
- Parameters:
playlist_id (str) – playlist ID
- Return type:
list[Image]
- Spotify.playlist_cover_image_upload(playlist_id, image)
Upload a custom playlist cover image.
- Parameters:
playlist_id (str) – playlist ID
image (str) – image data as a base64-encoded string
- Return type:
None
- Spotify.playlist_items(playlist_id, fields=None, market=None, as_tracks=False, limit=100, offset=0)
Full details of items on a playlist.
Note
Returns a dictionary if
fields
oras_tracks
is specified.- Parameters:
playlist_id (str) – playlist ID
fields (str | None) – which fields to return, see the Web API documentation for details
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’ when using a user token to authenticate. For episodes in the playlist, if a user token is used, the country associated with it overrides this parameter. If an application token is used and no market is specified, episodes are considered unavailable and returned as None.
as_tracks (bool | Iterable[str]) – return types of items with track-like fields. If
True
, return all other types as tracks. If an iterable is passed, types contained are returned as tracks. Currently the only extra type isepisode
.limit (int) – the number of items to return (1..100)
offset (int) – the index of the first item to return
- Returns:
paging object containing playlist items, or raw dictionary if
fields
oras_tracks
was specified- Return type:
PlaylistTrackPaging | dict
- Spotify.playlist_add(playlist_id, uris, position=None)
Add items.
- Parameters:
playlist_id (str) – playlist ID
uris (list[str]) – list of URIs, max 100 without chunking
position (int | None) – index to insert the items in
- Returns:
snapshot ID for the playlist
- Return type:
str
- Spotify.playlist_clear(playlist_id)
Remove all items.
- Parameters:
playlist_id (str) – playlist ID
- Return type:
None
- Spotify.playlist_remove(playlist_id, uris, snapshot_id=None)
Remove items by URI.
Removes all occurrences of the specified items. Note that when chunked,
snapshot_id
is not updated between requests.- Parameters:
playlist_id (str) – playlist ID
uris (list[str]) – list of URIs, max 100 without chunking
snapshot_id (str | None) – snapshot ID for the playlist
- Returns:
snapshot ID for the playlist
- Return type:
str
- Spotify.playlist_reorder(playlist_id, range_start, insert_before, range_length=1, snapshot_id=None)
Reorder items.
- Parameters:
playlist_id (str) – playlist ID
range_start (int) – position of the first item to be reordered
range_length (int) – number of items to be reordered
insert_before (int) – position where the items should be inserted
snapshot_id (str | None) – snapshot ID for the playlist
- Returns:
snapshot ID for the playlist
- Return type:
str
- Spotify.playlist_replace(playlist_id, uris)
Replace all items.
- Parameters:
playlist_id (str) – playlist ID
uris (list[str]) – list of URIs, max 100
- Return type:
None
Search API
- Spotify.search(query, types=('track',), market=None, include_external=None, limit=20, offset=0)
Search for an item.
Returns
NotFound
if limit+offset would be above 1000.- Parameters:
query (str) – search query
types (tuple) – resources to search for, tuple of strings containing artist, album, audiobook, track, playlist, show and/or episode
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
include_external (str | None) – if ‘audio’, response will include any externally hosted audio
- Returns:
Paging objects containing the types of items searched for in the order that they were specified in ‘types’.
artist:
FullArtistOffsetPaging
album:
SimpleAlbumPaging
audiobook:
SimpleAudiobookPaging
episode:
SimpleEpisodePaging
playlist:
SimplePlaylistPaging
show:
SimpleShowPaging
track:
FullTrackPaging
- Return type:
tuple
Examples
tracks, = spotify.search('monty python') artists, = spotify.search('sheeran', types=('artist',)) albums, tracks = spotify.search('piano', types=('album', 'track')) spotify.search('gold album:boba artist:abba', types=('track',)) spotify.search('bob year:1980-2020', types=('show',))
Note
You can narrow down search results by specifying field filters (e.g. year range, genre). See the Search for an Item page of the official documentation for more information.
Show API
Get information for a show. |
|
Get episodes of a show. |
|
Get information for multiple shows. |
- Spotify.show(show_id, market=None)
Get information for a show.
The user-read-playback-position scope allows episode resume points to be returned.
- Parameters:
show_id (str) – show ID
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the show is considered unavailable.
- Return type:
- Spotify.show_episodes(show_id, market=None, limit=20, offset=0)
Get episodes of a show.
- Parameters:
show_id (str) – show ID
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the show is considered unavailable.
limit (int) – the number of items to return (1..50)
offset (int) – the index of the first item to return
- Return type:
- Spotify.shows(show_ids, market=None)
Get information for multiple shows.
The user-read-playback-position scope allows episode resume points to be returned.
- Parameters:
show_ids (list[str]) – the show IDs, max 50 without chunking
market (str | None) – an ISO 3166-1 alpha-2 country code. If a user token is used to authenticate, the country associated with it overrides this parameter. If an application token is used and no market is specified, the show is considered unavailable.
- Return type:
list[FullShow]
Track API
Get information for a track. |
|
Get a detailed audio analysis for a track. |
|
Get audio feature information for a track. |
|
Get information for multiple tracks. |
|
Get audio feature information for multiple tracks. |
- Spotify.track(track_id, market=None)
Get information for a track.
- Parameters:
track_id (str) – track ID
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
- Return type:
- Spotify.track_audio_analysis(track_id)
Get a detailed audio analysis for a track.
Warning
This endpoint is unavailable to new third-party applications (#331)
The analysis describes the track’s structure and musical content, including rythm, pitch and timbre.
- Parameters:
track_id (str) –
- Return type:
- Spotify.track_audio_features(track_id)
Get audio feature information for a track.
Warning
This endpoint is unavailable to new third-party applications (#331)
- Parameters:
track_id (str) –
- Return type:
- Spotify.tracks(track_ids, market=None)
Get information for multiple tracks.
- Parameters:
track_ids (list[str]) – the track IDs, max 50 without chunking
market (str | None) – an ISO 3166-1 alpha-2 country code or ‘from_token’
- Return type:
list[FullTrack]
- Spotify.tracks_audio_features(track_ids)
Get audio feature information for multiple tracks.
Warning
This endpoint is unavailable to new third-party applications (#331)
Feature information for a track may be
None
if not available.- Parameters:
track_ids (list[str]) – track IDs, max 100 without chunking
- Return type:
list[AudioFeatures]
User API
Get current user's profile. |
|
Get a user's profile. |
- Spotify.current_user()
Get current user’s profile.
The user-read-private scope allows the user’s country and product subscription level to be returned.
- Return type:
- Spotify.user(user_id)
Get a user’s profile.
- Parameters:
user_id (str) – user ID
- Return type: