twython

Actively maintained, pure Python wrapper for the Twitter API. Supports both normal and streaming Twitter APIs.

https://github.com/ryanmcgrath/twython

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    5 of 103 committers (4.9%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.0%) to scientific vocabulary

Keywords from Contributors

forhumans requests python-requests humans cookies templates pallets wsgi werkzeug apps
Last synced: 11 months ago · JSON representation

Repository

Actively maintained, pure Python wrapper for the Twitter API. Supports both normal and streaming Twitter APIs.

Basic Info
Statistics
  • Stars: 1,858
  • Watchers: 102
  • Forks: 396
  • Open Issues: 27
  • Releases: 0
Created over 17 years ago · Last pushed almost 4 years ago
Metadata Files
Readme Changelog License

README.md

Twython

Twython is a Python library providing an easy way to access Twitter data. Supports Python 3. It's been battle tested by companies, educational institutions and individuals alike. Try it today!

Note: As of Twython 3.7.0, there's a general call for maintainers put out. If you find the project useful and want to help out, reach out to Ryan with the info from the bottom of this README. Great open source project to get your feet wet with!

Features

  • Query data for:
    • User information
    • Twitter lists
    • Timelines
    • Direct Messages
    • and anything found in the docs
  • Image Uploading:
    • Update user status with an image
    • Change user avatar
    • Change user background image
    • Change user banner image
  • OAuth 2 Application Only (read-only) Support
  • Support for Twitter's Streaming API
  • Seamless Python 3 support!

Installation

Install Twython via pip:

bash $ pip install twython

If you're on a legacy project that needs Python 2.7 support, you can install the last version of Twython that supported 2.7:

pip install twython==3.7.0`

Or, if you want the code that is currently on GitHub:

bash git clone git://github.com/ryanmcgrath/twython.git cd twython python setup.py install

Documentation

Documentation is available at https://twython.readthedocs.io/en/latest/

Starting Out

First, you'll want to head over to https://apps.twitter.com and register an application!

After you register, grab your applications Consumer Key and Consumer Secret from the application details tab.

The most common type of authentication is Twitter user authentication using OAuth 1. If you're a web app planning to have users sign up with their Twitter account and interact with their timelines, updating their status, and stuff like that this is the authentication for you!

First, you'll want to import Twython

python from twython import Twython

Obtain Authorization URL

Now, you'll want to create a Twython instance with your Consumer Key and Consumer Secret:

  • Only pass callback_url to getauthenticationtokens if your application is a Web Application
  • Desktop and Mobile Applications do not require a callback_url

```python APPKEY = 'YOURAPPKEY' APPSECRET = 'YOURAPPSECRET'

twitter = Twython(APPKEY, APPSECRET)

auth = twitter.getauthenticationtokens(callback_url='http://mysite.com/callback') ```

From the auth variable, save the oauth_token and oauth_token_secret for later use (these are not the final auth tokens). In Django or other web frameworks, you might want to store it to a session variable

python OAUTH_TOKEN = auth['oauth_token'] OAUTH_TOKEN_SECRET = auth['oauth_token_secret']

Send the user to the authentication url, you can obtain it by accessing

python auth['auth_url']

Handling the Callback

If your application is a Desktop or Mobile Application oauth_verifier will be the PIN code

After they authorize your application to access some of their account details, they'll be redirected to the callback url you specified in get_authentication_tokens.

You'll want to extract the oauth_verifier from the url.

Django example:

python oauth_verifier = request.GET['oauth_verifier']

Now that you have the oauth_verifier stored to a variable, you'll want to create a new instance of Twython and grab the final user tokens

```python twitter = Twython( APPKEY, APPSECRET, OAUTHTOKEN, OAUTHTOKEN_SECRET )

finalstep = twitter.getauthorizedtokens(oauthverifier) ```

Once you have the final user tokens, store them in a database for later use::

python OAUTH_TOKEN = final_step['oauth_token'] OAUTH_TOKEN_SECRET = final_step['oauth_token_secret']

For OAuth 2 (Application Only, read-only) authentication, see our documentation.

Dynamic Function Arguments

Keyword arguments to functions are mapped to the functions available for each endpoint in the Twitter API docs. Doing this allows us to be incredibly flexible in querying the Twitter API, so changes to the API aren't held up from you using them by this library.

Basic Usage

Function definitions (i.e. gethometimeline()) can be found by reading over twython/endpoints.py

Create a Twython instance with your application keys and the users OAuth tokens

python from twython import Twython twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

Authenticated Users Home Timeline

python twitter.get_home_timeline()

Updating Status

This method makes use of dynamic arguments, read more about them.

python twitter.update_status(status='See how easy using Twython is!')

Advanced Usage

Questions, Comments, etc?

My hope is that Twython is so simple that you'd never have to ask any questions, but if you feel the need to contact me for this (or other) reasons, you can hit me up at ryan@venodesigns.net.

Or if I'm to busy to answer, feel free to ping mikeh@ydekproductions.com as well.

Follow us on Twitter:

Want to help?

Twython is useful, but ultimately only as useful as the people using it (say that ten times fast!). If you'd like to help, write example code, contribute patches, document things on the wiki, tweet about it. Your help is always appreciated!

Owner

  • Name: Ryan McGrath
  • Login: ryanmcgrath
  • Kind: user
  • Location: Seattle / Tokyo
  • Company: Freelance

Privacy, Rust, Apple and everything in-between. Other tech stacks welcome too, as long as what we're building is cool.

GitHub Events

Total
  • Watch event: 16
Last Year
  • Watch event: 16

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 679
  • Total Committers: 103
  • Avg Commits per committer: 6.592
  • Development Distribution Score (DDS): 0.688
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Ryan McGrath r****n@v****t 212
Mike Helmick m****k@m****m 192
Mike Helmick m****h@y****m 35
Phil Gyford p****l@g****m 16
Ryan McGrath r****n@r****o 11
cash c****o@g****m 11
Mike Helmick me@m****m 10
Ben McGinnes b****n@a****g 9
Erik Scheffers e****5@g****m 9
Edward Hades e****s@g****m 8
Clayton A Davis c****d@c****t 8
Randall Degges r****s@g****m 7
ping l****g@g****m 6
jonathan vanasco j****n@2****m 5
Manuel Cortez m****l@m****t 5
devdave d****e@o****t 4
Tushar Bhushan t****n@t****m 4
Remy D r****d@c****s 4
kracekumar k****r@g****m 4
drevicko s****s@d****m 4
Erik e****k@e****) 4
Jose Manuel Delicado j****b@h****m 3
Cory Benfield l****z@g****m 3
Diego Allen d****n@g****m 3
Eugen Pyvovarov b****v@g****m 3
Joe Cabrera c****6@g****m 3
Mesar Hameed m****d@s****g 3
hansenrum s****e@d****s 2
lucadex l****x@g****m 2
fumieval f****l@g****m 2
and 73 more...

Issues and Pull Requests

Last synced: about 1 year ago

All Time
  • Total issues: 86
  • Total pull requests: 16
  • Average time to close issues: about 3 years
  • Average time to close pull requests: over 1 year
  • Total issue authors: 74
  • Total pull request authors: 13
  • Average comments per issue: 2.95
  • Average comments per pull request: 3.0
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: 11 minutes
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 3.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jvanasco (4)
  • cash (3)
  • chasrmartin (3)
  • ghost (2)
  • philgyford (2)
  • debunge (2)
  • Keramatfar (2)
  • michaelhelmick (2)
  • EhsanKia (1)
  • mad2code (1)
  • andrewtatham (1)
  • grantinator (1)
  • RandallShanePhD (1)
  • AlexFlipnote (1)
  • likewhoa (1)
Pull Request Authors
  • dvinegla (2)
  • jayvdb (2)
  • timgates42 (2)
  • jvmaia (1)
  • ctoth (1)
  • Telofy (1)
  • kannes (1)
  • altendky (1)
  • domeniconappo (1)
  • nouvak (1)
  • tirkarthi (1)
  • fogti (1)
  • AnnaYasenova (1)
Top Labels
Issue Labels
Enhancement (2) Feature Suggestion (1)
Pull Request Labels
Enhancement (1)

Packages

  • Total packages: 4
  • Total downloads:
    • pypi 124,764 last-month
  • Total docker downloads: 4,372
  • Total dependent packages: 13
    (may contain duplicates)
  • Total dependent repositories: 1,928
    (may contain duplicates)
  • Total versions: 71
  • Total maintainers: 2
pypi.org: twython

Actively maintained, pure Python wrapper for the Twitter API. Supports both normal and streaming Twitter APIs

  • Versions: 61
  • Dependent Packages: 11
  • Dependent Repositories: 1,924
  • Downloads: 124,764 Last month
  • Docker Downloads: 4,372
Rankings
Dependent repos count: 0.3%
Downloads: 0.8%
Docker downloads count: 1.1%
Average: 1.3%
Dependent packages count: 1.6%
Stargazers count: 1.6%
Forks count: 2.6%
Maintainers (2)
Last synced: 11 months ago
proxy.golang.org: github.com/ryanmcgrath/twython
  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Forks count: 1.4%
Stargazers count: 1.6%
Average: 5.8%
Dependent packages count: 9.6%
Dependent repos count: 10.8%
Last synced: 11 months ago
conda-forge.org: twython
  • Versions: 6
  • Dependent Packages: 2
  • Dependent Repositories: 2
Rankings
Forks count: 8.3%
Stargazers count: 9.2%
Average: 14.3%
Dependent packages count: 19.6%
Dependent repos count: 20.3%
Last synced: 11 months ago
anaconda.org: twython
  • Versions: 2
  • Dependent Packages: 0
  • Dependent Repositories: 2
Rankings
Forks count: 16.8%
Stargazers count: 18.3%
Average: 33.8%
Dependent repos count: 48.9%
Dependent packages count: 51.2%
Last synced: 11 months ago

Dependencies

requirements.txt pypi
  • coverage ==3.6.0
  • nose-cov ==1.6
  • python-coveralls ==2.1.0
  • requests >=2.1.0
  • requests_oauthlib >=0.4.0
  • responses ==0.3.0
setup.py pypi
  • requests >=2.1.0
  • requests_oauthlib >=0.4.0