Skip to main content

Minimal wrapper for Twitter's REST and Streaming APIs

Project description

This Python package supports Twitter’s REST and Streaming APIs (version 1.1) with OAuth 1.0 or OAuth 2.0. It works with the latest Python versions in both 2.x and 3.x branches.

Some Code Examples

[See TwitterAPI/cli.py and TwitterAPI/examples for more working examples.]

First, authenticate with your application credentials:

from TwitterAPI import TwitterAPI
api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret)

Tweet something:

r = api.request('statuses/update', {'status':'This is a tweet!'})
print r.status_code

Get some tweets:

r = api.request('search/tweets', {'q':'pizza'})
for item in r:
        print item

Stream tweets from New York City:

r = api.request('statuses/filter', {'locations':'-74,40,-73,41'})
for item in r:
        print item

Notice that request() accepts both REST and Streaming API methods, and it takes two arguments: the Twitter method, and a dictionary of method parameters. In the above examples we use get_iterator() to get each tweet object. The iterator knows how to iterate both REST and Streaming API results. Alternatively, you have access to the response object returned by request(). From the response object r you can get the raw response with r.text or the HTTP status code with r.status_code. See the requests library documentation for more details.

Command-Line Usage (cli.py)

For syntax help:

python -u -m TwitterAPI.cli -h

You will need to supply your Twitter application OAuth credentials. The easiest option is to save them in TwitterAPI/credentials.txt. It is the default place where cli.py will look for them. You also may supply an alternative credentials file as a command-line argument.

Call any REST API endpoint:

python -u -m TwitterAPI.cli -endpoint statuses/update -parameters status='my tweet'

Another example (here using abbreviated option names) that parses selected output fields:

python -u -m TwitterAPI.cli -e search/tweets -p q=zzz count=10 -field screen_name text

Calling any Streaming API endpoint works too:

python -u -m TwitterAPI.cli -e statuses/filter -p track=zzz -f screen_name text

After the -field option you must supply one or more key names from the raw JSON response object. This will print values only for these keys. When the -field option is omitted cli.py prints the entire JSON response object.

Installation

From the command line:

pip install TwitterAPI

Documentation

Project details


Release history Release notifications

History Node

2.5.3

History Node

2.5.2

History Node

2.5.0

History Node

2.4.10

History Node

2.4.9

History Node

2.4.8

History Node

2.4.6

History Node

2.4.5

History Node

2.4.4

History Node

2.4.3

History Node

2.4.2

History Node

2.4.1.1

History Node

2.4.1

History Node

2.4.0

History Node

2.3.6

History Node

2.3.5

History Node

2.3.4

History Node

2.3.3.4

History Node

2.3.3.3

History Node

2.3.3.2

History Node

2.3.3.1

History Node

2.3.3

History Node

2.3.2

This version
History Node

2.3.1

History Node

2.3.0

History Node

2.2.8

History Node

2.2.7.3

History Node

2.2.7.2

History Node

2.2.7.1

History Node

2.2.7

History Node

2.2.6

History Node

2.2.5

History Node

2.2.4

History Node

2.2.3

History Node

2.2.2

History Node

2.2.1

History Node

2.2.0

History Node

2.1.13

History Node

2.1.12

History Node

2.1.11

History Node

2.1.10

History Node

2.1.9.2

History Node

2.1.9.1

History Node

2.1.9

History Node

2.1.8.7

History Node

2.1.8.6

History Node

2.1.8.5

History Node

2.1.8.4

History Node

2.1.8

History Node

2.1.7.1

History Node

2.1.7

History Node

2.1.6

History Node

2.1.5

History Node

2.1.4

History Node

2.1.2

History Node

2.1.1

History Node

2.1.0

History Node

2.0.9.6

History Node

2.0.9.5

History Node

2.0.9.4

History Node

2.0.9.3

History Node

2.0.9.2

History Node

2.0.9.1

History Node

2.0.8

History Node

2.0.7.1

History Node

2.0.7

History Node

2.0.6

History Node

2.0.5

History Node

2.0.4

History Node

2.0.3

History Node

2.0.2

History Node

2.0.1

History Node

2.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
TwitterAPI-2.3.1.tar.gz (9.5 kB) Copy SHA256 hash SHA256 Source None Feb 19, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page