Connection

class spotify.connection.Connection(session)[source]

Connection controller.

You’ll never need to create an instance of this class yourself. You’ll find it ready to use as the connection attribute on the Session instance.

property state

The session’s current ConnectionState.

The connection state involves two components, authentication and offline mode. The mapping is as follows

  • LOGGED_OUT: not authenticated, offline

  • OFFLINE: authenticated, offline

  • LOGGED_IN: authenticated, online

  • DISCONNECTED: authenticated, offline, was previously online

Register listeners for the spotify.SessionEvent.CONNECTION_STATE_UPDATED event to be notified when the connection state changes.

property type

The session’s ConnectionType.

Defaults to ConnectionType.UNKNOWN. Set to a ConnectionType value to tell libspotify what type of connection you’re using.

This is used together with allow_network, allow_network_if_roaming, allow_sync_over_wifi, and allow_sync_over_mobile to control offline syncing and network usage.

property allow_network

Whether or not network access is allowed at all.

Defaults to True. Setting this to False turns on offline mode.

property allow_network_if_roaming

Whether or not network access is allowed if type is set to ConnectionType.MOBILE_ROAMING.

Defaults to False.

property allow_sync_over_wifi

Whether or not offline syncing is allowed when type is set to ConnectionType.WIFI.

Defaults to True.

property allow_sync_over_mobile

Whether or not offline syncing is allowed when type is set to ConnectionType.MOBILE, or allow_network_if_roaming is True and type is set to ConnectionType.MOBILE_ROAMING.

Defaults to True.

class spotify.ConnectionRule[source]
class spotify.ConnectionState[source]
class spotify.ConnectionType[source]