Skip to main content

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="..."

Last.fm privacy setting: Exporting scrobbles requires your recent listening information to be available through the Last.fm API. Make sure “Hide recent listening information” is disabled in your Last.fm privacy settings. This setting controls whether your recent listening information is publicly visible.

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


Download files

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

Source Distribution

lastfm_export-0.1.2.tar.gz (54.8 kB view details)

Uploaded Source

Built Distribution

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

lastfm_export-0.1.2-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file lastfm_export-0.1.2.tar.gz.

File metadata

  • Download URL: lastfm_export-0.1.2.tar.gz
  • Upload date:
  • Size: 54.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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

Hashes for lastfm_export-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bde186397c8dec7a10c9c8044a0d060e4d26fca4ad44fe268f7948f16fbc2222
MD5 176fea40edecb12de1c06c1f7ba7c554
BLAKE2b-256 75161f27743b43ecf0e4399bad355e2d05b79624ea3c2865c1974f9123079691

See more details on using hashes here.

File details

Details for the file lastfm_export-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lastfm_export-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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

Hashes for lastfm_export-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 38f1e30281831e7f1dcc6530d43566578e9d1d33a62de6c066c6c9f625923f89
MD5 30b9ff09359f6ff9aad873382be5bf08
BLAKE2b-256 ef05c52e15c2dde53af3c334219c7b862cfa8a7868d89de2957c0d9ecbba96df

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