Package: pyfy
Welcome 👋Pyfy is a Sync + Async Pythonic Spotify Client that focuses on ease of use in personal projects and API stability and security for production grade codebases.Setup ⚙️$pipinstallpyfyQuick Start 🎛️Sync:frompyfyimportSpotifyspt=Spotify('your_access_token')spt.play()spt.volume(85)spt.next()spt.pause()Async:importasynciofrompyfyimportAsyncSpotifyspt=AsyncSpotify('your_access_token')asyncdefsearch():returnawaitspt.search('A tout le monde')search_result=asyncio.run(search())Getting Started 👩You should start by creating client credentials from Spotify'sDevelopers consoleNext edit your application's settings and set a Redirect URL. If it's for personal use then set it as:http://localhost:9000Port can be any port of choice, not necessarily 9000Next, copy your:Client IDClient SecretRedirect URL (That you just set)Next, figure out the scopes that you think you'll need from here:https://developer.spotify.com/documentation/general/guides/scopes/e.g.["user-library-modify", "app-remote-control"]Next, follow the first authentication scheme from below (it's the one you'll most likely need, unless you're sure otherwise)Authentication Schemes 👩‍🎤1. Authorization Code Flow (OAuth2) (recommended)Suitable if you want to access user-related resources. e.g. user-playlists, user-tracks etc.Click here for full working examples with Sanic(async) and Flask(sync)frompyfyimportSpotify,ClientCreds,UserCreds,AuthError,ApiErrorclient=ClientCreds(client_id='clientid',client_secret='client_secret',redirect_uri='https://localhost:9000",scopes=["user-library-modify","app-remote-control"])spt=Spotify(client_creds=client)defauthorize():# Fist step of OAuth, Redirect user to spotify's authorization endpointifspt.is_oauth_ready:returnredirect(spt.auth_uri())# Authorization callbackdefcallback(grant):try:user_creds=spt.build_credentials(grant=grant)exceptAuthErrorase:abort(401)logging.info(e.msg)logging.info(e.http_response)else:db.insert(user_creds)returnredirect(url_for_home)defget_user_tracks():try:returnjson.dumps(spt.user_tracks())exceptApiError:abort(500)2. User's Access Tokenget from hereSame as the Authorization Code Flow above but without a refresh token. Suitable for quick runs.frompyfyimportSpotifyspt=Spotify('your access token')3. Client Credentials Flow (OAauth2):Suitable for when you want to access public information quickly. (Accessing user information is porhibited using this method)frompyfyimportClientCreds,Spotifyclient=ClientCreds(client_id=client_id,client_secret=client_secret)spt=Spotify(client_creds=client)spt.authorize_client_creds()API endpoints 🌐Albums:Get an albumPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.albumsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/albums/get-album/Get an album's tracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.album_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/albums/get-albums-tracks/Get several albumsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.albumsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/albums/get-several-albums/Artists:Get an artistPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.artistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/artists/get-artist/Artist albumsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.artist_albumsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/artists/get-artists-albums/Artist top tracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.artist_top_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/artists/get-artists-top-tracks/Artist related artistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.artist_related_artistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/artists/get-related-artists/Get several artistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.artistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/artists/get-several-artists/Browse:Get a categoryPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.categoryWeb API reference:https://developer.spotify.com/documentation/web-api/reference/browse/get-category/Get a category's playlistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.category_playlistWeb API reference:https://developer.spotify.com/documentation/web-api/reference/browse/get-categorys-playlists/Get list of categoriesPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.categoriesWeb API reference:https://developer.spotify.com/documentation/web-api/reference/browse/get-list-categories/Get a list of featured playlistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.featured_playlistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/browse/get-list-featured-playlists/Get a list of new releasesPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.new_releasesWeb API reference:https://developer.spotify.com/documentation/web-api/reference/browse/get-list-new-releases/Get recommendations based on seedsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.recommendationsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/browse/get-recommendations/Episodes:Get an episodePyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/episodes/get-an-episode/Get several episodesPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/episodes/get-several-episodes/Follow:Check if Current User Follows Artists or UsersPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.follows_usersWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/check-current-user-follows/Check if Users Follow a PlaylistPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.follows_playlistWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/check-user-following-playlist/Follow ArtistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.follow_artistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/follow-artists-users/Follow UsersPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.follow_artistsWeb API reference:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.follow_usersFollow a playlistPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.follow_playlistWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/follow-playlist/Get User's Followed ArtistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.followed_artistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/get-followed/Unfollow ArtistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.unfollow_artistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/Unfollow UsersPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.unfollow_usersWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-artists-users/Unfollow PlaylistPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.unfollow_playlistWeb API reference:https://developer.spotify.com/documentation/web-api/reference/follow/unfollow-playlist/User Library:Check User's Saved AlbumsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.owns_albumsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-albums/Check User's Saved ShowsPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/check-users-saved-shows/Check User's Saved TracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.owns_tracksWeb API reference:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.owns_tracksGet Current User's Saved AlbumsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.user_albumsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-albums/Get User's Saved ShowsPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-shows/Get a User's Saved TracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.user_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/get-users-saved-tracks/Remove Albums for Current UserPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.delete_albumsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/remove-albums-user/Remove User's Saved ShowsPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/remove-shows-user/Remove User's Saved TracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.delete_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/remove-tracks-user/Save Albums for Current UserPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.save_albumsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/save-albums-user/Save Shows for Current UserPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/save-shows-user/Save Tracks for UserPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.save_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/library/save-tracks-user/Personalization:Get a User's Top ArtistsPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.user_top_artistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/personalization/get-users-top-artists-and-tracks/Get a User's Top TracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.artist_top_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/personalization/get-users-top-artists-and-tracks/Player:Add an Item to the User's Playback QueuePyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.queueWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/add-to-queue/Get a User's Available DevicesPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.devicesWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/get-a-users-available-devices/Get Information About The User's Current PlaybackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.currently_playing_infoWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/get-information-about-the-users-current-playback/Get Current User's Recently Played TracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.recently_played_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/get-recently-played/Get the User's Currently Playing TrackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.currently_playingWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/get-the-users-currently-playing-track/Pause a User's PlaybackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.pauseWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/pause-a-users-playback/Seek To Position In Currently Playing TrackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.seekWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/seek-to-position-in-currently-playing-track/Set Repeat Mode On User’s PlaybackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.repeatWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/set-repeat-mode-on-users-playback/Set Volume For User's PlaybackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.volumeWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/set-volume-for-users-playback/Skip User’s Playback To Next TrackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.nextWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/skip-users-playback-to-next-track/Skip User’s Playback To Previous TrackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.previousWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/skip-users-playback-to-previous-track/Start/Resume a User's PlaybackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.playWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/start-a-users-playback/Toggle Shuffle For User’s PlaybackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.shuffleWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/toggle-shuffle-for-users-playback/Transfer a User's PlaybackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.playback_transferWeb API reference:https://developer.spotify.com/documentation/web-api/reference/player/transfer-a-users-playback/Playlists:Add playlist items:Docs:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.add_playlist_tracksWeb API Reference:https://developer.spotify.com/documentation/web-api/reference/playlists/add-tracks-to-playlist/Edit playlist:Pyfy:https://developer.spotify.com/documentation/web-api/reference/playlists/change-playlist-details/Web API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/change-playlist-details/Create playlist:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.create_playlistWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/create-playlist/List a user's playlists:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.user_playlistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/get-a-list-of-current-users-playlists/Playlist cover:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.playlist_coverWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist-cover/List a playlist:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.playlistWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/List a playlist items:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.playlist_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlists-tracks/Remove playlist items:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.delete_playlist_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/remove-tracks-playlist/Reorder playlist items:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.reorder_playlist_trackWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/reorder-playlists-tracks/Replace playlist items:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.replace_playlist_tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/replace-playlists-tracks/Upload custom playlist cover image:Pyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/upload-custom-playlist-cover/List current user playlists:Pyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.user_playlistsWeb API reference:https://developer.spotify.com/documentation/web-api/reference/playlists/get-a-list-of-current-users-playlists/Search:Search for an itemPyfy:https://developer.spotify.com/documentation/web-api/reference/search/search/Web API reference:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.searchShows:Get a ShowPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/shows/get-a-show/Get Several ShowsPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/shows/get-several-shows/Get a Show's EpisodesPyfy:TODOWeb API reference:https://developer.spotify.com/documentation/web-api/reference/shows/get-shows-episodes/Tracks:Get Audio Analysis for a TrackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.track_audio_analysisWeb API reference:https://developer.spotify.com/documentation/web-api/reference/tracks/get-audio-analysis/Get Audio Features for a TrackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.tracks_audio_featuresWeb API reference:https://developer.spotify.com/documentation/web-api/reference/tracks/get-audio-features/Get Audio Features for Several TracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.tracks_audio_featuresWeb API reference:https://developer.spotify.com/documentation/web-api/reference/tracks/get-several-audio-features/Get Several TracksPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/tracks/get-several-tracks/Get a TrackPyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.tracksWeb API reference:https://developer.spotify.com/documentation/web-api/reference/tracks/get-track/Users Profile:Get Current User's ProfilePyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.user_profileWeb API reference:https://developer.spotify.com/documentation/web-api/reference/users-profile/get-current-users-profile/Get a User's ProfilePyfy:https://pyfy.readthedocs.io/en/latest/#pyfy.sync_client.Spotify.user_profileWeb API reference:https://developer.spotify.com/documentation/web-api/reference/users-profile/get-users-profile/Pagination 📖frompyfyimportSpotifyuser_creds={'access_token':'...','refresh_token':'....'}spt=Spotify(user_creds=user_creds)user_top_tracks=spt.user_top_tracks(limit=5)next_page_1=spt.next_page(user_top_tracks)next_page_2=spt.next_page(next_page_1)previous_page_1=spt.previous_page(next_page_2)previous_page_1===next_page_1# TrueDocumentation 📑For a detailed documentation of Pyfy's API, please visit:https://pyfy.readthedocs.io/en/latestwhere you'll find:Sync client API 🎸:https://pyfy.readthedocs.io/en/latest/#sync-client-apiAsync client API 🎼:https://pyfy.readthedocs.io/en/latest/#async-client-apiExceptions API ⚠️:https://pyfy.readthedocs.io/en/latest/#module-pyfy.excsCredentials API 📇:https://pyfy.readthedocs.io/en/latest/#module-pyfy.credsBackward Incompatibility NoticesV2:RemovedSpotify.oauth_uriproperty in favor ofSpotify.auth_urimethod.Spotify.play()now accepts,track_ids,artist_idsetc. instead ofresource_ids+resource_namesOauth2 state handling:Removed deprecatedenforce_state_checkfunctionalityRemoved state attribute fromuser_credsOauth2 state checking is no longer done by Pyfy's client and should be handled manuallyTesting 👩‍🔬:Please visit:https://pyfy.readthedocs.io/en/latest/#testingContributorsBig thank you to our amazing contributors:Stɑrry ShivɑmexofeelSchiismkevinhyneshaykkhykellePatrick ArminioMustafa