Giter Club home page Giter Club logo

lastfmxpy's Introduction

Last FM API (lastfmxpy)

GitHub License GitHub issues GitHub commit activity (branch) GitHub contributors PyPI - Python Version PyPI - Version


  • lastfmxpy (Last FM Api) - is a mono-repository that has a user-friendly interface for interacting with the largest music service last.fm. This library implements all the standard methods available on this page.

Table of contents

Project goals

  • Implement all existing methods in the Last FM API Docs
  • Provide a convenient interface for sending requests to the server
  • Add doc-strings to each method or class
  • Add asynchronous support
  • Add tests
  • Add support for documentation in different languages

Documentation

This documentation provides examples of how to use the synchronous and asynchronous classes and methods, and shows all available methods and parameters

Installation

To install this library, you need to enter the following command

pip install -U lastfmxpy

Example of SYNCHRONOUS usage

In this example, we use the LastFMApi class that we previously imported from the api package, and then use the post method in which we set the method we will use and the parameter

import json

from lastfmxpy import (
    api,
    methods,
    params,
)

# Initialise our object through which we will interact with last.fm
client = api.LastFMApi(
    api_key="...", # Get here https://www.last.fm/api/account/create,
    shared_secret="..." # Also get here ( ̄︶ ̄)↗ 
)

# Get all information about the artist in JSON as a string 
response: str = client.post(
    
    # Specify which method we will use
    method=methods.User.GET_INFO,
    
    # Let us specify our parameters
    params=params.UserGetInfo(
        user="pkeorley"
    ),
    
    # We can also specify additional parameters
    additional_params=dict(format="json")

)

# Let's show our data in a convenient form on the screen
data: str = json.dumps(
    json.loads(response),
    indent=4,
    ensure_ascii=False
)

print(data)

Example of ASYNCHRONOUS usage

In this example, we use the AsyncLastFMApi class, which we previously imported from the api package in the same way as in the case of the previous class, and then use the post method in which we set the method we will use and the parameter

import asyncio
import json

from lastfmxpy import (
    api,
    methods,
    params,
)

# Initialise our object through which we will interact with last.fm
client = api.AsyncLastFMApi(
    api_key="...", # Get here https://www.last.fm/api/account/create,
    shared_secret="..." # Also get here ( ̄︶ ̄)↗ 
)

# Get all information about the artist in JSON as a string 
async def main():
    
    # Calling the asynchronous method
    response: str = await client.post(
        
        # Specify which method we will use
        method=methods.User.GET_INFO,
        
        # Let us specify our parameters
        params=params.UserGetInfo(
            user="pkeorley"
        ),
        
        # We can also specify additional parameters
        additional_params=dict(format="json")
    
    )
    
    # Let's show our data in a convenient form on the screen
    data: str = json.dumps(
        json.loads(response),
        indent=4,
        ensure_ascii=False
    )

    return data

print(asyncio.run(main()))

All available methods:

from lastfmxpy.methods import (
    Album,
    Artist,
    Auth,
    Chart,
    Geo,
    Library,
    Tag,
    Track,
    User
)

All available parameters:

from lastfmxpy.params import (
    AlbumAddTags,
    AlbumGetInfo,
    AlbumGetTags,
    AlbumGetTopTags,
    AlbumRemoveTag,
    AlbumSearch
)

from lastfmxpy.params import (
    AlbumAddTags,
    AlbumGetInfo,
    AlbumGetTags,
    AlbumGetTopTags,
    AlbumRemoveTag,
    AlbumSearch
)
from lastfmxpy.params import (
    ArtistAddTags,
    ArtistGetCorrection,
    ArtistGetInfo,
    ArtistGetSimilar,
    ArtistGetTags,
    ArtistGetTopAlbums,
    ArtistGetTopTags,
    ArtistGetTopTracks,
    ArtistRemoveTag,
    ArtistSearch
)
from lastfmxpy.params import (
    AuthGetMobileSession,  # deprecated as last.fm
    AuthGetSession,
    AuthGetToken
)
from lastfmxpy.params import (
    ChartGetTopArtists,
    ChartGetTopTags,
    ChartGetTopTracks
)
from lastfmxpy.params import (
    GeoGetTopArtists,
    GeoGetTopTracks
)
from lastfmxpy.params import (
    LibraryGetArtists
)
from lastfmxpy.params import (
    TagGetInfo,
    TagGetSimilar,
    TagGetTopAlbums,
    TagGetTopArtists,
    TagGetTopTracks,
    TagGetWeeklyChartList
)
from lastfmxpy.params import (
    TrackAddTags,
    TrackGetCorrection,
    TrackGetInfo,
    TrackGetSimilar,
    TrackGetTags,
    TrackGetTopTags,
    TrackLove,
    TrackRemoveTag,
    TrackScrobble,
    TrackSearch,
    TrackUnlove,
    TrackUpdateNowPlaying
)
from lastfmxpy.params import (
    UserGetFriends,
    UserGetInfo,
    UserGetLovedTracks,
    UserGetPersonalTags,
    UserGetRecentTracks,
    UserGetTopAlbums,
    UserGetTopArtists,
    UserGetTopTags,
    UserGetTopTracks,
    UserGetWeeklyAlbumChart,
    UserGetWeeklyArtistChart,
    UserGetWeeklyChartList,
    UserGetWeeklyTrackChart
)

License

lastfmxpy is distributed under the terms of the MIT license.

lastfmxpy's People

Contributors

pkeorley avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

lastfmxpy's Issues

Scrobbling of tracks not possible

First off: thank you for this wonderful package: very happy to have found it. Am I correct in thinking the TrackScrobble class doesn't have the params necessary to do a scrobble? I'd be happy to help out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.