Skip to main content

A simple wrapper for the Google OAuth2 client library

Project description


A Flask extension for interacting with Google OAuth2 Service Accounts.

Build Status
Coverage Status
PyPI Version
PyPI Downloads

Getting Started


  • Python 2.6+

  • OpenSSL


Flask-GSA can be installed with pip:

$ pip install Flask-GSA

Basic Usage

A minimal sample application:

from flask import Flask
from flask_gsa import GoogleServiceAccount

app = Flask(__name__)

# Create a service account object and assign a config variable prefix
analytics_gsa = GoogleServiceAccount('ANALYTICS_GSA')

# Set up the service account settings
app.config['ANALYTICS_GSA_PK_FILE'] = 'analytics.p12'
app.config['ANALYTICS_GSA_PK_PASSWORD'] = 'notasecret'
app.config['ANALYTICS_GSA_EMAIL'] = ''

# Initialize the extension

def get_analytics_token():
    scopes = [
    return analytics_gsa.generate_token(scopes)

if __name__ == '__main__':, debug=True)

Run the app:

$ python
 * Running on (Press CTRL+C to quit)
 * Restarting with stat

Get a token:

$ http :5000/token
    "expires": 1437698007,
    "issued": 1437694408,
    "token": "ya29.uQEiLFkED9YMTG7CvctLYtJqnOny_8CkA4_Hxk5yxzEhXR3eNSO-Pca20BRNxBT74XYD",
    "token_type": "Bearer"

Configuration Options:

When creating an instance of the extension, you must choose a config variable
prefix. This allows multiple service account objects to be used with the same
analytics_gsa = GoogleServiceAccount('ANALYTICS')
gdrive_gsa = GoogleServiceAccount('GDRIVE')

The following config variables are required:

Config Variable



Path to the PKCS12 key that will be used to sign tokens


Password for the PKCS12 private key


Service Account’s email address

# Revision History

## 0.1.1 (2015/07/23)

  • Fix tests

## 0.1.0 (2015/07/23)

  • Initial release

Project details

Download files

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

Source Distribution

Flask-GSA-0.1.1.tar.gz (4.5 kB view hashes)

Uploaded source

Built Distribution

Flask_GSA-0.1.1-py2-none-any.whl (4.8 kB view hashes)

Uploaded 2 7

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page