Using Python oauth2client with App Engine Standard

Lukas Karlsson
Jul 28, 2017 · 2 min read

I recently began working on my first App Engine application, following Google’s Quickstart for Python App Engine Standard Environment.

My application needs to be able to authenticate against to some Google APIs with OAuth 2.0. There are several ways to do this from App Engine, but all of them require you to have access to oauth2client.

I naturally assumed that oauth2client would be automatically included in the App Engine Standard Environment, because it’s installed as one of the dependencies for google-api-python-client. But the client libraries are not included by default.

App Engine

Because the Python client libraries are not installed in the App Engine Python runtime environment, they must be vendored into your application just like third-party libraries.

Google provides documentation for installing a third-party library into your App Engine application. Here’s the process I followed.

  1. Create a new empty directory in the root of the project: mkdir lib
  2. Create requirements.txt: echo 'oauth2client' > requirements.txt
  3. Install requirements: pip install -U -t lib -r requirements.txt
  4. Create appengine_config.py:
# appengine_config.py
from google.appengine.ext import vendor

# Add any libraries install in the "lib" folder.
vendor.add('lib')

Now, I can include modules and classes from the Google oauth2client in my App Engine application, both locally and when deployed.

Additional references

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Lukas Karlsson

Written by

Google Developer Expert, Cloud Platform; Google Certified Cloud Architect. Somerville, MA.

Google Cloud Platform - Community

A collection of technical articles published or curated by Google Cloud Platform Developer Advocates. The views expressed are those of the authors and don't necessarily reflect those of Google.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade