mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #652] Dumping improvement ideas for spotipy version 3 #385
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#385
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @stephanebruckert on GitHub (Mar 4, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/652
Let's start thinking of the next major version for spotipy, while we keep maintaining the version 2.
spotipy's philosophy for v3 remains the same:
Light weight means we keep it simple and let developers parse the JSON results themselves, as we trust that the Spotify API is backward-compatible.
v3 PRs and issues can use the label:
To do in version 3:
oauth2.pywhich confusingly includes non-oauth2 flows -> we could have an "auth" folder and a file for each authentication flowValueErrorexceptions heregithub.com/spotipy-dev/spotipy@b1db0b63d9 (diff-952bb1443c)Feel free to suggest anything that you believe could improve spotipy in the long term. Independent issues / PRs can still be created and referenced in this discussion.
Development process
Here is a first suggestion, and can be improved:
v3branch exists, so v3 PRs are welcome now!v3masteras usualmasterontov3while making sure it doesn't include any of the things we don't want in v3There is no rush, this will take the time it needs. Any suggestion is welcome! Thank you
@Peter-Schorn commented on GitHub (Mar 5, 2021):
I've noticed that the initializer for
Spotifyhas three parameters that all alias each other:client_credentials_manager,oauth_manager, andauth_manager. We should remove the first two because they just create confusion.@Peter-Schorn commented on GitHub (Mar 12, 2021):
DONE √ in https://github.com/plamere/spotipy/pull/665
Here's another idea: How about creating an Enum for all of the authorization scopes:
This can be a purely additive change to v3. We can still accept the scopes as a string string or a list of strings.
I see several advantages to an enum:
@stephanebruckert commented on GitHub (Apr 18, 2021):
https://github.com/plamere/spotipy/blob/master/spotipy/cache_handler.py
As we add more and more cache handlers, we would need to split the cache handler file into single files and move them in a folder.
Suggestions:
or:
or:
@Peter-Schorn commented on GitHub (Apr 18, 2021):
I like the first layout the most; it's the simplest. I suggest we use the same structure for the auth managers as well.
@mmattbtw commented on GitHub (Aug 1, 2021):
Maybe add event handlers for when someone skips/plays the next song.
@Peter-Schorn commented on GitHub (Aug 1, 2021):
That's not possible with the web API. All of the endpoints are documented here and spotipy already has a method for every endpoint and every authorization method.
@nleroy917 commented on GitHub (Aug 7, 2021):
Headless authentication has always seemed to be a hot-ticket item
@IdmFoundInHim commented on GitHub (Aug 10, 2021):
I think that some sort of handling/abstraction for Spotify's paging objects should be included because many of the basic endpoint return these paging objects. My guess is that most projects depending on spotipy have to deal with these, which requires making manual HTTP requests. This lies on the border of "let developers parse JSON results themselves" and the Spotify API itself; The object has to be parsed to deduce if another request is needed, but to make that request you need the auth token. If spotipy is supposed to work out of the box, this feature is necessary for many basic endpoints. A dependent package otherwise must
import requestsand do the extra work of integrating spotipy functions with those requests.In my experience, the best way to deal with these is to convert them to a more Pythonic iterable — namely, a generator. Because it uses lazy evaluation, it keeps the memory advantages of a paging object yet can be easily converted to a list if resources are available in excess.
The most aggressive solution would be to modify the return values of endpoints that include paging objects (e.g.
Spotify.playlist_items), replacing each JSON object that has a 'next' attribute with a generator. This would create a full abstraction layer, making it easy for someone unfamiliar with the API to use spotipy. However, it eliminates the convenient 'total' attribute and results in a dict that cannot be trivially converted back to portable JSON. Alternatively, we could include this functionality as an option in relevant endpoints (as_generator=Trueor something similar). That could be done in spotipy 2 (default is paging object) or 3 (default is generator).Another solution, which may be fully backwards compatible, is adding a function to the
Spotifyclass or the auth manager classes. This function would take a paging object and return a generator. I have a specialized implementation of this in my own project, and could enhance it for inclusion if this is the desired solution.@IdmFoundInHim commented on GitHub (Aug 18, 2021):
For the endpoints that limit input to 50 or 100 items, spotipy should accept any amount of input, breaking it up into smaller requests internally. Currently, devs using spotipy have to implement this themselves if their programs have any chance of exceeding the limit.
@nleroy917 commented on GitHub (Aug 18, 2021):
@IdmFoundInHim I agree that the paging aspect of the API can be a bit of a nuisance... but I feel like the
.next()method ofspotipyalready makes this so easy. This is some code I use regularly to iterate over paged objects:Maybe on methods/functions that can potentially lead to pagination, add a
page_items=Trueflag and it conducts the above code for you?I also agree an internal "grouping algorithm," would be great since some endpoints only accept a certain number of
ids. I always have to write this myself in order to achieve seamless use.@Peter-Schorn commented on GitHub (Aug 18, 2021):
Perhaps we should have an
extendmethod which, similar tonext, accepts a page of results and then requests all additional pages.@nleroy917 commented on GitHub (Aug 18, 2021):
Wouldn't that pretty much render
nextobsolete? I feel like most would just opt forextend. Maybe you could add a flag to thenextmethod:I think here you prevent the user from accessing other data in that
pageobject. I guess, however, that is their choice if they elect to use anextendmethod or anextend=Trueflag.... if I understand correctly here.
@Peter-Schorn commented on GitHub (Aug 18, 2021):
Some people need fine-grained control over when and which pages to retrieve (think of an infinitely-scrolling list), so
nextshould not be rendered obsolete if we add theextendmethod. Further, the wordnextimplies that only a single additional page will be retrieved, so adding anall_pagesparameter to it seems weird. Instead, it should be a separate method:@IdmFoundInHim commented on GitHub (Aug 18, 2021):
I actually wasn't aware of
Spotify.next, but shouldn't we be making the objects compatible with the Python builtins instead of duplicating them? It would be intuitive fornext(Spotify.playlist_items(...))to return the next playlist item, rather than a paging object.Converting to an iterator would take care of both use cases (controlled or mass retrieval), and would avoid loading unnecessarily large objects into memory.
This would allow you to do:
...as well as...
@timrae commented on GitHub (Apr 5, 2023):
Use
aiohttpand enable Async/await in the spotipy interface@hansmbakker commented on GitHub (Sep 9, 2023):
There is a request for allowing the Device Authorization Grant flow on the Spotify forum - it is very useful for embedded usecases like a remote control.
@Ousret commented on GitHub (Dec 11, 2023):
Hello there,
You may be interested in https://github.com/jawah/niquests for a transparent upgrade of Requests.
Have async, sync, and multiplexed connection. Support HTTP/2, and 3.
@wallysaurus commented on GitHub (Apr 22, 2024):
has this been updated since? I'm seeing this page on the official website now, although it's in javascript.
https://developer.spotify.com/documentation/web-playback-sdk/reference#events
@stephanebruckert commented on GitHub (Jan 12, 2025):
Following https://github.com/spotipy-dev/spotipy/pull/1171#issuecomment-2508728961, let's add limits to all docstrings in v3
@Peter-Schorn commented on GitHub (Jan 12, 2025):
@wallysaurus This is documentation for the Web Playback SDK, not the Web API. The Web Playback SDK is a client-side only javascript library that only runs in the browser. spotipy only supports the Web API.
@vitinhohhh commented on GitHub (Mar 9, 2025):
https://github.com/spotipy-dev/spotipy/issues/1149#issue-2430410583