This page of the documentation will cover all methods and classes available to the developer.
Twython, currently, has two main interfaces:
Instantiates an instance of Twython. Takes optional parameters for authentication and such (see below).
| Parameters: |
|
|---|
Add a member to a list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/members/create
Construct a Twitter API url, encoded, with parameters
| Parameters: |
|
|---|---|
| Return type: | string |
Usage:
>>> from twython import Twython
>>> twitter = Twython()
>>> api_url = 'https://api.twitter.com/1.1/search/tweets.json'
>>> constructed_url = twitter.construct_api_url(api_url, q='python', result_type='popular')
>>> print constructed_url
https://api.twitter.com/1.1/search/tweets.json?q=python&result_type=popular
Blocks the specified user from following the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/blocks/create
Favorites the status specified in the ID parameter as the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/favorites/create
Allows the authenticating users to follow the user specified in the ID parameter.
Docs: https://dev.twitter.com/docs/api/1.1/post/friendships/create
Creates a new list for the authenticated user.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/create
Adds multiple members to a list, by specifying a comma-separated list of member ids or screen names.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all
Creates a new place object at the given latitude and longitude.
Create a new saved search for the authenticated user.
Docs: https://dev.twitter.com/docs/api/1.1/post/saved_searches/create
Deletes the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/destroy
Removes the specified member from the list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy
Removes multiple members from a list, by specifying a comma-separated list of member ids or screen names.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy_all
Un-blocks the user specified in the ID parameter for the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/blocks/destroy
Destroys the direct message specified in the required id parameter
Docs: https://dev.twitter.com/docs/api/1.1/post/direct_messages/destroy
Un-favorites the status specified in the ID parameter as the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/favorites/destroy
Allows the authenticating user to unfollow the user specified in the ID parameter.
Docs: https://dev.twitter.com/docs/api/1.1/post/friendships/destroy
Destroys a saved search for the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/saved_searches/destroy/%3Aid
Destroys the status specified by the required ID parameter
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/destroy/%3Aid
Returns settings (including current trend, geo and sleep time information) for the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/account/settings
Returns a dict including an authorization URL, auth_url, to direct a user to
| Parameters: |
|
|---|---|
| Return type: | dict |
Returns a dict of authorized tokens after they go through the get_authentication_tokens phase.
| Parameters: | oauth_verifier – (required) The oauth_verifier (or a.k.a PIN for non web apps) retrieved from the callback url querystring |
|---|---|
| Return type: | dict |
Returns the locations that Twitter has trending topic information for.
Docs: https://dev.twitter.com/docs/api/1.1/get/trends/available
Returns the locations that Twitter has trending topic information for, closest to a specified location.
Docs: https://dev.twitter.com/docs/api/1.1/get/trends/closest
Returns a collection of users that the specified user can “contribute” to.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/contributees
Returns a collection of users who can contribute to the specified account.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/contributors
Returns a single direct message, specified by an id parameter.
Docs: https://dev.twitter.com/docs/api/1.1/get/direct_messages/show
Returns the 20 most recent direct messages sent to the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/direct_messages
Returns the 20 most recent Tweets favorited by the authenticating or specified user.
Docs: https://dev.twitter.com/docs/api/1.1/get/favorites/list
Returns a cursored collection of user IDs for every user following the specified user.
Docs: https://dev.twitter.com/docs/api/1.1/get/followers/ids
Returns a cursored collection of user objects for users following the specified user.
Docs: https://dev.twitter.com/docs/api/1.1/get/followers/list
Returns a cursored collection of user IDs for every user the specified user is following (otherwise known as their “friends”).
Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their “friends”).
Returns all the information about a known place.
Docs: https://dev.twitter.com/docs/api/1.1/get/geo/id/%3Aplace_id
Returns a collection of the most recent Tweets and retweets posted by the authenticating user and the users they follow.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline
Returns a collection of numeric IDs for every user who has a pending request to follow the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/incoming
Returns a specific header from the last API call This will return None if the header is not present
| Parameters: | header – (required) The name of the header you want to get the value of |
|---|
Returns the members of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/members
Returns a timeline of tweets authored by members of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/statuses
Returns the subscribers of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/subscribers
Obtain a collection of the lists the specified user is subscribed to.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions
Returns the 20 most recent mentions (tweets containing a users’s @screen_name) for the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
Returns information allowing the creation of an embedded representation of a Tweet on third party sites.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/oembed
Returns a collection of numeric IDs for every protected user for whom the authenticating user has a pending follow request.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing
Returns the top 10 trending topics for a specific WOEID, if trending information is available for it.
Returns a map of the available size variations of the specified user’s profile banner.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/profile_banner
Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
Returns up to 100 of the first retweets of a given tweet.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/%3Aid
Returns the authenticated user’s saved search queries.
Docs: https://dev.twitter.com/docs/api/1.1/get/saved_searches/list
Returns the 20 most recent direct messages sent by the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/get/direct_messages/sent
Locates places near the given coordinates which are similar in name.
Docs: https://dev.twitter.com/docs/api/1.1/get/geo/similar_places
Returns the specified list.
Returns a collection of user_ids that the currently authenticated user does not want to receive retweets from.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/no_retweets/ids
Access to Twitter’s suggested user list.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions
Access the users in a given category of the Twitter suggested user list.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug
Access the users in a given category of the Twitter suggested user list and return their most recent status if they are not a protected user.
Docs: https://dev.twitter.com/docs/api/1.1/get/users/suggestions/%3Aslug/members
Returns a collection of the most recent Tweets posted by the user indicated by the screen_name or user_id parameters.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
Check if the specified user is a member of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/members/show
Check if the specified user is a subscriber of the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show
Returns an array of numeric user ids the authenticating user is blocking.
Returns a collection of user objects that the authenticating user is blocking.
Returns the relationships of the authenticating user to the comma-separated list of up to 100 screen_names or user_ids provided.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/lookup
Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the user_id and/or screen_name parameters.
Removes the uploaded profile banner for the authenticating user. Returns HTTP 200 upon success.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/remove_profile_banner
Report the specified user as a spam account to Twitter.
Docs: https://dev.twitter.com/docs/api/1.1/post/users/report_spam
Return dict of response received from Twitter’s API
| Parameters: |
|
|---|---|
| Return type: | dict |
Retweets a tweet specified by the id parameter
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid
Returns the most recent tweets authored by the authenticating user that have been retweeted by others.
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets_of_me
Given a latitude and a longitude, searches for up to 20 places that can be used as a place_id when updating a status.
Docs: https://dev.twitter.com/docs/api/1.1/get/geo/reverse_geocode
Returns a collection of relevant Tweets matching a specified query.
Docs: https://dev.twitter.com/docs/api/1.1/get/search/tweets
Returns a generator of tweets that match a specified query.
Documentation: https://dev.twitter.com/docs/api/1.1/get/search/tweets
| Parameters: |
|
|---|---|
| Return type: | generator |
Usage:
>>> from twython import Twython
>>> twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
>>> search = twitter.search_gen('python')
>>> for result in search:
>>> print result
Search for places that can be attached to a statuses/update.
Provides a simple, relevance-based search interface to public user accounts on Twitter.
Sends a new direct message to the specified user from the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/direct_messages/new
Returns detailed information about the relationship between two arbitrary users.
Docs: https://dev.twitter.com/docs/api/1.1/get/friendships/show
Returns all lists the authenticating or specified user subscribes to, including their own.
Returns the lists owned by the specified Twitter user.
Docs: https://dev.twitter.com/docs/api/1.1/get/lists/ownerships
Retrieve the information for the saved search represented by the given id.
Docs: https://dev.twitter.com/docs/api/1.1/get/saved_searches/show/%3Aid
Returns a single Tweet, specified by the id parameter
Docs: https://dev.twitter.com/docs/api/1.1/get/statuses/show/%3Aid
Returns a variety of information about the user specified by the required user_id or screen_name parameter.
Subscribes the authenticated user to the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create
Unsubscribes the authenticated user from the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy
Updates the authenticating user’s settings.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/settings
Sets which device Twitter delivers updates to for the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/update_delivery_device
Allows one to enable or disable retweets and device notifications from the specified user.
Docs: https://dev.twitter.com/docs/api/1.1/post/friendships/update
Updates the specified list.
Docs: https://dev.twitter.com/docs/api/1.1/post/lists/update
Sets values that users are able to set under the “Account” tab of their settings page.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/update_profile
Uploads a profile banner on behalf of the authenticating user.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/update_profile_banner
Updates the authenticating user’s profile background image.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image
Sets one or more hex values that control the color scheme of the authenticating user’s profile page on twitter.com.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors
Updates the authenticating user’s profile image.
Docs: https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image
Updates the authenticating user’s current status, also known as tweeting
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/update
Updates the authenticating user’s current status and attaches media for upload. In other words, it creates a Tweet with a picture attached.
Docs: https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
Returns an HTTP 200 OK response code and a representation of the requesting user if authentication was successful; returns a 401 status code and an error message if not.
Docs: https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials
Streaming class for a friendly streaming user experience Authentication IS required to use the Twitter Streaming API
| Parameters: |
|
|---|
Used to disconnect the streaming client manually
Called when a deletion notice is received
Feel free to override this to handle your streaming data how you want it handled.
Twitter docs for deletion notices: http://spen.se/8qujd
| Parameters: | data (dict) – data from the ‘delete’ key recieved from the stream |
|---|
Called when a disconnect notice is received
Feel free to override this to handle your streaming data how you want it handled.
Twitter docs for disconnect notices: http://spen.se/xb6mm
| Parameters: | data (dict) – data from the ‘disconnect’ key recieved from the stream |
|---|
Called when stream returns non-200 status code
Feel free to override this to handle your streaming data how you want it handled.
| Parameters: |
|
|---|
Called when a limit notice is received
Feel free to override this to handle your streaming data how you want it handled.
Twitter docs for limit notices: http://spen.se/hzt0b
| Parameters: | data (dict) – data from the ‘limit’ key recieved from the stream |
|---|
Called when data has been successfull received from the stream
Feel free to override this to handle your streaming data how you want it handled. See https://dev.twitter.com/docs/streaming-apis/messages for messages sent along in stream responses.
| Parameters: | data (dict) – data recieved from the stream |
|---|
Called when the request has timed out
Class for different stream endpoints
Not all streaming endpoints have nested endpoints. User Streams and Site Streams are single streams with no nested endpoints Status Streams include filter, sample and firehose endpoints
Stream site
Accepted params found at: https://dev.twitter.com/docs/api/1.1/get/site
Stream user
Accepted params found at: https://dev.twitter.com/docs/api/1.1/get/user
Class for different statuses endpoints
Available so TwythonStreamer.statuses.filter() is available. Just a bit cleaner than TwythonStreamer.statuses_filter(), statuses_sample(), etc. all being single methods in TwythonStreamer
Stream statuses/filter
| Parameters: | **params – Paramters to send with your stream request |
|---|
Accepted params found at: https://dev.twitter.com/docs/api/1.1/post/statuses/filter
Stream statuses/firehose
| Parameters: | **params – Paramters to send with your stream request |
|---|
Accepted params found at: https://dev.twitter.com/docs/api/1.1/get/statuses/firehose
Stream statuses/sample
| Parameters: | **params – Paramters to send with your stream request |
|---|
Accepted params found at: https://dev.twitter.com/docs/api/1.1/get/statuses/sample
Generic error class, catch-all for most Twython issues. Special cases are handled by TwythonAuthError & TwythonRateLimitError.
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
Raised when you try to access a protected resource and it fails due to some issue with your authentication.
Raised when you’ve hit a rate limit.
The amount of seconds to retry your request in will be appended to the message.