scrobbles
Fetch, export, and visualize Last.fm listening data — plus create Spotify playlists from your top albums.
Setup
Prerequisites
- Python 3.12+
- uv (recommended) or pip
Install
pip install scrobbles
# or
uv add scrobbles
From source
git clone https://github.com/saforem2/scrobbles.git
cd lastfm
uv sync
Environment Variables
Last.fm
Get API credentials at https://www.last.fm/api/account.
export LASTFM_API_KEY="..."
export LASTFM_API_SECRET="..."
export LASTFM_USERNAME="..."
export LASTFM_PASSWORD="..."
Spotify (optional — only needed for playlist creation)
- Create an app at https://developer.spotify.com/dashboard
- Add
http://127.0.0.1:8888/callbackas a Redirect URI in your app settings - Export your credentials:
export SPOTIFY_CLIENT_ID="..." # or SPOTIPY_CLIENT_ID
export SPOTIFY_CLIENT_SECRET="..." # or SPOTIPY_CLIENT_SECRET
export SPOTIPY_REDIRECT_URI="http://127.0.0.1:8888/callback"
Either SPOTIFY_* or SPOTIPY_* naming works — the library maps them automatically.
Usage
CLI
# Via entry point (after install)
scrobbles top-albums overall --limit 25
scrobbles top-albums 2024
scrobbles dashboard
# Via main.py (development)
uv run python main.py top-albums overall --limit 25
uv run python main.py top-albums 2024
uv run python main.py top-albums last_month
# Export top albums to JSON
uv run python main.py dump-albums 2024 --limit 100
# Generate the HTML dashboard from existing JSON files
uv run python main.py dashboard
# Create Spotify playlists from all top100-YYYY.json files
uv run python main.py spotify-playlists --dry-run
uv run python main.py spotify-playlists --skip 2020 2021
Python API
import scrobbles
# Recent tracks & now playing
scrobbles.get_recent_tracks("username", 10)
print(scrobbles.get_now_playing("username"))
# Top albums — predefined periods
scrobbles.print_top_albums("username", period="7day", limit=20)
# Top albums — arbitrary date ranges
scrobbles.print_top_albums("username", period="2024") # full year
scrobbles.print_top_albums("username", period="2024-06") # single month
scrobbles.print_top_albums("username", period="last_week")
# Export to JSON
scrobbles.dump_top_albums("username", period="2024", limit=100)
# Generate interactive HTML dashboard
from scrobbles.albums import build_dashboard
build_dashboard() # reads data/albums/top100-*.json → data/albums/index.html
# Spotify: create a playlist from any album list
from scrobbles.spotify import create_playlist_from_albums
albums = [{"artist": "Radiohead", "album": "OK Computer", "plays": 50}]
create_playlist_from_albums(albums, "My Playlist", dry_run=True)
# Spotify: bulk-create yearly playlists
from scrobbles.spotify import create_all_playlists
create_all_playlists(dry_run=True)
Supported Period Strings
| Period | Description |
|---|---|
overall |
All time |
7day, 1month, 3month, 6month, 12month |
Rolling windows |
today, yesterday, last_week, last_month, last_year |
Calendar-relative |
2024 |
Full calendar year |
2024-06 |
Single month |
2024-06-15 |
Single day |
Project Structure
lastfm/
├── src/scrobbles/
│ ├── __init__.py # Network setup, track utils, re-exports
│ ├── albums.py # Top albums: fetch, format, export, dashboard
│ ├── cli.py # CLI entry point
│ └── spotify.py # Spotify playlist creation
├── data/albums/ # Generated JSON + HTML dashboard
│ ├── top100-YYYY.json
│ └── index.html
├── main.py # Thin shim (calls scrobbles.cli:main)
├── pyproject.toml
└── README.md
Publishing
# Bump version
uv version --bump patch
# Build
uv build
# Publish to PyPI
uv publish
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
scrobbles-0.1.0.tar.gz
(40.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
scrobbles-0.1.0-py3-none-any.whl
(13.4 kB
view details)
File details
Details for the file scrobbles-0.1.0.tar.gz.
File metadata
- Download URL: scrobbles-0.1.0.tar.gz
- Upload date:
- Size: 40.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1d0a7a3daab45308a2a2b84add131ca1b83e6423090d59779af6b30c8d96508
|
|
| MD5 |
9f6853c02997fb535904fd7fa4d8d54c
|
|
| BLAKE2b-256 |
46b5283cb8d1c51a1ffac52234a0ff9e25a91282a6c965dd865ba2a2425f03cf
|
File details
Details for the file scrobbles-0.1.0-py3-none-any.whl.
File metadata
- Download URL: scrobbles-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3888abc0a12dcb4c1d47ae924f835bf3f39f551cecb0c9b619e3c09f4b7ff74b
|
|
| MD5 |
a63d5c63fd08b8834fa87ee3d5d6042b
|
|
| BLAKE2b-256 |
196bdba81c3f96d1e5c05a7ccc935acf7348a1dfd216efd6a19ad863f24cc129
|