Twyt (Reprise)

By Andrew Price, 2008-01-06 17:21:10 in General.

Since the majority of twyt's code is reusable I've decided to brand it as an alternative Twitter API Python module instead of just a command line client. It's pretty simple to use, as exemplified by the following exciting and contrived Python session:

>>> from twyt import twitter, data
>>> t = twitter.Twitter()
>>> t.set_auth("username", "password")
>>> return_val = t.status_update("Test")
>>> s = data.Status()
>>> s.load_json(return_val)
>>> print s
[568644162] Andy Price: Test (Sun Jan 06 16:10:53 +0000 2008 via web)
>>> print
>>> t.status_destroy(

A quick run through the code: set_auth() tells the Twitter object your username and password. Then status_update() sends your status message to Twitter and return_val is set to the JSON formatted string that Twitter sends back. We then load the JSON string into a Status object which lets us access the returned data (the details of the new status message) conveniently. We then pass the id of the new status message into status_destroy() which tells Twitter to delete the status message, because it's boring.

The docs in the classes are pretty good so help() should be your friend. Go forth and write super-shiny twyt-based applications.

Twyt is now in Fedora Rawhide and Debian Unstable, so it should propagate into Ubuntu Hardy Heron (universe) soon. Those of you brave enough to run Rawhide, Unstable and Hardy can install twyt using 'yum install python-twyt' or 'apt-get install python-twyt' respectively. Alternatively, just grab the latest tarball.


Gabe writes:

I'm getting a lot of HTTP 304 errors using the twyt client. Is caching not implemented?

2008-01-18 00:07:45

Andy Price writes:

You can ignore the 304 errors. They are due to the fact that twyt only requests messages that have been posted since the most recent message it received and Twitter sends back a 304 error when no newer messages are found. And also that I accidentally left the error exception handler in the wrong place when I last made a release. Silly me. The bug is purely cosmetic, though.

It's fixed in the development code repository if you want to try that out but I'll not be making a new release until I've added some more Twitter API function handling, which will be whenever I can find some time to do so.

2008-01-18 17:49:02