Specify dependencies in Python

Specify your application dependencies forsupported Python versions using any of the following approaches:

  • Use arequirements.txt file in the root directory. This file must be inthe same directory as themain.py file that contains your source code. Therequirements.txt file contains one line per package. Each line containsthe package name, and optionally, the requested version. To prevent yourbuild from being affected by dependency version changes, consider pinningyour dependency packages to a specific version.

    The following is an examplerequirements.txt file:

    functions-frameworkrequests==2.20.0numpy
  • Use apyproject.toml file to specify dependencies. If you manage yourapplication dependencies in apyproject.toml file instead of therequirements.txt file, the Python buildpack determinesthe package manager based on the configuration you specify in thepyproject.toml file. For more information, seeDeploy Python applicationswith apyproject.toml file.

    If your application uses both thepyproject.toml file and therequirements.txt file, therequirements.txt file takes precedence.

    • The following is an examplepyproject.toml file:

      [project]name="demo-app"version="0.1.0"description=""requires-python=">=3.10"dependencies=["flask>=3.1.1","gunicorn>=23.0.0",][build-system]requires=["setuptools>=61.0"]build-backend="setuptools.build_meta"
  • Package local dependenciesalongside your function.

    Dependency specification using thePipfile/Pipfile.lock standard is notsupported. Your project shouldn't include these files.

    If you use arequirements.txt file to manage dependencies,Cloud Run installs theFunctionsFrameworkon your behalf when you create a function. However, we recommend that youinclude Functions Framework as an explicit dependency to avoiddiscrepancies.

    When you use apyproject.toml file, you must include theFunctionsFrameworkas a dependency because Cloud Run doesn't install it on your behalf.

Package manager

If you manage your dependencies using arequirements.txt file, the default packagemanager varies based on the Python version you configure.

If you use apyproject.toml file to manage dependencies instead of arequirements.txt file, the Python buildpack determines thepackage manager based on your configuration settings in thepyproject.tomlfile. The buildpack supports pip, uv and Poetry packagemanagers. For more information, seeDeploy Python applications with apyproject.toml file.

Python 3.14 and later

Starting from Python version 3.14 and later, the Pythonbuildpack uses theuvpackage manager as the default installer for the dependencies you specifyin yourrequirements.txt file.

To usepip as the package manager,configure the environment variableGOOGLE_PYTHON_PACKAGE_MANAGER="pip".

Run thegcloud run deploy command to set the package manager environmentvariable topip:

gcloud run deploySERVICE --source . \  --set-build-env-vars=GOOGLE_PYTHON_PACKAGE_MANAGER=pip

ReplaceSERVICE with the name of your Cloud Run service.

Python 3.13 and earlier

For Python version 3.13 and earlier, the Pythonbuildpack uses thepippackage manager to install dependencies you define in therequirements.txtfile.

To useuv as the package manager,configure the environment variableGOOGLE_PYTHON_PACKAGE_MANAGER="uv".

Run thegcloud run deploy command to set the package manager environmentvariable touv:

gcloud run deploySERVICE --source . \  --set-build-env-vars=GOOGLE_PYTHON_PACKAGE_MANAGER=uv

ReplaceSERVICE with the name of your Cloud Run service.

Package local dependencies

Package and deploy dependencies alongside your function. Thisapproach is useful if your dependency isn't available when you use asupportedpackage manager or if yourCloud Run environment's internet access is restricted.

You can also use arequirements.txt file to specify additionaldependencies you haven't packaged alongside your function.For example, you might use the following directory structure:

myfunction/├── main.py└── localpackage/    ├── __init__.py    └── script.py

Import the code fromlocalpackage using the followingimport statement:

# code in main.pyfromlocalpackageimportscript

This approach won't run anysetup.py files. You can bundle the packages with thosefiles, but the package might not run correctly on Cloud Run functions.

Copied dependencies

Copied dependencies are dependencies whose source is included directlyin your source code package and rebuilt alongside your own code.Use theGOOGLE_VENDOR_PIP_DEPENDENCIES build environment variableto create copied pip dependencies and avoid installing themduring deployment.

Create copied dependencies

  1. Ensure thatpython3 is installed onyour development system.

  2. Declare your application dependenciesin arequirements.txt file in the root directory of your development tree.

  3. Declare Functions Framework as a requirement by includingfunctions-framework on a separate line in yourrequirements.txt file.

  4. Download your function's dependencies to your local directory. The steps todo this depend on whether the dependency is a Python wheel (*.whl) file ora tar file (*.tar.gz).

    1. If the dependency is a Python wheel (*.whl), download it into the rootdirectory of your development tree with this pip command:

      python3-mpipdownload-rrequirements.txt--only-binary=:all: \-dDIRECTORY \--python-versionPYTHON_RUNTIME_VERSION \--platformmanylinux2014_x86_64 \--implementationcp

      Replace the following:

      • DIRECTORY: the name of the local directory todownload to.
      • PYTHON_RUNTIME_VERSION: the Python version to use forcompatibility checks. For example314 for Python 3.14.
        This version must match one of thesupported Python runtimes.

      The resulting directory structure should look like this:

      myfunction/├── main.py└── requirements.txt└──DIRECTORY   ├── dependency1.whl   └── dependency2.whl

    2. If the dependency is a tar file (*.tar.gz):

      1. If the dependency is written in Python, use pip to download it:

        python3-mpipdownload-rrequirements.txt \-dDIRECTORY
      2. If a dependency consists of code written in C or C++, downloadand compile the code separately.

  5. Deploy your function and its copied dependencies:

    gcloudfunctionsdeployFUNCTION_NAME\--runtimePYTHON_RUNTIME_NAME\--set-build-env-varsGOOGLE_VENDOR_PIP_DEPENDENCIES=DIRECTORY

    Replace the following:

    • FUNCTION_NAME: the name of the function you're deploying.
    • PYTHON_RUNTIME_NAME: the name of one of thesupported Python runtimesto run your deployed function under - for example python311.This must be the same Python runtime version as you've used inyour local development environment.
    • DIRECTORY: the name of the directory containing yourcopied dependencies.

For more details about using buildpacks, seeBuild a function with buildpacks.

Use private dependencies

You can use private dependencies from Artifact Registry or from other repositories.

Private dependencies from Artifact Registry

AnArtifact Registry Pythonrepository hosts privatedependencies for your Python function. When deploying to Cloud Run,the build process automatically generates Artifact Registry credentials for theCloud Build service account.Include the Artifact Registry URL in yourrequirements.txt withoutgenerating additional credentials. For example:

--index-urlREPOSITORY_URLsampleappFlask==0.10.1google-cloud-storage

If your build needs multiple repositories, use anArtifact Registry virtual repositoryto safely control the order that pip searches your repositories.

Private dependencies from other repositories

Buildpacks installs dependencies in a Cloud Build environmentthat doesn't provide access to SSH keys. Copy the packages you host in repositories that requireSSH-based authentication and upload the packages with your project'scode.

Use thepip install command with the-tDIRECTORY flag to copy private dependencies intoa local directory before deploying your app, as follows:

  1. Copy your dependency into a local directory:
    pip install -tDIRECTORYDEPENDENCY
  2. Add an empty__init__.py file to theDIRECTORYdirectory to turn it into a module.
  3. Import from this module to use your dependency:
    importDIRECTORY.DEPENDENCY

Pre-installed packages

The Python buildpack installs the following Python packageswhen you deploy your function. If you are using any of these packages in yourfunction code, include the following versions in yourrequirements.txt file:

To avoid issues with dependency version updates, pin the package to a specific version.

anyio==4.5.2blinker==1.8.2click==8.1.8cloudevents==1.11.0deprecation==2.1.0exceptiongroup==1.3.0Flask==3.0.3functions-framework==3.9.1gunicorn==23.0.0h11==0.16.0idna==3.10importlib_metadata==8.5.0itsdangerous==2.2.0Jinja2==3.1.6MarkupSafe==2.1.5packaging==25.0sniffio==1.3.1# Install starlette 0.44.0 for Python 3.8starlette==0.44.0; python_version == '3.8'# Install starlette 0.49.1 for Python versions greater than 3.8starlette==0.49.1; python_version > '3.8'typing_extensions==4.13.2uvicorn==0.33.0uvicorn-worker==0.2.0watchdog==4.0.2Werkzeug==3.0.6zipp==3.20.2

The Python buildpack installs the following packages pinnedto a specific version:

  • pip (latest version)
  • setuptools (latest version)
  • wheel (determined by product requirements)

The Python runtime also includes a number ofsystempackages in the execution environment.

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 2026-02-19 UTC.