I'll spare you the boring "Hello World" post (which I typed at least twice) and jump straight into things. Chances are, if you've ever tried calling into the Flickr API from python, you've run across FlickrClient and flickr.py. I tried both, and both worked as advertised. The former, while very cleverly implemented, felt un-pythonic from the underscores in all the calls. Also, the use of xmltramp seemed like overkill. The latter was basically a lot of [IMHO] unnecessary wrapper code.
Building on ideas from FlickrClient, I put together a small python module for calling into Flickr that just feels right. For example, to get a list of public picture URLs for a user specified in USER_ID:
from flickr import FlickrAPI, get_photo_url flickr = FlickrAPI( API_KEY ) photos = flickr.people.getPublicPhotos( user_id=USER_ID ) urls = [get_photo_url(p) for p in photos]
Notice that you can call the API using dot notation. No underscores. The module also has a couple classes for dealing with the XML results from Flickr API calls in an intuitive manner, much like xmltramp. Both tag attributes and text node children are accessible through dot notation. Child nodes are also accessible through bracket (list) notation. Consider the following (abbreviated) response to
<person nsid="12037949754@N01" isadmin="0" ispro="0" iconserver="3"> <username>bees</username> <realname>Cal Henderson</realname> <location>Vancouver, Canada</location> <photos> <firstdate>1071510391</firstdate> <count>449</count> </photos> </person>
This would be encapsulated in the returned
XMLElement (we'll call it
person) and could be accessed as follows:
person.nsid # would return 12037949754@N01 person.username # would return bees person.photos.count # would return 449
Best of all, the module is entirely self-contained. One small file to install. Give it a try, and feel free to leave feedback in the comments.