A Python interface to Last.fm and Libre.fm
Project description
pyLast
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:
python3 -m pip install pylast
Install latest development version:
python3 -m pip install -U git+https://github.com/pylast/pylast
Or from requirements.txt:
-e git://github.com/pylast/pylast.git#egg=pylast
Note:
- pyLast 4.3+ 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.
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.
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
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:
python3 -m pip install -e ".[tests]"
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pylast-4.3.0.tar.gz
.
File metadata
- Download URL: pylast-4.3.0.tar.gz
- Upload date:
- Size: 43.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71fd876e3753009bd10ea55b3f8f7c5d68591ee18a4127d257fc4a418010aa5c |
|
MD5 | d055b44bb9c2fe1c4b1805edf623bb56 |
|
BLAKE2b-256 | 609f02a502a27ffe1d4f12c69efa6f860985ba4477c23cd4bb184efce7da4846 |
Provenance
File details
Details for the file pylast-4.3.0-py3-none-any.whl
.
File metadata
- Download URL: pylast-4.3.0-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45ba09bc463d5e2e03f8ac1e7b0a98811b0aee4a4b9cebb2acdd378a9fd935c6 |
|
MD5 | fc338f3f08a265299b710df2c816b1ed |
|
BLAKE2b-256 | bf9edac4c6e124dbac7e6c6165b71046e1b72a4bfa259a81724fa96f32f3a580 |