Tracks
Track operations live under client.tracks.
Methods
| Method | Returns | Description |
|---|---|---|
get(id, market=None) |
Track |
Fetch a track by Spotify ID |
get_several(ids, market=None) |
list[Track] |
Fetch multiple tracks (max 20 IDs) |
Examples
import asyncio
from spotify_sdk import AsyncSpotifyClient
async def main() -> None:
async with AsyncSpotifyClient(access_token="your-access-token") as client:
track = await client.tracks.get("3n3Ppam7vgaVa1iaRUc9Lp")
tracks = await client.tracks.get_several(
["3n3Ppam7vgaVa1iaRUc9Lp", "7ouMYWpwJ422jRcDASZB7P"],
)
asyncio.run(main())
API details
The sync client mirrors these methods, minus the await keywords.
Bases: AsyncBaseService
Operations for Spotify tracks.
get(id, market=None)
async
Get a track by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The Spotify ID for the track. |
required |
market
|
str | None
|
An ISO 3166-1 alpha-2 country code for track relinking. |
None
|
Returns:
| Type | Description |
|---|---|
Track
|
The requested track. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If id is empty. |
get_several(ids, market=None)
async
Get multiple tracks by IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
list[str]
|
List of Spotify track IDs. The Spotify API enforces a maximum of 20 IDs per request. |
required |
market
|
str | None
|
An ISO 3166-1 alpha-2 country code for track relinking. |
None
|
Returns:
| Type | Description |
|---|---|
list[Track]
|
List of tracks. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If ids is empty. |