pyspot 0.0.1
Released: 19-Jul-2015
pyspot is a Python package that provides an interface to theSpotify RESTful web API.
I encourage other developers to create issues and submit pull requests if there exists errors or improvements can be made to the SDK.
Your credentials can be passed when instantiating the Spotify class. Alternatively, pyspot will check for the existence of the following environment variables:
SPOTIFY_CLIENT_ID- Your Spotify client ID
SPOTIFY_CLIENT_SECRET- Your Spotify client secret
Credentials can also be stored in a~/.pyspot
configuration file.
{
"SPOTIFY_CLIENT_ID":"<YOUR_SPOTIFY_CLIENT_ID>",
"SPOTIFY_CLIENT_SECRET":"<YOUR_SPOTIFY_CLIENT_SECRET>"
}
frompyspotimportSpotify
frompyspot.exceptionimportSpotifyServerError
# use credentials from ~/.pyspot configuration file
spotify=Spotify()
try:
track=spotify.get_track(id='6kLCHFM39wkFjOuyPGLGeQ',market='US')
exceptSpotifyServerError,e:
raisee
printtrack.name,'-',track.artists[0].name# Heaven and Hell - William Onyeabor
The Spotify Web API contains aPagingobject that serves as a container for a set of objects.
ToPaging
object supports iteration by calling thenext
method. An example below shows how to paginate through a list ofTrack
objects wrapped in aPaging
object:
frompyspotimportSpotify
frompyspot.exceptionimportSpotifyServerError
spotify=Spotify()
try:
tracks=spotify.get_albums_tracks(
id='6akEvsycLGftJxYudPjmqK',
limit=1
)
exceptpyspot.exception.SpotifyServerError,e:
raisee
# Print the first element of the track
printtracks.items
whiletracks.next:
# If the `next` attribute is not None, continue to iterate through the
# `Track` objects.
next(tracks)
printtracks.items