Using Python oauth2client with App Engine Standard
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.
- Create a new empty directory in the root of the project:
mkdir lib - Create requirements.txt:
echo 'oauth2client' > requirements.txt - Install requirements:
pip install -U -t lib -r requirements.txt - 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
- Managing vendored packages on App Engine (Jon Wayne Parrott)
- Managing App Engine Dependencies Using pip (Kevin Sookocheff)
- Simple Google API Auth samples for service accounts, installed applications and Appengine (@salmaan.rashid on Medium)
- Unable to run dev_appserver.py with gcloud (Stack Overflow)
- Unable to use google-cloud in GAE (Stack Overflow)

