A Python interface to Last.fm and Libre.fm
Find a file
Edward Betts 5eca8f556b Include tests in release source tarball
A test suite is a very useful thing, it would be great to include it in the pypi release tarball. That way people who download and build the release can run the tests to ensure the library is working.

Linux distributions, such as Debian, base their packages of Python modules on the pypi release. This means the test suite can be run when building a Debian package, and so catch mistakes in the packaging or errors introduced into dependencies.

I've written some more on this topic on the Debian Python mailing list: https://lists.debian.org/debian-python/2016/04/msg00074.html
2016-04-23 10:22:51 +01:00
pylast Release 1.5.1 2015-12-10 21:08:46 +02:00
tests Failing test for #146 2015-09-07 23:55:22 +03:00
.editorconfig Add YAML rules [CI skip] 2015-12-10 09:06:25 +02:00
.gitignore remove dir-locals. make clonedigger always exit 0 2015-01-08 23:13:38 -08:00
.scrutinizer.yml Add pypy3; track coverage in Scrutinizer 2014-12-26 17:16:41 +02:00
.travis.yml Fix tox==2.1.1 2015-12-10 00:44:17 +02:00
clonedigger.sh fix grep filter for clonedigger. 2015-01-08 23:23:29 -08:00
COPYING Import pylast-0.5.11 2012-03-10 14:50:47 +01: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 Add licence 2015-04-12 19:51:11 +03:00
MANIFEST.in Include tests in release source tarball 2016-04-23 10:22:51 +01:00
README.md Remove useless Scrutinizer badge 2015-06-16 23:21:42 +03:00
RELEASING.md Check installation sooner [CI skip] 2015-09-07 15:41:30 +03:00
setup.py Release 1.5.1 2015-12-10 21:08:46 +02:00
tox.ini Let Tox use these env vars 2015-08-03 13:54:21 +03:00

pyLast

Build Status PyPI version PyPI downloads Coverage Status Code Health

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

Try using the pydoc utility for help on usage or see test_pylast.py for examples.

Installation

Install via pip:

pip install pylast

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 a 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 http://www.last.fm/api/account 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 test_pylast.py.

Testing

tests/test_pylast.py contains integration tests with Last.fm, and plenty of code examples. Unit tests are also in the tests/ directory.

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

Or run just one test case:

py.test -k test_scrobble

To run with coverage:

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