class spotify.Session(config=None)[source]

The Spotify session.

If no config is provided, the default config is used.

The session object will emit a number of events. See SessionEvent for a list of all available events and how to connect your own listener functions up to get called when the events happens.


You can only have one Session instance per process. This is a libspotify limitation. If you create a second Session instance in the same process pyspotify will raise a RuntimeError with the message “Session has already been initialized”.


config (Config or None) – the session config

class spotify.SessionEvent[source]

Session events.

Using the Session object, 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)
        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.