Python 3 runtime environment - App Engine - Google Cloud.

The Python runtime is the software stack responsible for installingyour web service's code and its dependencies and running your App Engine service.

The Python runtime for App Engine in the standard environment isdeclared in theapp.yamlfile:

runtime:pythonVERSION

WhereVERSION is the PythonMAJOR andMINOR version numbers. Forexample, to use the latest Python version, Python 3.14 (preview), specify314.

For other supported Python versions, and the corresponding Ubuntu version for yourPython version, see theRuntime support schedule.

Python 3 versions

The latest supported Python version is 3.14 (preview). The Python runtime uses the latest stable release of theversion that is specified in yourapp.yaml file.App Engine automatically updates to new patch versions,but it does not automatically update the minor version.

For example, your application might be deployed at Python 3.7.0 and laterautomatically updated to Python 3.7.1, but it will not be automatically updatedto the next minor version Python 3.8.0.

Try it for yourself

If you're new to Google Cloud, create an account to evaluate how App Engine performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try App Engine free

App Engine runs Python apps in a container secured by gVisor on anup-to-date Ubuntu Linux distribution.

Dependencies

During deployment, App Engine uses the Python package managerpip to install dependenciesdefined in therequirements.txtmetadata file located in your project's root directory. You do not need toupload dependencies as App Engine performs a fresh install.

Dependency specification using thePipfile/Pipfile.lock standard iscurrently not supported and your project must not have these files present.

Application startup

The runtime starts your app by running the command you specify in theentrypoint fieldin yourapp.yaml file. If you have configured a Gunicorn web serverentrypoint in theapp.yaml file, you must also addgunicorn to yourrequirements.txt file.

The entrypoint should start a web server that listenson the port specified by thePORT environment variable. For example:

entrypoint:gunicorn-b:$PORTmain:app

The web framework that your app uses is responsible for routing requests to theappropriate handlers in your app.

If your app meets the following requirements, App Engine will startyour app with thegunicorn web server if you don'tspecify theentrypoint field:

  • The root of your app directory contains amain.py file with aWSGI-compatible object calledapp.

  • Your app does not containPipfile orPipfile.lock files.

If you do not specify an entrypoint for the Python 3 runtime, App Engineconfigures and starts the default Gunicorn web server.

Note: Thedefault timeout ofgunicorn is 30seconds when theentrypoint field is specified. Workers silent for more thanthis many seconds are killed and restarted. If your handler takes more than 30seconds, you may face[CRITICAL] WORKER TIMEOUT error. To ensure that therequest successfully completes, based on your use-case, you can use the--timeout flag in theentrypoint field to increase the timeout.

Entrypoint best practices

  • Ensure the Python module required to run the specified entrypoint inapp.yaml is present in therequirements.txt file. Addgunicorn to therequirements.txt file only if agunicorn endpoint is explicitly specifiedin theapp.yaml file.

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

  • You can use the entrypoint field to tune the performance of your app. Forexample, if you usegunicorn as your web server, you can use the--workers flagin the entrypoint field to configure the number of workers serving your app.

    The number of workers you specify should match theinstance classof your App Engine app:

    Instance classWorkers
    F12
    F24
    F48
    F4_1G8
    B12
    B24
    B48
    B4_1G8
    B88

    This guidance serves as a starting point for selecting thenumber of workers. You may need to use a different number of workersdepending on your app's performance characteristics.The example below shows an App Engine deployment that uses twogunicorn workers for serving apps:

    entrypoint:gunicorn-b:$PORT-w2main:app
  • We recommend that you configure your web server to listen and respond to HTTPrequests on the port specified by your$PORTenvironment variable. Using the default port8080prevents App Engine from using its NGINX layer to compress HTTPresponses. Note that if you use port8080, warnings aboutport8080 and NGINX will show in your app's log files.

Other web frameworks

In addition to Django and Flask, you can use other web frameworks withApp Engine, such asuwsgi andTornado. The following example showshow to useuwsgi with App Engine:

runtime:python313entrypoint:uwsgi --http-socket :$PORT --wsgi-file main.py --callable app --master --processes 1 --threads 2
uwsgi==2.0.22Flask==3.0.0

Environment variables

The following environment variables are set by the runtime:

Environment variableDescription
GAE_APPLICATIONThe ID of your App Engine application.This ID is prefixed with 'region code~'such as 'e~' for applications deployed in Europe.
GAE_DEPLOYMENT_IDThe ID of the current deployment.
GAE_ENVThe App Engine environment. Set tostandard.
GAE_INSTANCEThe ID of the instance on which your service is currently running.
GAE_MEMORY_MBThe amount of memory available to the application process, in MB.
GAE_RUNTIMEThe runtime specified in yourapp.yaml file.
GAE_SERVICEThe service name specified in yourapp.yaml file. If no service name is specified, it is set todefault.
GAE_VERSIONThe current version label of your service.
GOOGLE_CLOUD_PROJECTThe Google Cloud project ID associated with your application.
PORTThe port that receives HTTP requests.
NODE_ENV (Only available in the Node.js runtime)Set toproduction when your service is deployed.

You candefine additional environment variables in yourapp.yaml file,but the above values cannot be overridden, except forNODE_ENV.

HTTPS and forwarding proxies

App Engine terminates HTTPS connections at the load balancer andforwards requests to your application. Some applications need to determinethe original request IP and protocol. The user's IP address is available inthe standardX-Forwarded-For header. Applications that require thisinformation should configure their web framework to trust the proxy.

Filesystem

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

Metadata server

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

Note: Custom metadata is not supported in the standard environment.

You can access the metadata server through the following endpoints:

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

Requests sent to the metadata server must include the request headerMetadata-Flavor: Google. This header indicates that the request was sent withthe intention of retrieving metadata values.

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

Metadata endpointDescription
/computeMetadata/v1/project/numeric-project-idThe project number assigned to your project.
/computeMetadata/v1/project/project-idThe project ID assigned to your project.
/computeMetadata/v1/instance/regionThe region the instance is running in.
/computeMetadata/v1/instance/service-accounts/default/aliases
/computeMetadata/v1/instance/service-accounts/default/emailThe 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/scopesLists all the supported scopes for the default service accounts.
/computeMetadata/v1/instance/service-accounts/default/tokenReturns 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 tohttp://metadata.google.internal/computeMetadata/v1/project/project-id.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.