Registry / http-networking / pylast

pylast

JSON →
library7.0.2pypypi✓ verified 87d ago

A Python interface to Last.fm and Libre.fm. Current version 7.0.2 (requires Python >=3.10). Uses httpx for HTTP requests. Active development; releases every few months.

pip install pylast
INSTALL
IMPORT
SIG · PYLAST
P
pylast
http-networkingpythonv7.0.2
Install
2.1s avg
Import
296ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.0.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.314s · 22MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.1s · import 0.278s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LastFMNetwork
from pylast import LastFMNetwork
import pylast.LastFMNetwork
LastFMNetwork is a class, not a module; direct import leads to AttributeError.
Track
from pylast import Track
import pylast.Track
Same as others; classes are not submodules.
Album
from pylast import Album
Artist
from pylast import Artist
User
from pylast import User

Initialize LastFMNetwork with API credentials and fetch top tracks for a user.

from pylast import LastFMNetwork api_key = os.environ.get('LASTFM_API_KEY', '') api_secret = os.environ.get('LASTFM_API_SECRET', '') network = LastFMNetwork(api_key=api_key, api_secret=api_secret) # Get top tracks for a user try: user = network.get_user('RJ') top_tracks = user.get_top_tracks(limit=3) for track in top_tracks: print(track.item) except Exception as e: print(f"Error: {e}")
Debug
Known issues
breakingIn version 5.0.0, the HTTP library changed from `http.client` to `httpx`. Custom session handling or proxies must be adapted.
fix
If you were using `http.client` or relying on `urllib3` behavior, you must migrate to httpx proxy configuration.
affects: >=5.0.0
breakingIn version 6.0.0, proxy support was restored but the `network.proxy` attribute is now always a `dict` (previously could be `str` or `dict`).
fix
Check for `isinstance(network.proxy, dict)` instead of expecting a string.
affects: 6.0.0 and later
breakingIn version 7.0.0, `SCROBBLE_SOURCE_*` and `SCROBBLE_MODE_*` constants were removed. Use `chosen_by_user` parameter instead.
fix
Replace `SCROBBLE_SOURCE_USER` etc. with the `chosen_by_user` boolean parameter in `scrobble` calls.
affects: >=7.0.0
gotchaThe `get_top_tracks()` and similar methods return `TopItem` objects, not `Track` objects. Access the actual track via `.item`.
fix
Use `for top_item in user.get_top_tracks(): track = top_item.item`.
affects: all
gotchaWhen using session key authentication, you must call `network.get_session_key()` with the token first. Many users forget this step.
fix
See the authentication example in the README: generate token, get session key, then create `LastFMNetwork(api_key, api_secret, session_key)`.
affects: all
deprecatedIn version 5.0.0, `is_streamable` and `is_fulltrack_available` were removed.
fix
Use the `streamable` attribute on Track objects instead.
affects: >=5.0.0
Errors
Common errors & fixes
AttributeError: module 'pylast' has no attribute 'LastFMNetwork'
Using `import pylast` and then `pylast.LastFMNetwork` fails because LastFMNetwork is a class, not a module-level attribute. The class is not exposed at the top-level by default.
fix
Use `from pylast import LastFMNetwork`.
pylast.WSError: Invalid API Key
You provided an API key that is not valid or not active for Last.fm.
fix
Register at https://www.last.fm/api/account/create and use that key. Double-check you are using the correct key and secret.
httpx.ConnectError: All connection attempts failed
Network issue, proxy problem, or DNS failure. Also can happen if proxy configuration is wrong.
fix
Check your internet connection. If using a proxy, pass it correctly: `LastFMNetwork(api_key, api_secret, proxy="http://proxy:8080")` or as a dict for multiple proxies.
TypeError: 'str' object cannot be interpreted as an integer
Passing a string where integer expected, e.g., `limit="10"` instead of `limit=10`.
fix
Ensure numeric parameters are integers, e.g., `limit=10`.
pylast.WSError: The service is temporarily unavailable. Please try again.
Last.fm API rate limiting or temporary outage.
fix
Wait a few seconds and retry the request. Implement exponential backoff in your code.
Upgrade
Version history
7.0.2latest on PyPI · released Jan 19, 2026
Audit
Dependencies
httpxrequiredHTTP client for API requests
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
pylast — pip install pylast · libregistry