Spotify Module Reference

New in version 0.1.0.

Control Spotify using JXA-like syntax.

Classes:

XASpotifyApplication(properties)

A class for managing and interacting with Spotify.app.

XASpotifyTrack(properties)

A Spotify track.

class PyXA.apps.Spotify.XASpotifyApplication(properties)[source]

Bases: XASBApplication

A class for managing and interacting with Spotify.app.

New in version 0.1.0.

Classes:

PlayerState(value)

States of the Spotify track player.

Attributes:

current_track

The currently playing track.

frontmost

Whether Spotify is the active application.

name

The name of the application.

player_position

The player's position within the currently playing track in seconds.

player_state

Is Spotify stopped, paused, or playing?

repeating

Whether repeating is on or off.

repeating_enabled

Whether repeating is enabled in the current playback context.

shuffling

Whether shuffling is on or off.

shuffling_enabled

Whether shuffling is enabled in the current playback context.

sound_volume

The sound output volume (0 = minimum, 100 = maximum).

version

The version of Spotify.app.

Methods:

next_track()

Skips to the next track.

pause()

Pauses playback.

play()

Resumes playback.

play_track(track_uri[, context_uri])

Starts playback of a track in the given context.

playpause()

Toggles play/pause.

previous_track()

Skips to the previous track.

search([search_string, track, start_year, ...])

Opens the search tab and searches for content matching given parameters.

class PlayerState(value)[source]

Bases: Enum

States of the Spotify track player.

Attributes:

PAUSED

PLAYING

STOPPED

PAUSED = 1800426352
PLAYING = 1800426320
STOPPED = 1800426323
property current_track: XASpotifyTrack

The currently playing track.

property frontmost: bool

Whether Spotify is the active application.

property name: str

The name of the application.

next_track()[source]

Skips to the next track.

Example:

>>> import PyXA
>>> app = PyXA.Application("Spotify")
>>> app.next_track()

New in version 0.1.0.

pause()[source]

Pauses playback.

Example:

>>> import PyXA
>>> app = PyXA.Application("Spotify")
>>> app.pause()

New in version 0.1.0.

play()[source]

Resumes playback.

Example:

>>> import PyXA
>>> app = PyXA.Application("Spotify")
>>> app.play()

New in version 0.1.0.

play_track(track_uri: str, context_uri: str | None = None)[source]

Starts playback of a track in the given context.

Parameters:
  • track_uri (str) – The URI of the track to play

  • context_uri (Union[str, None], optional) – The URI of the context to play in, defaults to None

Example:

>>> import PyXA
>>> app = PyXA.Application("Spotify")
>>> app.play_track("spotify:track:4LRPiXqCikLlN15c3yImP7")

New in version 0.1.0.

property player_position: float

The player’s position within the currently playing track in seconds.

property player_state: PlayerState

Is Spotify stopped, paused, or playing?

playpause()[source]

Toggles play/pause.

Example:

>>> import PyXA
>>> app = PyXA.Application("Spotify")
>>> app.playpause()

New in version 0.1.0.

previous_track()[source]

Skips to the previous track.

Example:

>>> import PyXA
>>> app = PyXA.Application("Spotify")
>>> app.previous_track()

New in version 0.1.0.

property repeating: bool

Whether repeating is on or off.

property repeating_enabled: bool

Whether repeating is enabled in the current playback context.

search(search_string: str = '', track: str = '', start_year: int = -1, end_year: int = -1, genre: str = '', artist: str = '', album: str = '', label: str = '', mood: str = '')[source]

Opens the search tab and searches for content matching given parameters.

New in version 0.1.0.

property shuffling: bool

Whether shuffling is on or off.

property shuffling_enabled: bool

Whether shuffling is enabled in the current playback context.

property sound_volume: int

The sound output volume (0 = minimum, 100 = maximum).

property version: str

The version of Spotify.app.

class PyXA.apps.Spotify.XASpotifyTrack(properties)[source]

Bases: XAObject

A Spotify track.

New in version 0.1.0.

Attributes:

album

The album of the track.

album_artist

The album artist of the track.

artist

The artist of the track.

artwork

The album artwork image.

artwork_url

The URL of the track's album cover.

disc_number

The disc number of the track.

duration

The length of the track in milliseconds.

id

The ID of the track.

name

The name of the track.

played_count

The number of times this track has been played.

popularity

The popularity of this track, 0-100.

spotify_url

The URL of the track.

starred

Whether the track is starred.

track_number

The index of the track in its album.

property album: str

The album of the track.

property album_artist: str

The album artist of the track.

property artist: str

The artist of the track.

property artwork: XAImage

The album artwork image.

property artwork_url: XAURL

The URL of the track’s album cover.

property disc_number: int

The disc number of the track.

property duration: int

The length of the track in milliseconds.

property id: str

The ID of the track.

property name: str

The name of the track.

property played_count: int

The number of times this track has been played.

property popularity: int

The popularity of this track, 0-100.

property spotify_url: type

The URL of the track.

property starred: bool

Whether the track is starred.

property track_number: int

The index of the track in its album.