pyspotify
stable
  • Installation
  • Quickstart
  • API reference
    • Error handling
    • Configuration
    • Sessions
    • Event loop
    • Connection
    • Offline sync
    • Links
    • Users
    • Tracks
    • Albums
    • Artists
    • Images
    • Search
    • Playlists
    • Toplists
    • Inbox
    • Social
    • Player
    • Audio
    • Audio sinks
    • Internal API
  • Authors
  • Changelog
  • Contributing
pyspotify
  • Docs »
  • API reference »
  • Links
  • Edit on GitHub

Links¶

class spotify.Link(session, uri=None, sp_link=None, add_ref=True)[source]¶

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')
class spotify.LinkType(value)[source]¶
Next Previous

© Copyright 2013-2022, Stein Magnus Jodal and contributors Revision 575e0cbd.

Built with Sphinx using a theme provided by Read the Docs.