views:

1034

answers:

5

I'm new to XML-RPC and I would like to know if there is any good tutorial to use XML-RPC with the Last.fm API.

Is it possible to call the API methods using the xmlrpclib module like in the following example?

import xmlrpclib
myserver = xmlrpclib.ServerProxy('http://ws.audioscrobbler.com/2.0/')
A: 

You can use this:

http://pypi.python.org/pypi/pylast/0.3.1

or if u do it by your own you can check the code...

Gomez
I've tried to use it but it lacks documentation... Right now I'm trying to learn something from the code.
Alceu Costa
A: 

Yes, your example of using the xmlrpclib looks fine.

Pylast is probably not the best beginner example. From Python, I think the simplest options are to use XML-RPC as you mentioned, or the REST API with the JSON response format and simplejson to decode the ouput.

Matt Good
+1  A: 

Now its not a good time to work on last.fm's api. They are changing it in a few days I think.

simao
+2  A: 

Your code looks just fine.

You might not know this, but most XML-RPC endpoints (such as Last.fm's) support XML-RPC introspection. For instance, if you want to find out what methods it exposes, do this:

import xmlrpclib
svc = xmlrpclib.ServerProxy('http://ws.audioscrobbler.com/2.0/')
print svc.system.listMethods()

And you'll be given a list of the methods exposed by the XML-RPC endpoint.

By the way, that bit of code up there demonstrates how to use a ServerProxy object to call a method exposed by the endpoint it's tied to, in this case, the system.listMethods method. If you wanted to call the user.getTopTags (as demonstrated on the API documentation homepage) method exposed by Last.fm, you'd do this:

print svc.user.getTopTags({'user': 'foo', 'api_key': 'bar'})

Dead simple! Of course, you'll need an API key from Last.fm before you can use the API.

Keith Gaughan
A: 

pylast


Last fm library in Python

The pylast library is a good choice for this work.

The library has a very large set of functionality covering all the major parts of the last.fm API.

Functionality

This includes: Albums, Artists, Auth, Events, Geo, Libraries, Playlists, Tags, Tasteometer ratings, Users and Venues.

Using a library such as this means that a lot of the work is done for you, so you dont spend time reinventing the wheel. (The library iteself is 3,000+ lines of code).

License

Because of the license which this library is released under, it is possible to modify the code yourself.

There is also a community of people working to hightlight any bugs in the library at http://sourceforge.net/tracker/?group_id=66150&atid=513503

Jon Winstanley