Python 3 Runtime Environment

The Python 3.7 runtime is the software stack responsible for installing your web service's code and its dependencies and running your service. The Python 3.7 runtime for App Engine in the standard environment is declared in the app.yaml file as python37:

runtime: python37

Python 3 version

The Python 3.7 runtime environment uses the latest stable release of Python 3.7. App Engine automatically updates to new minor revisions upon deployment, but will not automatically update the major version.

For example, your application might be deployed at Python 3.7.0 and later automatically updated to Python 3.7.1, but it will not be automatically updated to Python 3.8.0.

Currently, Python 3.7 is the only Python 3 runtime available on the App Engine standard environment.

Dependencies

During deployment, App Engine uses the Python package manager pip to install dependencies defined in the requirements.txt metadata file located in your project's root directory. You do not need to upload dependencies as App Engine performs a fresh install.

Dependency specification using the Pipfile/Pipfile.lock standard is currently not supported and your project must not have these files present.

Application startup

The runtime starts your application by using the contents of the optional entrypoint field in your app.yaml file. For example:

runtime: python37
entrypoint: gunicorn -b :$PORT main:app

For your app to receive HTTP requests, your entrypoint should start a web server that listens on the port specified by the PORT environment variable.

The use of an entrypoint is optional. If your app meets the following conditions, App Engine will automatically add a web server to your requirements.txt file and configure the Gunicorn web server:

  • The root of your app directory contains a main.py file with a WSGI-compatible object called app.

  • app.yaml does not contain the entrypoint field.

  • Your app does not contain Pipfile or Pipfile.lock files.

Any HTTP requests will cause your application to run using this pre-configured web server.

Entrypoint best practices

Do not include gunicorn in your requirements.txt file unless you are specifying the entrypoint.

For the best performance, the entrypoint should be lightweight because it runs whenever a new instance of your application is created.

If you specify an entrypoint, configure your webserver according to your chosen instance size to avoid running out of memory. If you are using Gunicorn, configure the number of workers using the --workers flag. Append this flag to your entrypoint with a value that matches your chosen instance class:

Instance class Workers
F1 (default) 1
F2 2
F4 4
F4_1G 8
B1 (default) 1
B2 2
B4 4
B4_1G 8
B8 8

This guidance serves as a starting point for selecting the number of workers. Depending on your app's performance needs and characteristics, you may need to use more or fewer workers.

Environment variables

The following environment variables are set by the runtime:

Environment variable Description
GAE_APPLICATION The ID of your App Engine application.
GAE_DEPLOYMENT_ID The ID of the current deployment.
GAE_ENV The App Engine environment. Set to standard.
GAE_INSTANCE The ID of the instance on which your service is currently running.
GAE_MEMORY_MB The amount of memory available to the application process, in MB.
GAE_RUNTIME The runtime specified in your app.yaml file. The value is python37 for Python 3.7.
GAE_SERVICE The service name specified in your app.yaml file. If no service name is specified, it is set to default.
GAE_VERSION The current version label of your service.
GOOGLE_CLOUD_PROJECT The GCP project ID associated with your application.
NODE_ENV Set to production when your service is deployed.
PORT The port that receives HTTP requests.

You can define additional environment variables in your app.yaml file, but the above values cannot be overridden, except for NODE_ENV.

HTTPS and forwarding proxies

App Engine terminates HTTPS connections at the load balancer and forwards requests to your application. Some applications need to determine the original request IP and protocol. The user's IP address is available in the standard X-Forwarded-For header. Applications that require this information should configure their web framework to trust the proxy.

Filesystem

The runtime includes a full filesystem. The filesystem is read-only except for the location /tmp, which is a virtual disk storing data in your App Engine instance's RAM.

Metadata server

Each instance of your application can use the App Engine metadata server to query information about the instance and your project.

You can access the metadata server through the following endpoints:

  • http://metadata
  • http://metadata.google.internal

The following table lists the endpoints where you can make HTTP requests for specific metadata:

Metadata endpoint Description
/computeMetadata/v1/project/numeric-project-id The project number assigned to your project.
/computeMetadata/v1/project/project-id The project ID assigned to your project.
/computeMetadata/v1/instance/zone The zone the instance is running in.
/computeMetadata/v1/instance/service-accounts/default/aliases
/computeMetadata/v1/instance/service-accounts/default/email The default service account email assigned to your project.
/computeMetadata/v1/instance/service-accounts/default/ Lists all the default service accounts for your project.
/computeMetadata/v1/instance/service-accounts/default/scopes Lists all the supported scopes for the default service accounts.
/computeMetadata/v1/instance/service-accounts/default/token Returns the auth token that can be used to authenticate your application to other Google Cloud APIs.

For example, to retrieve your project ID, send a request to http://metadata.google.internal/computeMetadata/v1/project/project-id.

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

Send feedback about...

App Engine standard environment for Python 3 docs