Export your Last.fm listening history and optionally enrich it with Spotify metadata.
Project description
lastfm-export
Export your Last.fm listening history (scrobbles) and optionally enrich it with Spotify metadata.
Designed for both:
- CLI-first users who want “just get my data”, and
- Python users who want reusable clients and pipelines.
Features
- Export scrobbles from Last.fm with paging + retry/backoff.
- Optional Spotify enrichment (track metadata lookup).
- Streaming-friendly outputs (NDJSON recommended).
- Works with environment variables (no secrets in code).
Install
Using uv:
uv pip install lastfm-export
Or with .env support for local development:
uv pip install "lastfm-export[dotenv]"
Authentication
Last.fm
Set these environment variables:
export LASTFM_API_KEY="..."
export LASTFM_USERNAME="..."
Spotify (optional)
Set these environment variables:
export SPOTIFY_CLIENT_ID="..."
export SPOTIFY_CLIENT_SECRET="..."
If you installed lastfm-export[dotenv], you can also put these values in a local .env file.
Quickstart (CLI)
1) Export scrobbles
Recommended output format: NDJSON (one JSON object per line).
lastfm-export scrobbles export \
--out scrobbles.ndjson
Optional filters:
lastfm-export scrobbles export \
--out scrobbles.ndjson \
--from YYYY-MM-DD \
--to YYYY-MM-DD
You can also pass full datetimes:
lastfm-export scrobbles export \
--out scrobbles.ndjson \
--from YYYY-MM-DDTHH:MM:SS \
--to YYYY-MM-DDTHH:MM:SS
Resume (incremental export):
lastfm-export scrobbles export \
--out scrobbles.ndjson \
--resume auto
2) Enrich with Spotify
lastfm-export enrich spotify \
--in scrobbles.ndjson \
--out scrobbles_enriched.ndjson
Notes:
- Spotify enrichment is best-effort: some tracks may not match cleanly.
- Use NDJSON for large exports.
Quickstart (Python)
Export scrobbles
from lastfm_export.clients.lastfm import LastFMClient
from lastfm_export.pipelines.lastfm_export import export_scrobbles
lastfm = LastFMClient(
api_key="...",
username="...",
user_agent="lastfm-export",
)
for scrobble in export_scrobbles(lastfm=lastfm):
print(scrobble.to_record())
Enrich with Spotify
from lastfm_export.clients.spotify import SpotifyClient
from lastfm_export.pipelines.spotify_enrich import enrich_scrobbles_with_spotify
spotify = SpotifyClient(
client_id="...",
client_secret="...",
user_agent="lastfm-export",
)
enriched = enrich_scrobbles_with_spotify(spotify=spotify, scrobbles=export_scrobbles(lastfm=lastfm))
for row in enriched:
print(row.to_record())
Output formats
Supported formats depend on command:
- NDJSON: recommended for streaming and incremental runs.
- JSON array: convenient for small exports.
- CSV: convenient for spreadsheets.
Tip: For large histories, use NDJSON to avoid loading everything into memory.
Development
Clone the repo and set up the environment with uv:
uv venv
uv sync
Run checks:
uv run ruff check .
uv run pytest -q
Build:
uv build --no-sources
License
See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file lastfm_export-0.1.1.tar.gz.
File metadata
- Download URL: lastfm_export-0.1.1.tar.gz
- Upload date:
- Size: 50.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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 |
6200a9f0101aa3d37e7de0e1b000b37b7badcb97ad511ea13c42b7a76f248dd0
|
|
| MD5 |
bd734bd7cd4410c4d46fe2597282ec10
|
|
| BLAKE2b-256 |
cfd8e2aeb0d49b6dab9f0646617eb9f60746298a2c372e60adfac12c48e2db18
|
File details
Details for the file lastfm_export-0.1.1-py3-none-any.whl.
File metadata
- Download URL: lastfm_export-0.1.1-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","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 |
9c0957f559dcf7348eb849d6ca88de1161f3638f16dbee17d80e356d23684947
|
|
| MD5 |
92f936afc56ff906e06d33d991670903
|
|
| BLAKE2b-256 |
6b01962051ba7f79cfe99e90063996892cd807a16c415cef6b080b1b2c03f8ea
|