Skip to main content

A Python interface to and

Project description


PyPI version Supported Python versions PyPI downloads Test Coverage (Codecov) Code style: Black DOI

A Python interface to and other API-compatible websites such as

Use the pydoc utility for help on usage or see tests/ for examples.


Install via pip:

python3 -m pip install pylast

Install latest development version:

python3 -m pip install -U git+

Or from requirements.txt:



  • pyLast 5.2+ supports Python 3.8-3.12.
  • pyLast 5.1 supports Python 3.7-3.11.
  • pyLast 5.0 supports Python 3.7-3.10.
  • pyLast 4.3 - 4.5 supports Python 3.6-3.10.
  • pyLast 4.0 - 4.2 supports Python 3.6-3.9.
  • pyLast 3.2 - 3.3 supports Python 3.5-3.8.
  • pyLast 3.0 - 3.1 supports Python 3.5-3.7.
  • pyLast 2.2 - 2.4 supports Python 2.7.10+, 3.4-3.7.
  • pyLast 2.0 - 2.1 supports Python 2.7.10+, 3.4-3.6.
  • pyLast 1.7 - 1.9 supports Python 2.7, 3.3-3.6.
  • pyLast 1.0 - 1.6 supports Python 2.7, 3.3-3.4.
  • pyLast 0.5 supports Python 2, 3.
  • pyLast < 0.5 supports Python 2.


  • Simple public interface.
  • Access to all the data exposed by the web services.
  • Scrobbling support.
  • Full object-oriented design.
  • Proxy support.
  • Internal caching support for some web services calls (disabled by default).
  • Support for other API-compatible networks like

Getting started

Here's some simple code example to get you started. In order to create any object from pyLast, you need a Network object which represents a social music network that is or any other API-compatible one. You can obtain a pre-configured one for and use it as follows:

import pylast

# You have to have your own unique two values for API_KEY and API_SECRET
# Obtain yours from for
API_KEY = "b25b959554ed76058ac220b7b2e0a026"  # this is a sample key
API_SECRET = "425b55975eed76058ac220b7b4e8a054"

# In order to perform a write operation you need to authenticate yourself
username = "your_user_name"
password_hash = pylast.md5("your_password")

network = pylast.LastFMNetwork(

Alternatively, instead of creating network with a username and password, you can authenticate with a session key:

import pylast

SESSION_KEY_FILE = os.path.join(os.path.expanduser("~"), ".session_key")
network = pylast.LastFMNetwork(API_KEY, API_SECRET)
if not os.path.exists(SESSION_KEY_FILE):
    skg = pylast.SessionKeyGenerator(network)
    url = skg.get_web_auth_url()

    print(f"Please authorize this script to access your account: {url}\n")
    import time
    import webbrowser

    while True:
            session_key = skg.get_web_auth_session_key(url)
            with open(SESSION_KEY_FILE, "w") as f:
        except pylast.WSError:
    session_key = open(SESSION_KEY_FILE).read()

network.session_key = session_key

And away we go:

# Now you can use that object everywhere
track = network.get_track("Iron Maiden", "The Nomad")
track.add_tags(("awesome", "favorite"))

# Type help(pylast.LastFMNetwork) or help(pylast) in a Python interpreter
# to get more help about anything and see examples of how it works

More examples in hugovk/lastfm-tools and tests/.


The tests/ directory contains integration and unit tests with, and plenty of code examples.

For integration tests you need a test account at that will become cluttered with test data, and an API key and secret. Either copy example_test_pylast.yaml to test_pylast.yaml and fill out the credentials, or set them as environment variables like:


To run all unit and integration tests:

python3 -m pip install -e ".[tests]"

Or run just one test case:

pytest -k test_scrobble

To run with coverage:

pytest -v --cov pylast --cov-report term-missing
coverage report # for command-line report
coverage html   # for HTML report
open htmlcov/index.html


To enable from your own code:

import logging
import pylast


network = pylast.LastFMNetwork(...)

To enable from pytest:

pytest --log-cli-level info -k test_album_search_images

To also see data returned from the API, use level=logging.DEBUG or --log-cli-level debug instead.

Release history Release notifications | RSS feed

This version


Download files

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

Source Distribution

pylast-5.2.0.tar.gz (41.1 kB view hashes)

Uploaded Source

Built Distribution

pylast-5.2.0-py3-none-any.whl (29.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page