Sessions¶
-
class
spotify.Session(config=None)[source]¶ The Spotify session.
If no
configis provided, the default config is used.The session object will emit a number of events. See
SessionEventfor a list of all available events and how to connect your own listener functions up to get called when the events happens.Warning
You can only have one
Sessioninstance per process. This is a libspotify limitation. If you create a secondSessioninstance in the same process pyspotify will raise aRuntimeErrorwith the message “Session has already been initialized”.- Parameters
config (
ConfigorNone) – the session config
-
class
spotify.SessionEvent[source]¶ Session events.
Using the
Sessionobject, you can register listener functions to be called when various session related events occurs. This class enumerates the available events and the arguments your listener functions will be called with.Example usage:
import spotify def logged_in(session, error_type): if error_type is spotify.ErrorType.OK: print('Logged in as %s' % session.user) else: print('Login failed: %s' % error_type) session = spotify.Session() session.on(spotify.SessionEvent.LOGGED_IN, logged_in) session.login('alice', 's3cret')
All events will cause debug log statements to be emitted, even if no listeners are registered. Thus, there is no need to register listener functions just to log that they’re called.