Skip to main content

A Python interface to Last.fm and Libre.fm

Project description

pyLast

PyPI version Supported Python versions PyPI downloads Build status Coverage (Codecov) Coverage (Coveralls) Code style: black

A Python interface to Last.fm and other API-compatible websites such as Libre.fm.

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

Installation

Install via pip:

pip install pylast

Install latest development version:

pip install -U git+https://github.com/pylast/pylast

Or from requirements.txt:

-e git://github.com/pylast/pylast.git#egg=pylast

Note:

  • pylast 3.0.0+ supports Python 3.5+ (#265)
  • pyLast 2.2.0 - 2.4.0 supports Python 2.7.10+, 3.4, 3.5, 3.6, 3.7.
  • pyLast 2.0.0 - 2.1.0 supports Python 2.7.10+, 3.4, 3.5, 3.6.
  • pyLast 1.7.0 - 1.9.0 supports Python 2.7, 3.3, 3.4, 3.5, 3.6.
  • pyLast 1.0.0 - 1.6.0 supports Python 2.7, 3.3, 3.4.
  • pyLast 0.5 supports Python 2, 3.
  • pyLast < 0.5 supports Python 2.

Features

  • Simple public interface.
  • Access to all the data exposed by the Last.fm 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 Libre.fm.
  • Python 3-friendly (Starting from 0.5).

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 Last.fm or any other API-compatible one. You can obtain a pre-configured one for Last.fm 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 https://www.last.fm/api/account/create for Last.fm
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(api_key=API_KEY, api_secret=API_SECRET,
                               username=username, password_hash=password_hash)

# Now you can use that object everywhere
artist = network.get_artist("System of a Down")
artist.shout("<3")


track = network.get_track("Iron Maiden", "The Nomad")
track.love()
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/.

Testing

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

For integration tests you need a test account at Last.fm 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:

export PYLAST_USERNAME=TODO_ENTER_YOURS_HERE
export PYLAST_PASSWORD_HASH=TODO_ENTER_YOURS_HERE
export PYLAST_API_KEY=TODO_ENTER_YOURS_HERE
export PYLAST_API_SECRET=TODO_ENTER_YOURS_HERE

To run all unit and integration tests:

pip install pytest flaky
pytest

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

Logging

To enable from your own code:

import logging
import pylast

logging.basicConfig(level=logging.DEBUG)

network = pylast.LastFMNetwork(...)

To enable from pytest:

pytest --log-cli-level debug -k test_album_search_images

Project details


Release history Release notifications | RSS feed

This version

3.2.0

Download files

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

Source Distribution

pylast-3.2.0.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

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

pylast-3.2.0-py2.py3-none-any.whl (28.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pylast-3.2.0.tar.gz.

File metadata

  • Download URL: pylast-3.2.0.tar.gz
  • Upload date:
  • Size: 42.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for pylast-3.2.0.tar.gz
Algorithm Hash digest
SHA256 87c433ac63b592c92a5e8d5176fc8b65794ca239f7e295e6e46851e0c67b11d5
MD5 1a127ca5af050d8830f08cefe3a74d19
BLAKE2b-256 85159d85a52b9d5700ce2d7b19b391225e47dc218db3aeb51f059c41157925f5

See more details on using hashes here.

File details

Details for the file pylast-3.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: pylast-3.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.0

File hashes

Hashes for pylast-3.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fd92e969fc7dafb2b693e7124ed6cd6c4fc3382c9eaa273025a845f9410ddcd5
MD5 5b4b7e129a9af6db54761afafa0a4ff0
BLAKE2b-256 f5d97ca6f3f9f5687e3f5ae03bf60e502a8a154409b04f4edcfc34b618ca485e

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