Skip to content

rightlag/pyspot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

18 Commits

Repository files navigation

pyspot

pyspot 0.0.1

Released: 19-Jul-2015


Introduction

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.

Getting started with pyspot

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~/.pyspotconfiguration file.

{
"SPOTIFY_CLIENT_ID":"<YOUR_SPOTIFY_CLIENT_ID>",
"SPOTIFY_CLIENT_SECRET":"<YOUR_SPOTIFY_CLIENT_SECRET>"
}

Sample endpoint request

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

Iterating throughPagingobjects

The Spotify Web API contains aPagingobject that serves as a container for a set of objects.

ToPagingobject supports iteration by calling thenextmethod. An example below shows how to paginate through a list ofTrackobjects wrapped in aPagingobject:

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

About

An SDK for interacting with the Spotify web API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages