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.

state

The session’s current ConnectionState.

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

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

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.

allow_network

Whether or not network access is allowed at all.

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

allow_network_if_roaming

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

Defaults to False.

allow_sync_over_wifi

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

Defaults to True.

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]
ALLOW_SYNC_OVER_MOBILE = <ConnectionRule.ALLOW_SYNC_OVER_MOBILE: 4>
ALLOW_SYNC_OVER_WIFI = <ConnectionRule.ALLOW_SYNC_OVER_WIFI: 8>
NETWORK = <ConnectionRule.NETWORK: 1>
NETWORK_IF_ROAMING = <ConnectionRule.NETWORK_IF_ROAMING: 2>
class spotify.ConnectionState[source]
DISCONNECTED = <ConnectionState.DISCONNECTED: 2>
LOGGED_IN = <ConnectionState.LOGGED_IN: 1>
LOGGED_OUT = <ConnectionState.LOGGED_OUT: 0>
OFFLINE = <ConnectionState.OFFLINE: 4>
UNDEFINED = <ConnectionState.UNDEFINED: 3>
class spotify.ConnectionType[source]
MOBILE = <ConnectionType.MOBILE: 2>
MOBILE_ROAMING = <ConnectionType.MOBILE_ROAMING: 3>
NONE = <ConnectionType.NONE: 1>
UNKNOWN = <ConnectionType.UNKNOWN: 0>
WIFI = <ConnectionType.WIFI: 4>
WIRED = <ConnectionType.WIRED: 5>