Python Twitter API Library Reviews and Samples

There are many Twitter API libraries available for Python. I wanted to find out which one was the best and what the strengths and weaknesses of each are. However there are too many out there to find and review all of them. Instead here’s a bunch of the most popular Python Twitter API wrappers with a small review of each one, and some sample code showing off the syntax.

Python Twitter

This is the library that I personally use in most of my Twitter scripts. It’s very simple to use, but is not up to date with the latest developments at Twitter. It was written by DeWitt Clinton and available on Google Code. If you just want the basic API functionality this does a pretty decent job.

import twitter
api = twitter.Api('username', 'password')
statuses = api.GetPublicTimeline()
print [s.user.name for s in statuses]
users = api.GetFriends()
print [u.name for u in users]
statuses = api.GetUserTimeline(user)
print [s.text for s in statuses]
api.PostUpdate(username, password, 'I love python-twitter!')

twyt

Twyt is a pretty comprehensive library that seems to be pretty solid and well organized. In some cases there is added complexity to parse the return json objects from the Python Twitter API. It is written and maintained by Andrew Price.

from twyt import twitter, data
t = twitter.Twitter()
t.set_auth("username", "password")
print t.status_friends_timeline()
print t.user_friends()
return_val = t.status_update("Testing 123")
s = data.Status()
s.load_json(return_val)
print s
t.status_destroy(s.id)

Twython

An up to date, Python wrapper for the Twitter API. Supports Twitter’s main API, Twitter’s search API, and (soon) using OAuth with Twitter/Streaming API. It is based on the Python Twitter library and is actively maintained by Ryan Mcgrath.

import twython
twitter = twython.setup(authtype="Basic", username="example", password="example")
twitter.updateStatus("See how easy this was?")
friends_timeline = twitter.getFriendsTimeline(count="150", page="3")
print [tweet["text"] for tweet in friends_timeline]

Tweepy

Tweepy is a pretty compelling Python Twitter API library. It’s up to date with the latest features of Twitter and actively being developed by Joshua Roesslein. It features OAuth support, Python 3 support, streaming API support and it’s own cache system. Retweet streaming was recently added. If you want to use the most up to date features of the Twitter API on Python, or use Python 3, then you should definitely check out Tweepy.

import tweepy
api = tweepy.API.new('basic', 'username', 'password')
public_timeline = api.public_timeline()
print [tweet.text for tweet in public_timeline]
friends_timeline = api.friends_timeline()
print [tweet.text for tweet in friends_timeline]
u = tweepy.api.get_user('username')
friends = u.friends()
print [tweet.screen_name for f in friends]
api.update_status('tweeting with tweepy')

It’s pretty clear from the syntax samples that there’s not much difference between any of these Python Twitter API libraries when just getting the basics done. The difference only start to show up when you get into the latest features. OAuth, Streaming, and the retweet functions really differentiate these libraries. I hope this overview helps you find and choose the library that’s right for your project.

Bookmark and Share

Technorati Tags: , , , , ,

Related posts:

  1. Automatically Respond to Twitter Messages
  2. Python Web Crawler Script
  3. Scrape Bing Search Engine Results Page
  4. Getting links to a domain using Alexa and Python
  5. Targeting Twitter Trends Script
Stumble it!


RSS feed | Trackback URI

6 Comments »

Comment by halotis
2009-09-19 10:01:11

Python Twitter API Library Reviews and Samples – There are many Twitter API libraries available for Python. I wante.. http://bit.ly/2Q4ge

This comment was originally posted on Twitter

 
Comment by ryanmcgrath
2009-09-22 12:40:22

Cool comparison of the various Python Twitter libraries out there: http://is.gd/3zme7

This comment was originally posted on Twitter

 
Comment by arjun077
2009-10-03 06:24:01

Reading: “Python Twitter API Library Reviews and Samples | HalOtis Marketing” (http://twitthis.com/sgqaiz)

This comment was originally posted on Twitter

 
Comment by ideamonk
2009-10-03 06:27:39

Before you choose an API to play around twitter using python – http://is.gd/3U9b0

This comment was originally posted on Twitter

 
Comment by kamusin
2009-11-16 12:05:08

nice, just what I need

 
2010-07-07 01:33:19

[...] using python to communicate with twitter. If you want to check out other ones check out the post: Python Twitter API Library Reviews and Samples. I suggest you download the latest source (twitter.py) but it should work if you download the [...]

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped=""> in your comment.

Additional comments powered by BackType