Name | pylast JSON |
Version |
5.2.0
JSON |
| download |
home_page | |
Summary | A Python interface to Last.fm and Libre.fm |
upload_time | 2023-06-06 16:28:42 |
maintainer | Hugo van Kemenade |
docs_url | None |
author | |
requires_python | >=3.8 |
license | Apache-2.0 |
keywords |
last.fm
music
scrobble
scrobbling
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pyLast
[![PyPI version](https://img.shields.io/pypi/v/pylast.svg)](https://pypi.org/project/pylast/)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/pylast.svg)](https://pypi.org/project/pylast/)
[![PyPI downloads](https://img.shields.io/pypi/dm/pylast.svg)](https://pypistats.org/packages/pylast)
[![Test](https://github.com/pylast/pylast/workflows/Test/badge.svg)](https://github.com/pylast/pylast/actions)
[![Coverage (Codecov)](https://codecov.io/gh/pylast/pylast/branch/main/graph/badge.svg)](https://codecov.io/gh/pylast/pylast)
[![Code style: Black](https://img.shields.io/badge/code%20style-Black-000000.svg)](https://github.com/psf/black)
[![DOI](https://zenodo.org/badge/7803088.svg)](https://zenodo.org/badge/latestdoi/7803088)
A Python interface to [Last.fm](https://www.last.fm/) and other API-compatible websites
such as [Libre.fm](https://libre.fm/).
Use the pydoc utility for help on usage or see [tests/](tests/) for examples.
## Installation
Install via pip:
```sh
python3 -m pip install pylast
```
Install latest development version:
```sh
python3 -m pip install -U git+https://github.com/pylast/pylast
```
Or from requirements.txt:
```txt
-e https://github.com/pylast/pylast.git#egg=pylast
```
Note:
* pyLast 5.2+ supports Python 3.8-3.12.
* pyLast 5.1 supports Python 3.7-3.11.
* pyLast 5.0 supports Python 3.7-3.10.
* pyLast 4.3 - 4.5 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:
```python
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,
)
```
Alternatively, instead of creating `network` with a username and password,
you can authenticate with a session key:
```python
import pylast
SESSION_KEY_FILE = os.path.join(os.path.expanduser("~"), ".session_key")
network = pylast.LastFMNetwork(API_KEY, API_SECRET)
if not os.path.exists(SESSION_KEY_FILE):
skg = pylast.SessionKeyGenerator(network)
url = skg.get_web_auth_url()
print(f"Please authorize this script to access your account: {url}\n")
import time
import webbrowser
webbrowser.open(url)
while True:
try:
session_key = skg.get_web_auth_session_key(url)
with open(SESSION_KEY_FILE, "w") as f:
f.write(session_key)
break
except pylast.WSError:
time.sleep(1)
else:
session_key = open(SESSION_KEY_FILE).read()
network.session_key = session_key
```
And away we go:
```python
# 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
<a href="https://github.com/hugovk/lastfm-tools">hugovk/lastfm-tools</a> and
[tests/](https://github.com/pylast/pylast/tree/main/tests).
## Testing
The [tests/](https://github.com/pylast/pylast/tree/main/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](example_test_pylast.yaml) to test_pylast.yaml and fill out
the credentials, or set them as environment variables like:
```sh
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:
```sh
python3 -m pip install -e ".[tests]"
pytest
```
Or run just one test case:
```sh
pytest -k test_scrobble
```
To run with coverage:
```sh
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:
```python
import logging
import pylast
logging.basicConfig(level=logging.INFO)
network = pylast.LastFMNetwork(...)
```
To enable from pytest:
```sh
pytest --log-cli-level info -k test_album_search_images
```
To also see data returned from the API, use `level=logging.DEBUG` or
`--log-cli-level debug` instead.
Raw data
{
"_id": null,
"home_page": "",
"name": "pylast",
"maintainer": "Hugo van Kemenade",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Last.fm,music,scrobble,scrobbling",
"author": "",
"author_email": "\"Amr Hassan <amr.hassan@gmail.com> and Contributors\" <amr.hassan@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c0/0e/da064214d2595dc0dedc6db11379b961cdc128054728cd4f81830ff925b5/pylast-5.2.0.tar.gz",
"platform": null,
"description": "# pyLast\n\n[![PyPI version](https://img.shields.io/pypi/v/pylast.svg)](https://pypi.org/project/pylast/)\n[![Supported Python versions](https://img.shields.io/pypi/pyversions/pylast.svg)](https://pypi.org/project/pylast/)\n[![PyPI downloads](https://img.shields.io/pypi/dm/pylast.svg)](https://pypistats.org/packages/pylast)\n[![Test](https://github.com/pylast/pylast/workflows/Test/badge.svg)](https://github.com/pylast/pylast/actions)\n[![Coverage (Codecov)](https://codecov.io/gh/pylast/pylast/branch/main/graph/badge.svg)](https://codecov.io/gh/pylast/pylast)\n[![Code style: Black](https://img.shields.io/badge/code%20style-Black-000000.svg)](https://github.com/psf/black)\n[![DOI](https://zenodo.org/badge/7803088.svg)](https://zenodo.org/badge/latestdoi/7803088)\n\nA Python interface to [Last.fm](https://www.last.fm/) and other API-compatible websites\nsuch as [Libre.fm](https://libre.fm/).\n\nUse the pydoc utility for help on usage or see [tests/](tests/) for examples.\n\n## Installation\n\nInstall via pip:\n\n```sh\npython3 -m pip install pylast\n```\n\nInstall latest development version:\n\n```sh\npython3 -m pip install -U git+https://github.com/pylast/pylast\n```\n\nOr from requirements.txt:\n\n```txt\n-e https://github.com/pylast/pylast.git#egg=pylast\n```\n\nNote:\n\n* pyLast 5.2+ supports Python 3.8-3.12.\n* pyLast 5.1 supports Python 3.7-3.11.\n* pyLast 5.0 supports Python 3.7-3.10.\n* pyLast 4.3 - 4.5 supports Python 3.6-3.10.\n* pyLast 4.0 - 4.2 supports Python 3.6-3.9.\n* pyLast 3.2 - 3.3 supports Python 3.5-3.8.\n* pyLast 3.0 - 3.1 supports Python 3.5-3.7.\n* pyLast 2.2 - 2.4 supports Python 2.7.10+, 3.4-3.7.\n* pyLast 2.0 - 2.1 supports Python 2.7.10+, 3.4-3.6.\n* pyLast 1.7 - 1.9 supports Python 2.7, 3.3-3.6.\n* pyLast 1.0 - 1.6 supports Python 2.7, 3.3-3.4.\n* pyLast 0.5 supports Python 2, 3.\n* pyLast < 0.5 supports Python 2.\n\n## Features\n\n * Simple public interface.\n * Access to all the data exposed by the Last.fm web services.\n * Scrobbling support.\n * Full object-oriented design.\n * Proxy support.\n * Internal caching support for some web services calls (disabled by default).\n * Support for other API-compatible networks like Libre.fm.\n\n\n## Getting started\n\nHere's some simple code example to get you started. In order to create any object from\npyLast, you need a `Network` object which represents a social music network that is\nLast.fm or any other API-compatible one. You can obtain a pre-configured one for Last.fm\nand use it as follows:\n\n```python\nimport pylast\n\n# You have to have your own unique two values for API_KEY and API_SECRET\n# Obtain yours from https://www.last.fm/api/account/create for Last.fm\nAPI_KEY = \"b25b959554ed76058ac220b7b2e0a026\" # this is a sample key\nAPI_SECRET = \"425b55975eed76058ac220b7b4e8a054\"\n\n# In order to perform a write operation you need to authenticate yourself\nusername = \"your_user_name\"\npassword_hash = pylast.md5(\"your_password\")\n\nnetwork = pylast.LastFMNetwork(\n api_key=API_KEY,\n api_secret=API_SECRET,\n username=username,\n password_hash=password_hash,\n)\n```\n\nAlternatively, instead of creating `network` with a username and password,\nyou can authenticate with a session key:\n\n```python\nimport pylast\n\nSESSION_KEY_FILE = os.path.join(os.path.expanduser(\"~\"), \".session_key\")\nnetwork = pylast.LastFMNetwork(API_KEY, API_SECRET)\nif not os.path.exists(SESSION_KEY_FILE):\n skg = pylast.SessionKeyGenerator(network)\n url = skg.get_web_auth_url()\n\n print(f\"Please authorize this script to access your account: {url}\\n\")\n import time\n import webbrowser\n\n webbrowser.open(url)\n\n while True:\n try:\n session_key = skg.get_web_auth_session_key(url)\n with open(SESSION_KEY_FILE, \"w\") as f:\n f.write(session_key)\n break\n except pylast.WSError:\n time.sleep(1)\nelse:\n session_key = open(SESSION_KEY_FILE).read()\n\nnetwork.session_key = session_key\n```\n\nAnd away we go:\n\n```python\n# Now you can use that object everywhere\ntrack = network.get_track(\"Iron Maiden\", \"The Nomad\")\ntrack.love()\ntrack.add_tags((\"awesome\", \"favorite\"))\n\n# Type help(pylast.LastFMNetwork) or help(pylast) in a Python interpreter\n# to get more help about anything and see examples of how it works\n```\n\n\nMore examples in\n<a href=\"https://github.com/hugovk/lastfm-tools\">hugovk/lastfm-tools</a> and\n[tests/](https://github.com/pylast/pylast/tree/main/tests).\n\n## Testing\n\nThe [tests/](https://github.com/pylast/pylast/tree/main/tests) directory contains\nintegration and unit tests with Last.fm, and plenty of code examples.\n\nFor integration tests you need a test account at Last.fm that will become cluttered with\ntest data, and an API key and secret. Either copy\n[example_test_pylast.yaml](example_test_pylast.yaml) to test_pylast.yaml and fill out\nthe credentials, or set them as environment variables like:\n\n```sh\nexport PYLAST_USERNAME=TODO_ENTER_YOURS_HERE\nexport PYLAST_PASSWORD_HASH=TODO_ENTER_YOURS_HERE\nexport PYLAST_API_KEY=TODO_ENTER_YOURS_HERE\nexport PYLAST_API_SECRET=TODO_ENTER_YOURS_HERE\n```\n\nTo run all unit and integration tests:\n\n```sh\npython3 -m pip install -e \".[tests]\"\npytest\n```\n\nOr run just one test case:\n\n```sh\npytest -k test_scrobble\n```\n\nTo run with coverage:\n\n```sh\npytest -v --cov pylast --cov-report term-missing\ncoverage report # for command-line report\ncoverage html # for HTML report\nopen htmlcov/index.html\n```\n\n## Logging\n\nTo enable from your own code:\n\n```python\nimport logging\nimport pylast\n\nlogging.basicConfig(level=logging.INFO)\n\n\nnetwork = pylast.LastFMNetwork(...)\n```\n\nTo enable from pytest:\n\n```sh\npytest --log-cli-level info -k test_album_search_images\n```\n\nTo also see data returned from the API, use `level=logging.DEBUG` or\n`--log-cli-level debug` instead.\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A Python interface to Last.fm and Libre.fm",
"version": "5.2.0",
"project_urls": {
"Changelog": "https://github.com/pylast/pylast/releases",
"Homepage": "https://github.com/pylast/pylast",
"Source": "https://github.com/pylast/pylast"
},
"split_keywords": [
"last.fm",
"music",
"scrobble",
"scrobbling"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e9b42313379b9edaffcb4e604eee1122a824994fc9fc039d37a165c0f5370330",
"md5": "43bd260c854ba98c038249610aaeb74c",
"sha256": "89c7c01ea9f08c83865999d8907835157a8096e77dd9dc23420246eb66cfcff5"
},
"downloads": -1,
"filename": "pylast-5.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "43bd260c854ba98c038249610aaeb74c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 29008,
"upload_time": "2023-06-06T16:28:40",
"upload_time_iso_8601": "2023-06-06T16:28:40.914084Z",
"url": "https://files.pythonhosted.org/packages/e9/b4/2313379b9edaffcb4e604eee1122a824994fc9fc039d37a165c0f5370330/pylast-5.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c00eda064214d2595dc0dedc6db11379b961cdc128054728cd4f81830ff925b5",
"md5": "3c4675ffe7beef16269ac808e022ace1",
"sha256": "bb046804ef56a0c18072c750d61a282d47ac102a3b0b9c44a023eaf5b0934b0a"
},
"downloads": -1,
"filename": "pylast-5.2.0.tar.gz",
"has_sig": false,
"md5_digest": "3c4675ffe7beef16269ac808e022ace1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 41137,
"upload_time": "2023-06-06T16:28:42",
"upload_time_iso_8601": "2023-06-06T16:28:42.931190Z",
"url": "https://files.pythonhosted.org/packages/c0/0e/da064214d2595dc0dedc6db11379b961cdc128054728cd4f81830ff925b5/pylast-5.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-06 16:28:42",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pylast",
"github_project": "pylast",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "pylast"
}