Using Python Libraries

Declaring and managing dependencies

Dependencies for python applications are declared in a standard requirements.txt file. For example:


You can use any Linux-compatible Python package in the App Engine flexible environment, including packages that require native (C) extensions.

The Python runtime will automatically install all dependencies declared in your requirements.txt during deployment.

Installing dependencies locally

When developing and testing your application locally, it's highly recommended to use virtualenv to isolate your application's dependencies from your system packages. This also ensures that your dependencies will be the same version on your local machine and the deployed application.

If you do not have virtualenv, you can install it via pip.

[sudo] pip install virtualenv

You can then create a virtualenv, activate it, and install all of your application dependencies.

virtualenv env
source env/bin/activate
pip install -r requirements.txt

Now when you run your application you can be confident that only the dependencies declared in requirements.txt are available.

Often you will not know your exact dependencies. You can use the virtualenv and pip to install dependencies and use pip freeze to write the name and version of all installed packages to your requirements.txt.

virtualenv env
source env/bin/activate
pip install flask
pip install python-memcached
pip freeze > requirements.txt

Installing a web framework

You'll need to use a web framework to enable your app to serve web requests. You can use any Python web framework including the following:

To use a particular web framework, just add it to your requirements.txt:


Installing a WSGI server

Some web frameworks have built-in WSGI servers; however, few of them are suitable for serving production traffic. Most web applications use a standalone WSGI server such as Gunicorn, uWSGI or Waitress. For more information on installing, configuring, and using a WSGI server see application startup.

Installing the Google Cloud Client library

The Google Cloud Client Library for Python is a client library for accessing Google Cloud Platform services that significantly reduces the boilerplate code you have to write. The library provides high-level API abstractions so they're easier to understand. It embraces idioms of Python, works well with the standard library, and integrates better with your codebase. All this means you spend more time creating code that matters to you.

To install the library locally:

pip install google-cloud

The client library can automatically handle authentication for you locally as well by using the Google Cloud SDK.

gcloud auth login
Was this page helpful? Let us know how we did:

Send feedback about...

App Engine flexible environment for Python docs