asyncspotify is an asynchronous, object-oriented python wrapper for the Spotify Web API.
Simply install the library from PyPI:
python -m pip install asyncspotifyThe documentation can be found at readthedocs.
To get going quickly, read the quickstart.
For complete examples, please check the documentation. Here's some snippets:
Authenticating using the Client Credentials flow, and getting a playlist:
fromasyncspotifyimportClient, ClientCredentialsFlowauth=ClientCredentialsFlow(
client_id='your client id',
client_secret='your client secret',
)
asyncwithClient(auth) assp:
playlist=awaitsp.get_playlist('1MG01HhbCvVhH9NmXhd9GC')
asyncfortrackinplaylist:
print(track.name)Searching for and getting tracks:
results=awaitsp.search_tracks(q='involvers', limit=2)
# [<SimpleTrack id='5xoJhWwvzPJD9k8j8BE2xO' name='27'>, <SimpleTrack id='0WUTBejxPUhURFCFfSYbDc' name='Fighting My Fight'>]track=awaitsp.get_track('0hqAWKZDhuOfFb6aK002Ph')
# <FullTrack id='0hqAWKZDhuOfFb6aK002Ph' name='Bone Dry'>Fetching and creating playlists:
# get a playlistplaylist=awaitsp.get_playlist('1wPvaRtuI8mt10CpP2KnlO')
# <FullPlaylist id='1wPvaRtuI8mt10CpP2KnlO' name='my playlist'># iterate through playlist tracksfortrackinplaylist.tracks:
print(track)
# get current userme=awaitsp.get_me()
# <PrivateUser id='runie13'># create new playlistmy_playlist=awaitme.create_playlist(name='My playlist!')
# <FullPlaylist id='0YTCnj0WE5gGb1lRqD6Ks9' name='My playlist!'># add tracks from previews playlist to the new playlistawaitmy_playlist.add_tracks(*playlist.tracks)Please report issues here at GitHub.