mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #975] Convert all Spotify response objects to Pydantic models #584
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#584
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 @MrinalJain17 on GitHub (May 13, 2023).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/975
Is your feature request related to a problem? Please describe.
Describe the solution you'd like
All the responses can be represented as Pydantic models. https://docs.pydantic.dev/latest/
Describe alternatives you've considered
I've used Pydantic before, so biased towards the tool. There might be other options, but the core feature request stays the same -- well-structured and validated python objects in favour of raw JSON responses.
Additional context
This can be thought of as a more rigorous version of #695.
@stefanondisponibile commented on GitHub (Jun 1, 2023):
This idea is nice, but I can see how creating (and maintaining) such schemas could be a little bit tedious.
I was trying to figure out if we could get the json schemas somewhere, and create the type hints out of them. This way we'd just have to keep in "sync" with the schemas.
However, the only thing I found were these. The repository seems archived though, does anyone know if there are any fresher ones?
@mase-git commented on GitHub (Jun 3, 2023):
Problem here is the dynamic structure response that changes over time according to the Spotify API changelog. You need to adapt manually every schema and mantains the latest versions with updated schema. This identifies a notable effort spent to contributors.
Unfortunately, Spotify didn't update response schema very well and it's a bit tedious mantains a good schema without occurs in some issues.
@dieser-niko commented on GitHub (Jun 21, 2023):
Even though pydantic and similar approaches probably won't be implemented in spotipy, I just want to leave this OpenAPI specification here: https://developer.spotify.com/reference/web-api/open-api-schema.yaml
Apparently it also has some wrong parts, but I didn't look into it yet.
Found in this community post: https://community.spotify.com/t5/Spotify-for-Developers/OpenApi-Swagger-description-for-the-Web-API/m-p/5329753#messageview_1
@stefanondisponibile commented on GitHub (Jun 21, 2023):
yep, @dieser-niko is right. If that can be of help for @MrinalJain17 or anyone in the future one option is converting that openapi schema to pydantic classes (pydantic docs, datamodel-code-generator). So ideally, you could have a thin layer to convert spotipy's responses to Pydantic objects. IMO this remains overkill to implement and remain in sync, but just in case someone needs it :)