changeling edited this page Aug 23, 2018 · 7 revisions

Python Twitter

A Python wrapper around the Twitter API.

Author: The Python-Twitter Developers


This library provides a pure Python interface for the Twitter API.

Twitter provides a service that allows people to connect via the web, IM, and SMS. Twitter exposes a web services API and this library is intended to make it even easier for Python programmers to use.


From source:

Install the dependencies:

Alternatively use pip:

$ pip install -r requirements.txt

Download the latest python-twitter library from: or simply install it with:

pip install python-twitter

If you prefer to build from source, extract the source distribution and run:

$ python build
$ python install


With setuptools installed:

$ python test

Without setuptools installed:

$ python

Getting the code

The code is hosted at Github.

Check out the latest development version anonymously with:

 $ git clone git://
 $ cd python-twitter


View the last release API documentation at:


The library provides a Python wrapper around the Twitter API and the Twitter data model.


The three model classes are twitter.Status, twitter.User, and twitter.DirectMessage. The API methods return instances of these classes.

To read the full API for twitter.Status, twitter.User, or twitter.DirectMessage, run:

$ pydoc twitter.Status
$ pydoc twitter.User
$ pydoc twitter.DirectMessage


The API is exposed via the twitter.Api class.

To create an instance of the twitter.Api class:

>>> import twitter
>>> api = twitter.Api()

To create an instance of the twitter.Api with login credentials (many API calls required the client to be authenticated.)

The python-twitter library now only supports oAuth authentication as the Twitter devs have indicated that OAuth is the only method that will be supported moving forward.

>>> api = twitter.Api(consumer_key='consumer_key',

To see if your credentials are successful:

>>> print api.VerifyCredentials()
{"id": 16133, "location": "Philadelphia", "name": "bear"}

NOTE - much more than the small sample given here will print

To fetch a single user's public status messages, where user is either a Twitter short name or their user id.

>>> statuses = api.GetUserTimeline(user)
>>> print [s.text for s in statuses]

To fetch a list a user's friends (requires authentication):

>>> users = api.GetFriends()
>>> print [ for u in users]

To post a Twitter status message (requires authentication):

>>> status = api.PostUpdate('I love python-twitter!')
>>> print status.text
I love python-twitter!

There are many more API methods, to read the full API documentation:

$ pydoc twitter.Api


Patches and bug reports are welcome, just please keep the style consistent with the original source.

Add more example scripts.

The twitter.Status and twitter.User classes are going to be hard to keep in sync with the API if the API changes. More of the code could probably be written with introspection.

Statement coverage of twitter_test is only about 80% of

The twitter.Status and twitter.User classes could perform more validation on the property setters.

More Information

Please visit the google group for more discussion.


Additional thanks to Pierre-Jean Coudert, Omar Kilani, Jodok Batlogg, edleaf, glen.tregoning, Brad Choate, Jim Cortez, Jason Lemoine, Thomas Dyson, Robert Laquey, Hameedullah Khan, Mike Taylor, DeWitt Clinton, and the rest of the python-twitter mailing list.


Copyright 2007 The Python-Twitter Developers

Licensed under the Apache License, Version 2.0 (the 'License');
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an 'AS IS' BASIS,
See the License for the specific language governing permissions and
limitations under the License.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.