{"id":21758,"library":"pylast","title":"pylast","description":"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.","status":"active","version":"7.0.2","language":"python","source_language":"en","source_url":"https://github.com/pylast/pylast","tags":["last.fm","libre.fm","scrobbling","music","api"],"install":[{"cmd":"pip install pylast","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"HTTP client for API requests","package":"httpx","optional":false}],"imports":[{"note":"LastFMNetwork is a class, not a module; direct import leads to AttributeError.","wrong":"import pylast.LastFMNetwork","symbol":"LastFMNetwork","correct":"from pylast import LastFMNetwork"},{"note":"Same as others; classes are not submodules.","wrong":"import pylast.Track","symbol":"Track","correct":"from pylast import Track"},{"note":"","wrong":"","symbol":"Album","correct":"from pylast import Album"},{"note":"","wrong":"","symbol":"Artist","correct":"from pylast import Artist"},{"note":"","wrong":"","symbol":"User","correct":"from pylast import User"}],"quickstart":{"code":"from pylast import LastFMNetwork\n\napi_key = os.environ.get('LASTFM_API_KEY', '')\napi_secret = os.environ.get('LASTFM_API_SECRET', '')\nnetwork = LastFMNetwork(api_key=api_key, api_secret=api_secret)\n\n# Get top tracks for a user\ntry:\n    user = network.get_user('RJ')\n    top_tracks = user.get_top_tracks(limit=3)\n    for track in top_tracks:\n        print(track.item)\nexcept Exception as e:\n    print(f\"Error: {e}\")","lang":"python","description":"Initialize LastFMNetwork with API credentials and fetch top tracks for a user."},"warnings":[{"fix":"If you were using `http.client` or relying on `urllib3` behavior, you must migrate to httpx proxy configuration.","message":"In version 5.0.0, the HTTP library changed from `http.client` to `httpx`. Custom session handling or proxies must be adapted.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Check for `isinstance(network.proxy, dict)` instead of expecting a string.","message":"In version 6.0.0, proxy support was restored but the `network.proxy` attribute is now always a `dict` (previously could be `str` or `dict`).","severity":"breaking","affected_versions":"6.0.0 and later"},{"fix":"Replace `SCROBBLE_SOURCE_USER` etc. with the `chosen_by_user` boolean parameter in `scrobble` calls.","message":"In version 7.0.0, `SCROBBLE_SOURCE_*` and `SCROBBLE_MODE_*` constants were removed. Use `chosen_by_user` parameter instead.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Use `for top_item in user.get_top_tracks(): track = top_item.item`.","message":"The `get_top_tracks()` and similar methods return `TopItem` objects, not `Track` objects. Access the actual track via `.item`.","severity":"gotcha","affected_versions":"all"},{"fix":"See the authentication example in the README: generate token, get session key, then create `LastFMNetwork(api_key, api_secret, session_key)`.","message":"When using session key authentication, you must call `network.get_session_key()` with the token first. Many users forget this step.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the `streamable` attribute on Track objects instead.","message":"In version 5.0.0, `is_streamable` and `is_fulltrack_available` were removed.","severity":"deprecated","affected_versions":">=5.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `from pylast import LastFMNetwork`.","cause":"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.","error":"AttributeError: module 'pylast' has no attribute 'LastFMNetwork'"},{"fix":"Register at https://www.last.fm/api/account/create and use that key. Double-check you are using the correct key and secret.","cause":"You provided an API key that is not valid or not active for Last.fm.","error":"pylast.WSError: Invalid API Key"},{"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.","cause":"Network issue, proxy problem, or DNS failure. Also can happen if proxy configuration is wrong.","error":"httpx.ConnectError: All connection attempts failed"},{"fix":"Ensure numeric parameters are integers, e.g., `limit=10`.","cause":"Passing a string where integer expected, e.g., `limit=\"10\"` instead of `limit=10`.","error":"TypeError: 'str' object cannot be interpreted as an integer"},{"fix":"Wait a few seconds and retry the request. Implement exponential backoff in your code.","cause":"Last.fm API rate limiting or temporary outage.","error":"pylast.WSError: The service is temporarily unavailable. Please try again."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}