Git Product home page Git Product logo

twython's Introduction

Twython - Easy Twitter utilities in Python

Ah, Twitter, your API used to be so awesome, before you went and implemented the crap known as OAuth 1.0. However, since you decided to force your entire development community over a barrel about it, I suppose Twython has to support this. So, that said...

Does Twython handle OAuth?

Yes, in a sense. There's a variety of builtin-methods that you can use to handle the authentication ritual. There's an example Django application that showcases this - feel free to peruse and use!

Installation

Installing Twython is fairly easy. You can...

(pip install | easy_install) twython

...or, you can clone the repo and install it the old fashioned way.

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

Please note:

As of Twython 2.0.0, we have changed routes for functions to abide by the Twitter Spring 2012 clean up. Please make changes to your code accordingly.

Example Use

from twython import Twython

twitter = Twython()
results = twitter.search(q = "bert")

# More function definitions can be found by reading over twython/twitter_endpoints.py, as well
# as skimming the source file. Both are kept human-readable, and are pretty well documented or
# very self documenting.

Streaming API

Twython, as of v1.5.0, now includes an experimental Twitter Streaming API handler. Usage is as follows; it's designed to be open-ended enough that you can adapt it to higher-level (read: Twitter must give you access) streams. This also exists in large part (read: pretty much in full) thanks to the excellent python-requests library by Kenneth Reitz.

import json  
from twython import Twython  

def on_results(results):  
    """  
        A callback to handle passed results. Wheeee.  
    """  
    print json.dumps(results)  

Twython.stream({  
    'username': 'your_username',  
    'password': 'your_password',  
    'track': 'python'  
}, on_results)  

A note about the development of Twython (specifically, 1.3)

As of version 1.3, Twython has been extensively overhauled. Most API endpoint definitions are stored in a separate Python file, and the class itself catches calls to methods that match up in said table.

Certain functions require a bit more legwork, and get to stay in the main file, but for the most part it's all abstracted out.

As of Twython 1.3, the syntax has changed a bit as well. Instead of Twython.core, there's a main Twython class to import and use. If you need to catch exceptions, import those from twython as well.

Arguments to functions are now exact keyword matches for the Twitter API documentation - that means that whatever query parameter arguments you read on Twitter's documentation (http://dev.twitter.com/doc) gets mapped as a named argument to any Twitter function.

For example: the search API looks for arguments under the name "q", so you pass q="query_here" to search().

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.

Twython 3k

There's an experimental version of Twython that's made for Python 3k. This is currently not guaranteed to work in all situations, but it's provided so that others can grab it and hack on it. If you choose to try it out, be aware of this.

OAuth is now working thanks to updates from Hades. You'll need to grab his Python 3 branch for python-oauth2 to have it work, though.

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 [email protected].

You can also follow me on Twitter - @ryanmcgrath.

Twython is released under an MIT License - see the LICENSE file for more information.

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!

Special Thanks to...

This is a list of all those who have contributed code to Twython in some way, shape, or form. I think it's exhaustive, but I could be wrong - if you think your name should be here and it's not, please contact me and let me know (or just issue a pull request on GitHub, and leave a note about it so I can just accept it ;)).

twython's People

Contributors

michaelhelmick avatar eriks5 avatar hades avatar randalldegges-okta-2 avatar decause avatar kracekumar avatar eugenepyvovarov avatar mckellister avatar voulnet avatar jvanasco avatar luquedaniel avatar jelsas avatar mliu7 avatar idris avatar jennylin avatar

Stargazers

Kristof Leroux avatar

Watchers

Kristof Leroux avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.