Skip to main content

📻 spotify-cmd v0.1.22

spotify-cmd is a Spotify client that allows controlling the playback of albums and playlists from a user's library (based on names or Spotify URIs) and individual tracks (based solely on Spotify URIs). The application is intended for use with spotifyd, but it works with any Spotify-enabled device.

Installation

Ensure you have Python 3 installed. Package is available on PyPi: https://pypi.org/project/spotify-cmd/. Install it using pip3:

pip3 install spotify-cmd

Debian/Ubuntu (apt)

curl -fsSL https://maciej-ciemborowicz.eu/apt/spotify-cmd.gpg | sudo gpg --dearmor -o /usr/share/keyrings/spotify-cmd-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/spotify-cmd-archive-keyring.gpg] https://maciej-ciemborowicz.eu/apt ./" | sudo tee /etc/apt/sources.list.d/spotify-cmd.list
sudo apt update
sudo apt install spotify-cmd

After installing from apt, the daemon is managed by systemd. Create the config at /var/lib/spotify-cmd/.config/spotify-cmd/config.ini, then restart:

sudo systemctl restart spotify-cmd
sudo systemctl status spotify-cmd --no-pager

If the service stays inactive, you need a token cache at /var/lib/spotify-cmd/.config/spotify-cmd/cache/token-cache. You can either generate it by running a one-time OAuth flow as the service user, or copy it from a user cache.

sudo systemctl stop spotify-cmd
sudo -u spotify-cmd /usr/bin/spotify-cmd-daemon --foreground
# Complete the OAuth flow in your browser (use an SSH tunnel if remote).
sudo systemctl start spotify-cmd

Or copy an existing cache:

sudo install -d -o spotify-cmd -g spotify-cmd /var/lib/spotify-cmd/.config/spotify-cmd/cache
sudo cp ~/.config/spotify-cmd/cache/token-cache /var/lib/spotify-cmd/.config/spotify-cmd/cache/token-cache
sudo chown spotify-cmd:spotify-cmd /var/lib/spotify-cmd/.config/spotify-cmd/cache/token-cache
sudo systemctl restart spotify-cmd

If you want to run the client as a regular user (for example pi), add it to the spotify-cmd group so it can access the daemon socket:

sudo usermod -aG spotify-cmd <user>

Headless spotifyd (Raspberry Pi, servers)

When using spotifyd on headless hosts, run it in the foreground under systemd and disable MPRIS to avoid DBus/X11 issues:

[global]
use_mpris = false

Configuration

The application configuration should be located in ~/.config/spotify-cmd/config.ini. Below is a detailed guide on each configuration option:

[SPOTIFY]
client_id = your_client_id
client_secret = your_client_secret
device_name = your_device_name  # optional; if omitted, uses the current active device
redirect_uri = http://localhost:8888/callback

[SPOTIFY_CMD_DAEMON]
socket_path = /run/spotify-cmd/spotify-cmd.sock
socket_buffer_size = 1024
  • client_id, client_secret are required. Obtain these by creating an app at the Spotify Developer Dashboard.
  • device_name is optional. If set, spotify-cmd-daemon will force to use it even if another is active; if omitted, it uses the current active device.
  • redirect_uri is used for Spotify authentication. If not set, it defaults to 'http://localhost:8888/callback'.
  • socket_path specifies the Unix socket path for the daemon. Defaults to '/run/spotify-cmd/spotify-cmd.sock' on Linux and '/tmp/spotify-cmd-daemon.sock' on other systems.
  • socket_buffer_size defines the buffer size for socket communication. Defaults to 1024.

Commands

spotify-cmd offers the following commands:

  • get playlists: Lists the user's playlists.
  • get albums: Lists the user's albums.
  • play playlist <name>, play album <name>, play uri <spotify_uri>: Plays a specific playlist, album, or resource by Spotify URI.
  • play, pause, next, previous: Controls playback.
  • set shuffle <on|off>: Toggles shuffle mode.
  • set volume <0-100>: Sets the volume level.
  • find <search_type> <query>: Searches for items on Spotify. Acceptable search types are album, artist, playlist, track, episode, and show.
  • version: Prints the installed spotify-cmd version.

Output Format

Select output format using the --format flag:

  • --format text: Plain text output (default).
  • --format json: Output in JSON format.
  • --format verbose: Verbose text information.

Usage Examples

spotify-cmd get albums
spotify-cmd get playlists
spotify-cmd play album "Listening Tree"
spotify-cmd play uri spotify:album:5zKTfU3vyuZfLgtYRfJyza
spotify-cmd find artist "Nils Frahm"

Terminal UI

Run spotify-cmd-ui to browse albums, playlists, and the active Spotify queue. Use 1, 2, and 3 to change views, arrow keys to select an item, and Enter to play it. Space toggles play/pause, s stops playback, and h toggles shuffle. The UI receives state events from the daemon, so changes made through any client appear automatically.

For Developers

Developers can create interfaces for spotify-cmd-daemon using /run/spotify-cmd/spotify-cmd.sock (Linux) or /tmp/spotify-cmd-daemon.sock (other systems). Socket handling and data format details are in the ./src/common directory (there is no documentation).

Test coverage

Install development dependencies and enable the Git hook:

pip install -e '.[dev]'
pre-commit install

Every commit runs the test suite with coverage for src. A commit passes only with 100% coverage. Run the same check manually with:

python -m coverage run -m pytest
python -m coverage report

The published-package smoke test uses PyPI and a new virtual environment. Run it explicitly when validating a release:

python -m pytest -m pypi

Daemon helper:

  • spotify-cmd-daemon --version prints the installed daemon version.

Planned Features and Upcoming Development

  • Displaying tracks from specific albums or playlists. [Done in 0.1.22]
  • MPRIS D-Bus interface support to reduce server queries. [Done in 0.1.22]
  • spotify-cmd-ui: A ncurses-based UI for track display and control, working with the same daemon. [Done in 0.1.22]
  • Search functionality. [Done in 0.1.4]
  • Support for other resource types like artists.
  • Config instructions after installation / creation of default config.

License

This project is licensed under the terms of the GNU General Public License. Detailed information can be found in the LICENSE.md file.

Author

Project created by Maciej Ciemborowicz.

Metadata

Release files for spotify-cmd 0.1.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spotify-cmd 0.1.22
File Size Uploaded Provenance Actions
spotify_cmd-0.1.22.tar.gz 53.9 kB Without provenance Details for spotify_cmd-0.1.22.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spotify-cmd 0.1.22
File Interpreter ABI Platform Actions
spotify_cmd-0.1.22-py3-none-any.whl Python 3 none any Details for spotify_cmd-0.1.22-py3-none-any.whl

Total release size: 102.9 kB

Release files / spotify_cmd-0.1.22.tar.gz

Download URL spotify_cmd-0.1.22.tar.gz
Size 53.9 kB
Tags Source
SHA-256 checksum
How to use checksums
46de21b06852559ce512f28cf5310c449f4d36d1f638049824ee296032fb8040
BLAKE2b-256 checksum
How to use checksums
8be287fde80e9e58ee48d39e30d1fe8e367ffd55c4e4f1bb7384a325cd19806f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / spotify_cmd-0.1.22-py3-none-any.whl

Download URL spotify_cmd-0.1.22-py3-none-any.whl
Size 49.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
947b94dc8281fa55183481d7e777bf1b036d36b524ca4219f2344db95ca1e152
BLAKE2b-256 checksum
How to use checksums
44bf9346f3be700321ae22d9cb32780f9da401f7ab9731665cff0402b0e92227
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for spotify-cmd 0.1.22

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page