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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.314s · 22MB
glibcpy 3.10–3.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}")
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.
fixUse `from pylast import LastFMNetwork`.
pylast.WSError: Invalid API Key
You provided an API key that is not valid or not active for Last.fm.
fixRegister 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.
fixCheck 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`.
fixEnsure 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.
fixWait 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