A Python interface to Last.fm and Libre.fm
Find a file
2014-03-05 10:29:16 +02:00
.build Update .build 2014-02-26 19:55:48 +02:00
.gitignore Implement artist/album/track.getPlaylinks, closes #74 2014-03-05 00:41:26 +02:00
.travis.yml Attempt coverage with coveralls 2014-03-02 18:55:32 +02: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
MANIFEST.in Allow getting venue info through Event.get_venue() as a workaround until 2013-12-26 23:16:55 +00:00
pylast.py Refactor to include limit parameter to reduce bandwidth\n\nRefactor calls to chart.getTopArtists, chart.getTopTracks, tag.getTopTags and user.getTopTags to include the limit parameter (where available) to reduce the size of data sent by Last.fm.\n\nFor example, getting limit=1 can reduce receiving 101 items to 1, making the test take 0.5s rather than 1.2s.\n\nAlso return a list of TopItems rather than just items, and add cacheable parameter. 2014-03-05 10:29:16 +02:00
README.md Update README.md 2014-03-04 23:04:50 +02:00
requirements.txt Move secrets out to test_pylast.yaml and provide an example. 2014-03-01 12:59:07 +02:00
setup.py Update setup.py 2014-02-26 19:55:37 +02:00
test_pylast.py Refactor to include limit parameter to reduce bandwidth\n\nRefactor calls to chart.getTopArtists, chart.getTopTracks, tag.getTopTags and user.getTopTags to include the limit parameter (where available) to reduce the size of data sent by Last.fm.\n\nFor example, getting limit=1 can reduce receiving 101 items to 1, making the test take 0.5s rather than 1.2s.\n\nAlso return a list of TopItems rather than just items, and add cacheable parameter. 2014-03-05 10:29:16 +02:00

pyLast

Build Status Coverage Status

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.

Original code can be found at http://code.google.com/p/pylast/ but hasn't been updated since 2011.

Installation

The old 0.5 version from 2011 is in PyPI so if you have it installed remove it first:

pip uninstall pylast

You can install this version with pip like this:

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

Or just copy pylast.py to somewhere your Python can see it. No other dependencies are needed.

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).
  • No extra dependencies but Python itself.
  • 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

test_pylast.py contains integration tests with Last.fm, and plenty of code examples.

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

Then:

pip install pyyaml
./test_pylast.py

To run with coverage:

pip install coverage
coverage run --source=pylast ./test_pylast.py
coverage report # for command-line report
coverage html   # for HTML report
open htmlcov/index.html