Skip to main content
                                                       pyscrobble

pyscrobble is a Python library for interacting with the Last.fm API. It allows you to fetch detailed information about artists, albums, tracks, and users. The library includes rate limiting to avoid exceeding API usage limits and supports various Last.fm endpoints.

Installation

You can install pyscrobble via pip:

pip install pyscrobble

Usage

Here is how to use the pyscrobble library to interact with the Last.fm API:

Importing the Library

from pyscrobble import Handler

Initializing the Handler

api_key = 'your_lastfm_api_key'
handler = Handler(api_key)

Fetching Artist Information

artist = handler.get_artist('Radiohead')
print(artist)

Fetching Album Information

album = handler.get_album('OK Computer', 'Radiohead')
print(album)

Fetching Track Information

track = handler.get_track('Creep', 'Radiohead')
print(track)

Fetching User Information

user = handler.get_user('someusername')
print(user)

Fetching Top Artists for a User

top_artists = handler.get_top_artists('someusername')
for artist in top_artists:
    print(artist)

Example with a Discord Bot

Here’s a simple example of how to use pyscrobble in a Discord bot using discord.py:

import discord
from discord.ext import commands
from pyscrobble import Handler

# Initialize the bot
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)

# Initialize the Handler with your Last.fm API key
api_key = 'your_lastfm_api_key'
handler = Handler(api_key)

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user.name}')

@bot.command(name='artist')
async def fetch_artist(ctx, artist_name: str):
    try:
        artist = handler.get_artist(artist_name)
        await ctx.send(f"Artist: {artist.name}\nBio: {artist.bio}")
    except Exception as e:
        await ctx.send(f"Error: {str(e)}")

@bot.command(name='album')
async def fetch_album(ctx, album_name: str, artist_name: str):
    try:
        album = handler.get_album(album_name, artist_name)
        await ctx.send(f"Album: {album.title}\nArtist: {album.artist.name}\nRelease Date: {album.release_date}\nURL: {album.url}")
    except Exception as e:
        await ctx.send(f"Error: {str(e)}")

@bot.command(name='track')
async def fetch_track(ctx, track_name: str, artist_name: str):
    try:
        track = handler.get_track(track_name, artist_name)
        await ctx.send(f"Track: {track.title}\nArtist: {track.artist.name}\nAlbum: {track.album.title}\nDuration: {track.duration} seconds\nURL: {track.url}")
    except Exception as e:
        await ctx.send(f"Error: {str(e)}")

# Run the bot with your Discord token
bot.run('your_discord_bot_token')

Methods

get_artist(artist_name)

Fetches information about an artist.

get_album(album_name, artist_name)

Fetches information about an album.

get_track(track_name, artist_name)

Fetches information about a track.

get_user(user_name)

Fetches information about a user.

get_top_artists(user_name, period='overall')

Fetches the top artists for a user for a specified period.

get_top_albums(user_name, period='overall')

Fetches the top albums for a user for a specified period.

get_top_tracks(user_name, period='overall')

Fetches the top tracks for a user for a specified period.

get_friends(user_name)

Fetches a list of friends for a user.

get_neighbours(user_name)

Fetches a list of neighbours for a user.

get_now_playing(user_name)

Fetches the currently playing track for a user.

get_recent_tracks(user_name)

Fetches recent tracks listened to by a user.

get_loved_tracks(user_name)

Fetches tracks that a user has loved.

get_attended_events(user_name)

Fetches events attended by a user.

get_shouts(user_name)

Fetches shouts (user comments) for a user.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Replace placeholders like your_package_name, your_lastfm_api_key, and your_discord_bot_token with your actual package name and credentials.

Release files for pyscrobble 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyscrobble 0.0.4
File Size Uploaded
pyscrobble-0.0.4.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyscrobble 0.0.4
File Interpreter ABI Platform
pyscrobble-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.1 kB

Release files / pyscrobble-0.0.4.tar.gz

Download URL pyscrobble-0.0.4.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e6693851ccea1cd5df451f920ebf5143d81980153a5a28518ec270c6e22f3bcb
BLAKE2b-256 checksum
How to use checksums
6f63858ca7fde4870b15c60c9a3adf36f174a30cb4446ab4e0ceb265754b7d78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / pyscrobble-0.0.4-py3-none-any.whl

Download URL pyscrobble-0.0.4-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f603bd5144e7f2d605015fa47a86f78e221202c878728d9492c6891662edee59
BLAKE2b-256 checksum
How to use checksums
cafc169d22e4bfa90aba1f0a3f5611c0e840ac58bd602b76f43b03814607a07f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page