AsyncSpotify
Documentation
The full documentation can be viewed here.
Why should you use this library
- 100% Code coverage
- Completely type annotated
- Completely async
- Scales up to (theoretically) unlimited requests per second (tested with 1000 simultaneous requests which lead to a 429)
- Customize the timeout, maximal simultaneous request
- Throws custom errors, so you can catch different errors easily
+ Token expiration
+ Rate limit violation
+ An invalid album id
- Gets rid of the client credential workflow if you provide spotify cookies
- Good for automated testing
- Offers a hook which gets called if the token expires, so you can automatically update the token
Installation
You need at least python3.6 to install the package
pip install async-spotify
Example
For more in depth examples take a look here or visit the documentation.
from async_spotify import SpotifyApiClient
from async_spotify.authentification import SpotifyAuthorisationToken
from async_spotify.authentification.authorization_flows import AuthorizationCodeFlow
auth_flow = AuthorizationCodeFlow()
auth_flow.load_from_env()
api_client = SpotifyApiClient(auth_flow, hold_authentication=True)
code: str = "Your Spotify Code"
auth_token: SpotifyAuthorisationToken = await api_client.get_auth_token_with_code(code)
await api_client.create_new_client(request_limit=1500)
album_tracks: dict = await api_client.albums.get_tracks('03dlqdFWY9gwJxGl3AREVy')
album_tracks: dict = await api_client.albums.get_tracks('03dlqdFWY9gwJxGl3AREVy', auth_token)
await api_client.player.play(context_uri="spotify:album:5ht7ItJgpBH7W6vJ5BqpPr", device_id="whatever_id")
Tests
See here.