A Python interface to Last.fm and Libre.fm
Find a file
Paddez 7694de346e Store Album Art URLs when you call GetTopAlbums.
GetTopAlbums returns AlbumArt information alongside the TopAlbums.
We should store this in the Album() info variable, so we don't have to follow up with an additional GetInfo() call if we want the Album Art.

Signed-off-by: Paddez <dave@paddez.com>
2019-06-22 22:36:41 +01:00
.github Add issue and PR templates 2018-02-08 14:14:25 +02:00
src/pylast Store Album Art URLs when you call GetTopAlbums. 2019-06-22 22:36:41 +01:00
tests Store Album Art URLs when you call GetTopAlbums. 2019-06-22 22:36:41 +01:00
.codecov.yml Codecov: Avoid "Missing base report" [CI skip] 2018-03-01 11:47:03 +02:00
.editorconfig Add YAML rules [CI skip] 2015-12-10 09:06:25 +02:00
.gitignore Ignore new '.pytest_cache' directory 2018-04-11 11:25:42 +03:00
.scrutinizer.yml Add pypy3; track coverage in Scrutinizer 2014-12-26 17:16:41 +02:00
.travis.yml Update encrypted password 2019-02-03 20:56:42 +02:00
CHANGELOG.md Start new release cycle 2019-03-07 09:44:45 +02:00
COPYING http -> https 2017-10-24 00:11:49 +03:00
example_test_pylast.yaml Rename test_pylast_example.yaml -> example_test_pylast.yaml (makes tab-autocompletion happier) 2014-03-03 08:59:36 +02:00
INSTALL Import pylast-0.5.11 2012-03-10 14:50:47 +01:00
LICENSE.txt http -> https [CI skip] 2017-09-18 13:52:19 +03:00
MANIFEST.in Simplify via https://blog.ionelmc.ro/2014/05/25/python-packaging/#the-structure 2019-04-05 10:48:58 +03:00
pytest.ini Show deprecation warnings for tests 2018-04-11 00:19:24 +03:00
README.md Update Black link 2019-05-10 09:03:03 +03:00
RELEASING.md Move production code to src/ 2019-04-05 08:37:01 +03:00
setup.cfg Remove deprecated license_file from setup.cfg 2019-05-10 09:02:53 +03:00
setup.py Move production code to src/ 2019-04-05 08:37:01 +03:00
tox.ini Test in random order to prevent collisions 2019-02-02 13:54:18 +02:00

pyLast

PyPI version Supported Python versions 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 mock
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