Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lastfmget

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lastfmget

Last.fm API for retrieving scrobbling data.

  • 1.1.0
  • PyPI
  • Socket score

Maintainers
1

LastFmGet

PyPI Latest Release Tests Current Source Tests

LastFmGet is a Python package for accessing Last.fm scrobble data using the public API.

  • Provides functions for calling specific Last.fm API methods
  • Must use a cfg YAML file and call lastfmget.init() before use
  • Gets a response from the API in JSON and returns a Python dictionary
  • Examples of the response for each method shown in data/dump
  • Use _raw method verions for more direct access to the Last.fm API

Installation

pip install lastfmget

Dependencies

  • python3.10
  • requests
  • requests_cache (used only if configured in api_cfg.yaml)
  • pyyaml

Documentation

lastfmget

Usage

Import

import lastfmget

Config

lastfmget.init('api_cfg.yaml')

api_cfg.yaml example (data/example_api_cfg.yaml)
api_url: http://ws.audioscrobbler.com/2.0/
api_key: <API KEY>
user_agent: <USER AGENT>
call_rate: 5 # Calls per second
cache:
  enable: true
  dir: .cache
  backend: sqlite
  lifetime: 120 # Seconds
# or (defaults)
cache:
  enable: true
# or (disable)
cache:
  enable: false
FieldDescription
api_urlAPI root URL, should be 'http://ws.audioscrobbler.com/2.0/'
api_keyYour private API key. See here
user_agentIdentifiable user agent for requests
call_rateMax API requests per second
cacheenable: use requests_cache
dir: (optional) cache location
backend: (optional) sqlite recommended
lifetime: (optional) expire_after time in seconds

Code Examples

Getting user information using the user.getInfo method
>>> info = lastfmget.user_info('D3r3k523')
>>> info['playcount']
161602
>>> info['user']['url']
'https://www.last.fm/user/D3r3k523'
Getting a user's top 10 artists using the user.getTopArtists method
>>> topartists = lastfmget.user_top_artists('D3r3k523', 10)
>>> [ artist['name'] for artist in topartists ]
['Radiohead', 'Converge', 'Pink Floyd', 'Queens of the Stone Age', 'Bon Iver', 'Thee Oh Sees', 'Tame Impala', 'Arcade Fire', 'Beach House', 'Mastodon']

Example Projects

Last.fm API Methods Available

FunctionLast.fm API method
lastfmget.user_infouser.getInfo
lastfmget.user_recent_tracksuser.getRecentTracks
lastfmget.user_top_artistsuser.getTopArtists
lastfmget.user_top_albumsuser.getTopAlbums
lastfmget.user_top_tracksuser.getTopTracks
lastfmget.user_weekly_chart_listuser.getWeeklyChartList
lastfmget.user_weekly_artist_chartuser.getWeeklyArtistChart
lastfmget.user_weekly_album_chartuser.getWeeklyAlbumChart
lastfmget.user_weekly_track_chartuser.getWeeklyTrackChart

Last.fm API Reference

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc