Code Snippet

from sanction.client import Client
from sanction.adapters.google import Google

client = Client(Google, {
    "google.client_id": "myclientid",
    "google.client_secret": "myclientsecret",
    "google.redirect_uri": "myredirecturi",
    "google.scope": "myscope",
    "google.access_type": "online" # google-specific

# get authorization

# returned to your app (subsequent request)

# if all goes well in previous call


Note: Sanction is nearing alpha state, so usage and issue logs are appreciated.

Sanction is a Python implementation of the OAuth 2.0 protocol. It was written to cover issues missed by other implementations:

  • Support for multiple providers (protocol deviations). This didn't seem to be supported by any library.
  • Actually an OAuth2 implementation (python-oauth2 is a 2nd version of python-oauth, not an actual OAuth2 implementation)
  • Support for the entire OAuth2 spec. Most provide support for the authorization request flow (employed by all web server providers) with Bearer token credentials, but lacked support or extensibility for any other flows, credentials or other provider extensions)
  • 100% unit test coverage. Some employed TDD, others didn't.

The library is for anyone wanting to access protected resources via OAuth 2.0.

Currently, there are implementations for:

  • Google
  • Facebook
  • Foursquare
  • Deviant Art
  • Stack Exchange






Demian Brecht <demianbrecht [at] gmail.com>



Contributions can be made through pull requests.


FWIW, this library has undergone a major overhaul and now lives as a much happier Pythonic module (went from ~450 LOC to 66) and can be found at https://github.com/demianbrecht/sanction.


...And now also supports Python 3 (Github version, not uploaded to PyPI yet).

You must log in to answer this question.

protected by Community Oct 5 '15 at 17:25

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .