The Python Runtime

The Cloud Functions Python runtime is based on Python version 3.7.1. For instructions on how to prepare your local machine for Python development, see Setting Up a Python Development Environment.

To get started with Python on Cloud Functions, see the Quickstart.

Selecting the runtime

You can select the Python runtime for your function during deployment.


If you are using the gcloud command-line tool, you can specify the runtime by using the --runtime parameter. For example:

gcloud functions deploy NAME --runtime python37 --trigger-http

For more arguments that you can specify when you are deploying, see Deploy using the gcloud tool.


If you are using the GCP Console, you can select the runtime when you create and deploy a function.

  1. In the GCP Console, go to the Cloud Functions Overview page.

    Go to the Cloud Functions Overview page

    Make sure that the project for which you enabled Cloud Functions is selected.

  2. Click Create Function.

  3. Under Runtime, select Python 3.7.

Execution environment

The execution environment includes the runtime, the operating system, packages, and a library that invokes your function.

Base image

For the Python runtime, Cloud Functions uses an execution environment based on Ubuntu 18.04. Updates to the language runtime are done automatically (unless otherwise notified), and include changes in the definition of the base image.

HTTP library

The Python runtime uses Flask to handle incoming requests. This helper invokes your function in response to an incoming request and takes care of other details, such as handling HTTP.

Python packages

The following Python packages are installed alongside your function during deployment. If you are using any of these packages in your function code, we recommend that you include the following versions in your requirements.txt file:


Updates to the execution environment

This runtime receives automatic updates to the version of Python. For example, Cloud Functions currently uses Python version 3.7.1. When a new version of Python is released to the language community, the runtime version might be updated.

Similarly, Cloud Functions might apply updates to other aspects of the execution environment, such as the operating system, packages, and other elements of the environment. These updates help keep your function secure.

Source code structure

Your function's entrypoint must be defined in a Python source file named

Specifying dependencies

A function is allowed to use other third-party libraries as well as other local data. Dependencies in Python are managed with pip and expressed in a metadata file called requirements.txt shipped alongside your function. This file must be in the same directory as the file that contains your function code.

When you deploy your function, Cloud Functions downloads and installs dependencies declared in the requirements.txt file using pip. You can also pre-package fully materialized dependencies alongside your function. See Private dependencies for details.

The requirements.txt file contains one line per library. Each line contains the package name, and optionally, the requested version. For more details, see the requirements.txt reference.

The following is an example requirements.txt file:


Private dependencies

Dependencies are installed in a Cloud Build environment that does not provide access to SSH keys. Packages hosted on repositories that require SSH-based authentication must be vendored and uploaded alongside your project's code. Use pip with the -t DIRECTORY flag to copy dependencies into a local folder before deploying your app, as follows:

  1. Copy dependencies into a local folder:

    pip install -t lib dependency
  2. Add an empty file to the lib directory to turn it into a module.

  3. Import from this module:

    import lib.dependency
Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Functions Documentation