Skip to main content

Automatically scrobble music playing on your Sonos speakers to Last.fm

Project description

Sonos Last.fm Scrobbler

PyPI Python

sonos lastfm

Automatically scrobble what's playing on your Sonos speakers to your Last.fm profile.

The problem

If you use Last.fm, you know the value of a complete listening history. Some of us have been scrobbling for 10, 15, even 20 years — and that data tells a story.

But Sonos doesn't support Last.fm. There's no native integration, no plugin, no setting to flip. Every song you play on your Sonos speakers is a gap in your scrobbling history.

The solution

sonos-lastfm is a lightweight CLI tool that monitors your local network for Sonos playback and scrobbles every track to Last.fm automatically.

Run it on any always-on device in your home — a Raspberry Pi, a Mac Mini, an old laptop, or any Linux server — and never miss a scrobble again. It works as a background daemon, so once you set it up, you can forget about it.

Get started in 2 minutes

1. Install

pip install sonos-lastfm

Requires Python 3.10+ and Sonos speakers on the same network.

2. Get a free Last.fm API key

You need an API key so the app can talk to Last.fm on your behalf. It's free and takes 30 seconds:

  1. Open https://www.last.fm/api/account/create
  2. Fill in the form — app name can be anything (e.g. "my sonos scrobbler"), other fields don't matter
  3. Submit — you'll see your API key and Shared secret. Keep this page open, you'll need both in the next step

3. Run setup

sonos-lastfm setup

The setup wizard will ask for four things:

Credential What it is
Username Your Last.fm username (the one you log in with)
Password Your Last.fm account password
API key From step 2 above
API secret The "Shared secret" from step 2 above

The wizard validates your credentials immediately, so you'll know right away if something's wrong.

4. Start scrobbling

sonos-lastfm run

That's it! Play something on your Sonos and it will show up on your Last.fm profile.

CLI usage

sonos-lastfm run                # start scrobbling (interactive, with progress bar)
sonos-lastfm run --daemon       # start scrobbling (no progress display, for services)
sonos-lastfm run --interval 5   # check every 5s instead of 1s
sonos-lastfm info               # show account info and recent scrobbles
sonos-lastfm recent             # show last 10 scrobbled tracks
sonos-lastfm show               # show stored credentials (masked)
sonos-lastfm reset              # delete stored credentials

All run options: sonos-lastfm run --help

Run as a systemd service

Create ~/.config/systemd/user/sonos-lastfm.service:

[Unit]
Description=Sonos Last.fm Scrobbler
After=network-online.target

[Service]
Type=simple
ExecStart=%h/.local/bin/sonos-lastfm run --daemon
Restart=on-failure
RestartSec=10

[Install]
WantedBy=default.target

Then:

systemctl --user daemon-reload
systemctl --user enable --now sonos-lastfm
journalctl --user -u sonos-lastfm -f   # watch logs

In daemon mode, only song changes, scrobbles, and errors are logged.

AI-powered setup

Want an AI agent to handle the full setup for you — installing, configuring credentials, and setting up a persistent daemon? Use the included setup skill with any agent that supports open agent skills (Claude Code, Cursor, Windsurf, Codex, etc.).

Option A — Install the skill directly (no clone needed):

npx skills add denya/sonos-lastfm@setup-sonos-lastfm

Then ask your agent to "set up sonos-lastfm as a daemon."

Option B — Clone the repo and use the skill from source:

git clone https://github.com/denya/sonos-lastfm.git
cd sonos-lastfm
npx skills add ./skills/setup-sonos-lastfm

The skill covers Linux (systemd), macOS (launchd), and Windows (Task Scheduler), guides you through getting Last.fm API keys, and ensures you're always running the latest version from PyPI.

Scrobble rules

  • Track is scrobbled after 25% played (configurable via --threshold) or 4 minutes, whichever comes first
  • Same track won't be scrobbled again within 30 minutes

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sonos_lastfm-1.1.1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sonos_lastfm-1.1.1-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file sonos_lastfm-1.1.1.tar.gz.

File metadata

  • Download URL: sonos_lastfm-1.1.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for sonos_lastfm-1.1.1.tar.gz
Algorithm Hash digest
SHA256 976393cfc3176451e1797e84598dbbd9f2647562de15bcf0da50e9af3487b721
MD5 360748ffc629339784c265093b02bc41
BLAKE2b-256 f0faace7dd570fe99cc2a042740a11c7d7719182953d5129be494a2d29ad0ec2

See more details on using hashes here.

File details

Details for the file sonos_lastfm-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sonos_lastfm-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 520721ff30adb488306c460633e8c0e98b2b23468b63e4ff8b52f0151629da50
MD5 20c3adb5cd08614fa7571bbd7821129e
BLAKE2b-256 276c5c58a3daa7cbe815d4555b92ac2abe3a655f39bc3daafdbd3b5916980b90

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page