twitter (version 0.3)
index
/home/dewitt/svn/python-twitter/twitter.py

A library that provides a python interface to the Twitter API

 
Modules
       
md5
os
simplejson
tempfile
time
twitter
urllib
urllib2
urlparse

 
Classes
       
__builtin__.object
Api
Status
User
exceptions.Exception
TwitterError

 
class Api(__builtin__.object)
    A python interface into the Twitter API
 
By default, the Api caches results for 1 minute.
 
Example usage:
 
  To create an instance of the twitter.Api class:
 
    >>> import twitter
    >>> api = twitter.Api()
 
  To fetch the most recently posted public twitter status messages:
 
    >>> statuses = api.GetPublicTimeline()
    >>> print [s.user.name for s in statuses]
    [u'DeWitt', u'Kesuke Miyagi', u'ev', u'Buzz Andersen', u'Biz Stone'] #...
 
  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:
 
    >>> users = api.GetFriends(username, password)
    >>> print [u.name for u in users]
 
  To post a twitter status message:
 
    >>> status = api.PostUpdate(username, password, 'I love python-twitter!')
    >>> print status.text
    I love python-twitter!
 
  Methods defined here:
GetFollowers(self, username, password)
Fetch the sequence of twitter.User instances, one for each follower
 
Args:
  username: The username whose followers should be fetched
  password: The password for the username to be fetched.
 
Returns:
  A sequence of twitter.User instances, one for each follower
GetFriends(self, username, password)
Fetch the sequence of twitter.User instances, one for each friend
 
Args:
  username: The username whose friends should be fetched
  password: The password for the username to be fetched.
 
Returns:
  A sequence of twitter.User instances, one for each friend
GetFriendsTimeline(self, username, password)
Fetch the sequence of twitter.Status messages for a user's friends
 
Args:
  username: The username to be fetched
  password: The password for the username to be fetched.
 
Returns:
  A sequence of twitter.Status instances, one for each message
GetPublicTimeline(self)
Fetch the sequnce of public twitter.Status message for all users.
 
Returns:
  An sequence of twitter.Status instances, one for each message
GetUserTimeline(self, user, count=None)
Fetch the sequence of public twitter.Status messages for a single user.
 
Args:
  user:
    either the username (short_name) or id of the user to retrieve
  count: the number of status messages to retrieve
 
Returns:
  A sequence of twitter.Status instances, one for each message up to count
PostUpdate(self, username, password, text)
Post a twitter status message.
 
Args:
  username: The username to post the status message
  password: The password for the username to be posted
  text: The message text to be posted
 
Returns:
  A twitter.Status instance representing the message posted
SetCache(self, cache)
Override the default cache.  Set to None to prevent caching.
 
Args:
  cache: an instance that supports the same API as the  twitter._FileCache
SetCacheTimeout(self, cache_timeout)
Override the default cache timeout.
 
Args:
  cache_timeout: time, in seconds, that responses should be reused.
SetUrllib(self, urllib)
Override the default urllib implementation.
 
Args:
  urllib: an instance that supports the same API as the urllib2 module
SetUserAgent(self, user_agent)
Override the default user agent
 
Args:
  user_agent: a string that should be send to the server as the User-agent
__init__(self)
Instantiate a new twitter.Api object.

Data and other attributes defined here:
DEFAULT_CACHE_TIMEOUT = 60
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Api' objects>
list of weak references to the object (if defined)

 
class Status(__builtin__.object)
    A class representing the Status structure used by the twitter API.
 
The Status structure exposes the following properties:
 
  status.created_at
  status.created_at_in_seconds # read only
  status.id
  status.text
  status.relative_created_at # read only
  status.user
 
  Methods defined here:
AsDict(self)
A dict representation of this twitter.Status instance.
 
The return value uses the same key names as the JSON representation.
 
Return:
  A dict representing this twitter.Status instance
AsJsonString(self)
A JSON string representation of this twitter.Status instance.
 
Returns:
  A JSON string representation of this twitter.Status instance
GetCreatedAt(self)
Get the time this status message was posted.
 
Returns:
  The time this status message was posted
GetCreatedAtInSeconds(self)
Get the time this status message was posted, in seconds since the epoch.
 
Returns:
  The time this status message was posted, in seconds since the epoch.
GetId(self)
Get the unique id of this status message.
 
Returns:
  The unique id of this status message
GetNow(self)
Get the wallclock time for this status message.
 
Used to calculate relative_created_at.  Defaults to the time
the object was instantiated.
 
Returns:
  Whatever the status instance believes the current time to be,
  in seconds since the epoch.
GetRelativeCreatedAt(self)
Get a human redable string representing the posting time
 
Returns:
  A human readable string representing the posting time
GetText(self)
Get the text of this status message.
 
Returns:
  The text of this status message.
GetUser(self)
Get a twitter.User reprenting the entity posting this status message.
 
Returns:
  A twitter.User reprenting the entity posting this status message
SetCreatedAt(self, created_at)
Set the time this status message was posted.
 
Args:
  created_at: The time this status message was created
SetId(self, id)
Set the unique id of this status message.
 
Args:
  id: The unique id of this status message
SetNow(self, now)
Set the wallclock time for this status message.
 
Used to calculate relative_created_at.  Defaults to the time
the object was instantiated.
 
Args:
  now: The wallclock time for this instance.
SetText(self, text)
Set the text of this status message.
 
Args:
  text: The text of this status message
SetUser(self, user)
Set a twitter.User reprenting the entity posting this status message.
 
Args:
  user: A twitter.User reprenting the entity posting this status message
__eq__(self, other)
__init__(self, created_at=None, id=None, text=None, user=None, now=None)
An object to hold a Twitter status message.
 
This class is normally instantiated by the twitter.Api class and
returned in a sequence.
 
Note: Dates are posted in the form "Sat Jan 27 04:17:38 +0000 2007"
 
Args:
  created_at: The time this status message was posted
  id: The unique id of this status message
  text: The text of this status message
  relative_created_at:
    A human readable string representing the posting time
  user:
    A twitter.User instance representing the person posting the message
  now:
    The current time, if the client choses to set it.  Defaults to the
    wall clock time.
__ne__(self, other)
__str__(self)
A string representation of this twitter.Status instance.
 
The return value is the same as the JSON string representation.
 
Returns:
  A string representation of this twitter.Status instance.

Static methods defined here:
NewFromJsonDict(data)
Create a new instance based on a JSON dict.
 
Args:
  data: A JSON dict, as converted from the JSON in the twitter API
Returns:
  A twitter.Status instance

Properties defined here:
created_at
The time this status message was posted.
get = GetCreatedAt(self)
Get the time this status message was posted.
 
Returns:
  The time this status message was posted
set = SetCreatedAt(self, created_at)
Set the time this status message was posted.
 
Args:
  created_at: The time this status message was created
created_at_in_seconds
The time this status message was posted, in seconds since the epoch
get = GetCreatedAtInSeconds(self)
Get the time this status message was posted, in seconds since the epoch.
 
Returns:
  The time this status message was posted, in seconds since the epoch.
id
The unique id of this status message.
get = GetId(self)
Get the unique id of this status message.
 
Returns:
  The unique id of this status message
set = SetId(self, id)
Set the unique id of this status message.
 
Args:
  id: The unique id of this status message
now
The wallclock time for this status instance.
get = GetNow(self)
Get the wallclock time for this status message.
 
Used to calculate relative_created_at.  Defaults to the time
the object was instantiated.
 
Returns:
  Whatever the status instance believes the current time to be,
  in seconds since the epoch.
set = SetNow(self, now)
Set the wallclock time for this status message.
 
Used to calculate relative_created_at.  Defaults to the time
the object was instantiated.
 
Args:
  now: The wallclock time for this instance.
relative_created_at
Get a human readable string representingthe posting time
get = GetRelativeCreatedAt(self)
Get a human redable string representing the posting time
 
Returns:
  A human readable string representing the posting time
text
The text of this status message
get = GetText(self)
Get the text of this status message.
 
Returns:
  The text of this status message.
set = SetText(self, text)
Set the text of this status message.
 
Args:
  text: The text of this status message
user
A twitter.User reprenting the entity posting this status message
get = GetUser(self)
Get a twitter.User reprenting the entity posting this status message.
 
Returns:
  A twitter.User reprenting the entity posting this status message
set = SetUser(self, user)
Set a twitter.User reprenting the entity posting this status message.
 
Args:
  user: A twitter.User reprenting the entity posting this status message

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Status' objects>
list of weak references to the object (if defined)

 
class TwitterError(exceptions.Exception)
    Base class for Twitter errors
 
  Methods inherited from exceptions.Exception:
__getitem__(...)
__init__(...)
__str__(...)

 
class User(__builtin__.object)
    A class representing the User structure used by the twitter API.
 
The User structure exposes the following properties:
 
  user.id
  user.name
  user.screen_name
  user.location
  user.description
  user.profile_image_url
  user.url
  user.status
 
  Methods defined here:
AsDict(self)
A dict representation of this twitter.User instance.
 
The return value uses the same key names as the JSON representation.
 
Return:
  A dict representing this twitter.User instance
AsJsonString(self)
A JSON string representation of this twitter.User instance.
 
Returns:
  A JSON string representation of this twitter.User instance
GetDescription(self)
Get the short text description of this user.
 
Returns:
  The short text description of this user
GetId(self)
Get the unique id of this user.
 
Returns:
  The unique id of this user
GetLocation(self)
Get the geographic location of this user.
 
Returns:
  The geographic location of this user
GetName(self)
Get the real name of this user.
 
Returns:
  The real name of this user
GetProfileImageUrl(self)
Get the url of the thumbnail of this user.
 
Returns:
  The url of the thumbnail of this user
GetScreenName(self)
Get the short username of this user.
 
Returns:
  The short username of this user
GetStatus(self)
Get the latest twitter.Status of this user.
 
Returns:
  The latest twitter.Status of this user
GetUrl(self)
Get the homepage url of this user.
 
Returns:
  The homepage url of this user
SetDescription(self, description)
Set the short text description of this user.
 
Args:
  description: The short text description of this user
SetId(self, id)
Set the unique id of this user.
 
Args:
  id: The unique id of this user.
SetLocation(self, location)
Set the geographic location of this user.
 
Args:
  location: The geographic location of this user
SetName(self, name)
Set the real name of this user.
 
Args:
  name: The real name of this user
SetProfileImageUrl(self, profile_image_url)
Set the url of the thumbnail of this user.
 
Args:
  profile_image_url: The url of the thumbnail of this user
SetScreenName(self, screen_name)
Set the short username of this user.
 
Args:
  screen_name: the short username of this user
SetStatus(self, status)
Set the latest twitter.Status of this user.
 
Args:
  status: The latest twitter.Status of this user
SetUrl(self, url)
Set the homepage url of this user.
 
Args:
  url: The homepage url of this user
__eq__(self, other)
__init__(self, id=None, name=None, screen_name=None, location=None, description=None, profile_image_url=None, url=None, status=None)
__ne__(self, other)
__str__(self)
A string representation of this twitter.User instance.
 
The return value is the same as the JSON string representation.
 
Returns:
  A string representation of this twitter.User instance.

Static methods defined here:
NewFromJsonDict(data)
Create a new instance based on a JSON dict.
 
Args:
  data: A JSON dict, as converted from the JSON in the twitter API
Returns:
  A twitter.User instance

Properties defined here:
description
The short text description of this user.
get = GetDescription(self)
Get the short text description of this user.
 
Returns:
  The short text description of this user
set = SetDescription(self, description)
Set the short text description of this user.
 
Args:
  description: The short text description of this user
id
The unique id of this user.
get = GetId(self)
Get the unique id of this user.
 
Returns:
  The unique id of this user
set = SetId(self, id)
Set the unique id of this user.
 
Args:
  id: The unique id of this user.
location
The geographic location of this user.
get = GetLocation(self)
Get the geographic location of this user.
 
Returns:
  The geographic location of this user
set = SetLocation(self, location)
Set the geographic location of this user.
 
Args:
  location: The geographic location of this user
name
The real name of this user.
get = GetName(self)
Get the real name of this user.
 
Returns:
  The real name of this user
set = SetName(self, name)
Set the real name of this user.
 
Args:
  name: The real name of this user
profile_image_url
The url of the thumbnail of this user.
get = GetProfileImageUrl(self)
Get the url of the thumbnail of this user.
 
Returns:
  The url of the thumbnail of this user
set = SetProfileImageUrl(self, profile_image_url)
Set the url of the thumbnail of this user.
 
Args:
  profile_image_url: The url of the thumbnail of this user
screen_name
The short username of this user.
get = GetScreenName(self)
Get the short username of this user.
 
Returns:
  The short username of this user
set = SetScreenName(self, screen_name)
Set the short username of this user.
 
Args:
  screen_name: the short username of this user
status
The latest twitter.Status of this user.
get = GetStatus(self)
Get the latest twitter.Status of this user.
 
Returns:
  The latest twitter.Status of this user
set = SetStatus(self, status)
Set the latest twitter.Status of this user.
 
Args:
  status: The latest twitter.Status of this user
url
The homepage url of this user.
get = GetUrl(self)
Get the homepage url of this user.
 
Returns:
  The homepage url of this user
set = SetUrl(self, url)
Set the homepage url of this user.
 
Args:
  url: The homepage url of this user

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'User' objects>
list of weak references to the object (if defined)

 
Data
        __author__ = 'dewitt@google.com'
__version__ = '0.3'

 
Author
        dewitt@google.com