Python Twitter library: which one?

Question:

I realize this is a bit of a lazyweb question, but I wanted to see which python library for Twitter people have had good experiences with.

I’ve used Python Twitter Tools and like its brevity and beauty of interface, but it doesn’t seem to be one of the popular ones – it’s not even listed on the Twitter Libraries page.

There are, however, plenty of others listed:

  • oauth-python-twitter2 by Konpaku Kogasa. Combines python-twitter and oauth-python-twitter to create an evolved OAuth Pokemon.
  • python-twitter by DeWitt Clinton. This library provides a pure Python interface for the Twitter API.
  • python-twyt by Andrew Price. BSD licensed Twitter API interface library and command line client.
  • twitty-twister by Dustin Sallings. A Twisted interface to Twitter.
  • twython by Ryan McGrath. REST and Search library inspired by python-twitter.
  • Tweepy by Josh Roesslein. Supports OAuth, Search API, Streaming API.

My requirements are fairly simple:

  • Be able to use OAuth
  • Be able to follow a user
  • Be able to send a direct message
  • Be able to post
  • Streaming API would be nice

Twisted one aside (I’m not using twisted in this case), have you used any of the others, and if so, do you recommend them?

[Update] FWIW, I ended up going with Python Twitter Tools again. The new version supported OAuth nicely, and it’s a very clever API, so I stuck to it.

Asked By: Parand

||

Answers:

python-twitter should cover the first four requirements. I’ve used it before, and it’s fairly easy to start developing with it. For leveraging Twitter’s streaming API, I would recommend tweetstream. It’s a fantastic Python module that grabs tweets in real-time as they are posted. Based on whether you have gardenhose/firehose access to the twitter stream, you’ll only get a small fraction of tweets posted. With tweetstream, you can also provide a list of search predicates to filter specific tweets that you are looking for. I used it for a project that involved mining tweets over an 8 hour period and it worked flawlessly. Both of these modules should be available through Python’s easy-install.

EDIT: I don’t know what you intend on doing with Python/Twitter but if you do plan on capturing a lot of tweets, keep in mind that Twitter receives myriad tweets in languages besides English. Remember to encode everything properly.

Answered By: GobiasKoffi

I’ve used tweepy for playing around and thought it was pretty easy and fun to use. Didn’t really look that much into the alternatives however so take my opinion with suitable amount of salt :).

Answered By: Hagge

Full disclosure: I’m the author of Twython.

As such, I’d recommend using mine. It supports OAuth now, and ships with a skeleton Django application to get you up and running in ~5 minutes.

It can handle everything you’re looking for, sans the Streaming API – I’m of the opinion that something like that should be implemented on a case-by-case basis, as it’s generally a fairly custom setup. There’s been very little demand for library support for it, either, so I’ve a hard time dedicating cycles to supporting it.

pip install twython

http://github.com/ryanmcgrath/twython

Answered By: Ryan McGrath
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.