Links

A Spotify object link.

Call the get_link() method on your Session instance to get a Link object from a Spotify URI. You can also get links from the link attribute on most objects, e.g. Track.link.

To get the URI from the link object you can use the uri attribute, or simply use the link as a string:

>>> session = spotify.Session()
# ...
>>> link = session.get_link(
...     'spotify:track:2Foc5Q5nqNiosCNqttzHof')
>>> link
Link('spotify:track:2Foc5Q5nqNiosCNqttzHof')
>>> link.uri
'spotify:track:2Foc5Q5nqNiosCNqttzHof'
>>> str(link)
'spotify:track:2Foc5Q5nqNiosCNqttzHof'
>>> link.type
<LinkType.TRACK: 1>
>>> track = link.as_track()
>>> track.link
Link('spotify:track:2Foc5Q5nqNiosCNqttzHof')
>>> track.load().name
u'Get Lucky'

You can also get Link objects from open.spotify.com and play.spotify.com URLs:

>>> session.get_link(
...     'http://open.spotify.com/track/4wl1dK5dHGp3Ig51stvxb0')
Link('spotify:track:4wl1dK5dHGp3Ig51stvxb0')
>>> session.get_link(
...     'https://play.spotify.com/track/4wl1dK5dHGp3Ig51stvxb0'
...     '?play=true&utm_source=open.spotify.com&utm_medium=open')
Link('spotify:track:4wl1dK5dHGp3Ig51stvxb0')
uri

The link’s Spotify URI.

url

The link’s HTTP URL.

type

The link’s LinkType.

as_track()[source]

Make a Track from the link.

as_track_offset()[source]

Get the track offset in milliseconds from the link.

as_album()[source]

Make an Album from the link.

as_artist()[source]

Make an Artist from the link.

as_playlist()[source]

Make a Playlist from the link.

as_user()[source]

Make an User from the link.

as_image(callback=None)[source]

Make an Image from the link.

If callback isn’t None, it is expected to be a callable that accepts a single argument, an Image instance, when the image is done loading.

class spotify.LinkType[source]
ALBUM = <LinkType.ALBUM: 2>
ARTIST = <LinkType.ARTIST: 3>
IMAGE = <LinkType.IMAGE: 9>
INVALID = <LinkType.INVALID: 0>
LOCALTRACK = <LinkType.LOCALTRACK: 8>
PLAYLIST = <LinkType.PLAYLIST: 5>
PROFILE = <LinkType.PROFILE: 6>
SEARCH = <LinkType.SEARCH: 4>
STARRED = <LinkType.STARRED: 7>
TRACK = <LinkType.TRACK: 1>