Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install requests-oauth-hook

How to install requests-oauth-hook

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install requests-oauth-hook
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.2.0 Available View build log
0.1.4 Available View build log
0.1.3 Available View build log
0.1.1 Available View build log
0.1.0 Available View build log
Windows (64-bit)
0.2.0 Available View build log
0.1.4 Available View build log
0.1.3 Available View build log
0.1.1 Available View build log
0.1.0 Available View build log
Mac OS X (10.5+)
0.2.0 Available View build log
0.1.4 Available View build log
0.1.3 Available View build log
0.1.1 Available View build log
0.1.0 Available View build log
Linux (32-bit)
0.2.0 Available View build log
0.1.4 Available View build log
0.1.3 Available View build log
0.1.1 Available View build log
0.1.0 Available View build log
Linux (64-bit)
0.2.0 Available View build log
0.1.4 Available View build log
0.1.3 Available View build log
0.1.1 Available View build log
0.1.0 Available View build log
 
Author
License
BSD
Dependencies
Imports
Lastest release
version 0.2.0 on Jan 4th, 2012

# requests-oauth-hook

This is a hook for <a href="http://github.com/kennethreitz/requests">python-requests</a> great python HTTP library by <a href="https://github.com/kennethreitz">Kenneth Reitz</a>, that makes python-requests support Open Authentication version 1.0. The intention of this project is to provide the easiest way to do OAuth connections with Python.

This hook was initially based on <a href="https://github.com/simplegeo/python-oauth2">python-oauth2</a>, which looks unmaintained, kudos to the authors and contributors for doing a huge effort in providing OAuth to python httplib2.

## Installation

You can install requests-oauth-hook by simply doing:

pip install requests-oauth-hook

## Usage

You can initialize the hook passing it 4 parameters: access_token, access_token_secret, consumer_key, consumer_secret. First two access_token and access_token_secret are optional, in case you want to retrieve those from the API service (see later for an example). There are two ways to do initialize the hook. First one:

oauth_hook = OAuthHook(access_token, access_token_secret, consumer_key, consumer_secret)

If you are using the same consumer_key and consumer_secret all the time, you probably want to setup those fixed, so that you only have to pass the token parameters for setting the hook:

OAuthHook.consumer_key = consumer_key OAuthHook.consumer_secret = consumer_secret oauth_hook = OAuthHook(access_token, access_token_secret)

Now you need to pass the hook to python-requests, you probably want to do it as a session, so you don't have to do this every time:

client = requests.session(hooks={'pre_request': oauth_hook})

What you get is python-requests client which you can use the same way as you use requests API. Let's see a GET example:

response = client.get('http://api.twitter.com/1/account/rate_limit_status.json') results = json.loads(response.content)

And a POST example:

response = client.post('http://api.twitter.com/1/statuses/update.json', {'status': "Yay! It works!", 'wrap_links': True})

Beware that you are not forced to pass the token information to the hook. That way you can retrieve it from the API. Let's see a Twitter example:

client = requests.session(hooks={'pre_request': OAuthHook(consumer_key=consumer_key, consumer_secret=consumer_secret)}) response = client.get('https://api.twitter.com/oauth/request_token') response = parse_qs(response.content) print "Token: %s Secret: %s" % (response['oauth_token'], response['oauth_token_secret'])

## Testing

If you want to run the tests, you will need to copy test_settings.py.template into test_settings.py. This file is in the .gitignore index, so it won't be committed:

cp test_settings.py.template test_settings.py

Then fill in the information there. At the moment, the testing of the library is done in a functional way, doing a GET and a POST request against OAuth API services, so use a test account and not your personal account:

./tests.py

## Contributing

If you'd like to contribute, simply fork the repository, commit your changes to the dev branch (or branch off of it), and send a pull request. Make sure you add yourself to AUTHORS.

## TODO

  • Improve testing suite.
  • Support for python3.

Subscribe to package updates

Last updated Jan 4th, 2012

Download Stats

Last month:4

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.