You can use [custom runtimes](https://docs.cloud.google.com/appengine/docs/flexible/custom-runtimes) to add
additional functionality to a Python app running in the flexible environment. To configure
a custom runtime, you replace this line in your `app.yaml` file:

    runtime: python

with this line:

    runtime: custom

You must also [specify a base image](https://docs.cloud.google.com/appengine/docs/flexible/custom-runtimes/build#base)
by adding a Dockerfile in the same directory that contains the `app.yaml` file.

Visit the [Custom runtimes](https://docs.cloud.google.com/appengine/docs/flexible/custom-runtimes)
documentation to learn how to define a Dockerfile in a custom runtime.

## Health Checking

By default, all programs running in the flexible environment receive [health check requests](https://docs.cloud.google.com/appengine/docs/flexible/custom-runtimes#health_check_requests).
If a base image supports health checking, you don't need to write any additional code. If it does not, you will need
to disable health checks, or write your own code to handle health check requests.

## Selecting the Python version

The `python` runtime has [Python 2.7.12](https://www.python.org/downloads/release/python-2712/) and [Python 3.6.10](https://www.python.org/downloads/release/python-3610/) pre-installed. You can customize the `Dockerfile` to install other versions or alternative interpreters if needed.

You can specify a whether to use Python 2 or Python 3 in your application's `Dockerfile` when creating the virtual environment:

    # Python 3
    RUN venv /env -p python3.7

    # Python 2 (implicit)
    RUN virtualenv /env

    # Python 2 (explicit)
    RUN virtualenv /env -p python2.7