[GH-ISSUE #740] Option to automatically loop through paginated playlists with length more than 100 in spotipy.spotify.playlist() function #448

Closed
opened 2026-02-27 23:22:41 +03:00 by kerem · 1 comment
Owner

Originally created by @AbhishekJavali on GitHub (Nov 7, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/740

Is your feature request related to a problem? Please describe.
With the spotipy.spotify.playlist() function the items or tracks returned by default is limited to 100 and the results are paginated. And there is no way to read further details.

Describe the solution you'd like
Provide a parameter which would take care of looping through the paginated results and return the full playlist items.

Describe alternatives you've considered
An alternate solution that I ended up using is to get the total track number and loop over the results using spotipy.spotify,playlist_items with offsets at steps of 50 (max value allowed by spotify) to get the complete playlist items. Please see the code example below

sp = spotipy.Spotify(access_token)
results = sp.playlist(playlist_id)

total_track_count = results['tracks']['total']
max_limit = 50
offset = 0
remaining_track_count = total_track_count

tracks = []

while remaining_track_count > 0:
    results = sp.playlist_items(playlist_id,limit=max_limit,offset=offset)
    tracks.extend(results['items'])
    offset = offset + max_limit
    remaining_track_count = remaining_track_count - max_limit
Originally created by @AbhishekJavali on GitHub (Nov 7, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/740 **Is your feature request related to a problem? Please describe.** With the spotipy.spotify.playlist() function the items or tracks returned by default is limited to 100 and the results are paginated. And there is no way to read further details. **Describe the solution you'd like** Provide a parameter which would take care of looping through the paginated results and return the full playlist items. **Describe alternatives you've considered** An alternate solution that I ended up using is to get the total track number and loop over the results using spotipy.spotify,playlist_items with offsets at steps of 50 (max value allowed by spotify) to get the complete playlist items. Please see the code example below ``` sp = spotipy.Spotify(access_token) results = sp.playlist(playlist_id) total_track_count = results['tracks']['total'] max_limit = 50 offset = 0 remaining_track_count = total_track_count tracks = [] while remaining_track_count > 0: results = sp.playlist_items(playlist_id,limit=max_limit,offset=offset) tracks.extend(results['items']) offset = offset + max_limit remaining_track_count = remaining_track_count - max_limit ```
kerem 2026-02-27 23:22:41 +03:00
Author
Owner

@stephanebruckert commented on GitHub (Dec 11, 2021):

Won't do for the reason given here https://github.com/plamere/spotipy/pull/751#issuecomment-991626458

However thanks both for raising this!

<!-- gh-comment-id:991626839 --> @stephanebruckert commented on GitHub (Dec 11, 2021): Won't do for the reason given here https://github.com/plamere/spotipy/pull/751#issuecomment-991626458 However thanks both for raising this!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#448
No description provided.