Skip to main content

Track Models

The track models represent track data from the Spotify API. Tracks can be embedded in albums and playlists or returned with full details.

SimplifiedTrack

Basic track information embedded in other objects like albums.

Fields

artists
list[SimplifiedArtist]
required
The artists who performed the track. See Artist Models.
available_markets
list[str] | None
A list of ISO 3166-1 alpha-2 country codes where the track is available
disc_number
int
required
The disc number (usually 1 unless the album consists of multiple discs)
duration_ms
int
required
The duration of the track in milliseconds
explicit
bool
required
Whether the track has explicit lyrics
external_urls
ExternalUrls
required
External URLs for this track. See Common Models.
href
str
required
A link to the Web API endpoint providing full details of the track
id
str
required
The Spotify ID for the track
is_playable
bool | None
Whether the track is playable in the current market
linked_from
LinkedFrom | None
Information about the originally requested track when track relinking is applied. See Common Models.
restrictions
Restriction | None
Content restrictions applied to this track. See Common Models.
name
str
required
The name of the track
preview_url
str | None
A URL to a 30-second preview (MP3) of the track, or None if not available
track_number
int
required
The number of the track on the album/disc
type
Literal['track']
required
The object type, always “track”
uri
str
required
The Spotify URI for the track
is_local
bool
required
Whether the track is from a local file

Example JSON

{
  "artists": [
    {
      "external_urls": {
        "spotify": "https://open.spotify.com/artist/xyz789"
      },
      "href": "https://api.spotify.com/v1/artists/xyz789",
      "id": "xyz789",
      "name": "Example Artist",
      "type": "artist",
      "uri": "spotify:artist:xyz789"
    }
  ],
  "available_markets": ["US", "GB", "CA"],
  "disc_number": 1,
  "duration_ms": 234000,
  "explicit": false,
  "external_urls": {
    "spotify": "https://open.spotify.com/track/track123"
  },
  "href": "https://api.spotify.com/v1/tracks/track123",
  "id": "track123",
  "is_playable": true,
  "name": "Example Track",
  "preview_url": "https://p.scdn.co/mp3-preview/track123",
  "track_number": 3,
  "type": "track",
  "uri": "spotify:track:track123",
  "is_local": false
}

Track

Complete track object with album, popularity, and external IDs. Extends SimplifiedTrack.

Additional Fields

album
SimplifiedAlbum
required
The album the track appears on. See Album Models.
external_ids
ExternalIds
required
External identifiers for the track (ISRC). See Common Models.
popularity
int
required
The popularity of the track, between 0 and 100, with 100 being the most popular. Calculated based on total plays and recency.

Example JSON

{
  "id": "track123",
  "name": "Example Track",
  "artists": [
    {
      "id": "xyz789",
      "name": "Example Artist",
      "type": "artist",
      "uri": "spotify:artist:xyz789"
    }
  ],
  "duration_ms": 234000,
  "explicit": false,
  "track_number": 3,
  "disc_number": 1,
  "is_local": false,
  "album": {
    "id": "abc123",
    "name": "Example Album",
    "album_type": "album",
    "total_tracks": 12,
    "release_date": "2023-01-15",
    "images": [
      {
        "url": "https://i.scdn.co/image/abc123",
        "height": 640,
        "width": 640
      }
    ]
  },
  "external_ids": {
    "isrc": "USABC1234567"
  },
  "popularity": 82
}

Model Relationships

Track Model Hierarchy
  • SimplifiedTrack contains basic track information without album details
  • Track extends SimplifiedTrack and includes a SimplifiedAlbum object, external IDs, and popularity
The simplified version is used when tracks are embedded in album responses, while the full Track model is returned from track-specific endpoints and playlist items.

Usage Example

from spotify_sdk.models.track import Track, SimplifiedTrack

# Parse a track from the API response
track = Track(**api_response)

# Access track properties
print(f"Track: {track.name}")
print(f"Artists: {', '.join(a.name for a in track.artists)}")
print(f"Album: {track.album.name}")
print(f"Duration: {track.duration_ms // 1000} seconds")
print(f"Popularity: {track.popularity}/100")

# Check if explicit
if track.explicit:
    print("⚠ Explicit content")

# Check preview availability
if track.preview_url:
    print(f"Preview: {track.preview_url}")
else:
    print("No preview available")

# Get ISRC if available
if track.external_ids.isrc:
    print(f"ISRC: {track.external_ids.isrc}")

Common Use Cases

Build docs developers (and LLMs) love