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
Metadata
Release files for scrobbles 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scrobbles-0.1.0.tar.gz | 40.1 kB | Without provenance | Details for scrobbles-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scrobbles-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for scrobbles-0.1.0-py3-none-any.whl |
Total release size: 53.5 kB
Release files / scrobbles-0.1.0.tar.gz
| Download URL | scrobbles-0.1.0.tar.gz |
|---|---|
| Size | 40.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c1d0a7a3daab45308a2a2b84add131ca1b83e6423090d59779af6b30c8d96508
|
|
BLAKE2b-256 checksum How to use checksums |
46b5283cb8d1c51a1ffac52234a0ff9e25a91282a6c965dd865ba2a2425f03cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / scrobbles-0.1.0-py3-none-any.whl
| Download URL | scrobbles-0.1.0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3888abc0a12dcb4c1d47ae924f835bf3f39f551cecb0c9b619e3c09f4b7ff74b
|
|
BLAKE2b-256 checksum How to use checksums |
196bdba81c3f96d1e5c05a7ccc935acf7348a1dfd216efd6a19ad863f24cc129
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for scrobbles 0.1.0
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.