Specify your application dependencies for supported Python versions using any of the following approaches:
-
Use a
requirements.txtfile in the root directory. This file must be in the same directory as themain.pyfile that contains your source code. Therequirements.txtfile contains one line per package. Each line contains the package name, and optionally, the requested version. To prevent your build from being affected by dependency version changes, consider pinning your dependency packages to a specific version.The following is an example
requirements.txtfile:functions - framework requests == 2.20 . 0 numpy -
Use a
pyproject.tomlfile to specify dependencies. If you manage your application dependencies in apyproject.tomlfile instead of therequirements.txtfile, the Python buildpack determines the package manager based on the configuration you specify in thepyproject.tomlfile. For more information, see Deploy Python applications with apyproject.tomlfile .If your application uses both the
pyproject.tomlfile and therequirements.txtfile, therequirements.txtfile takes precedence.-
The following is an example
pyproject.tomlfile:[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 dependencies alongside your function.
Dependency specification using the
Pipfile/Pipfile.lockstandard is not supported. Your project shouldn't include these files.If you use a
requirements.txtfile to manage dependencies, Cloud Run installs the Functions Framework on your behalf when you create a function. However, we recommend that you include Functions Framework as an explicit dependency to avoid discrepancies.When you use a
pyproject.tomlfile, you must include the Functions Framework as a dependency because Cloud Run doesn't install it on your behalf.
Package manager
If you manage your dependencies using a requirements.txt file
, the default package
manager varies based on the Python version you configure.
If you use a pyproject.toml
file to manage dependencies instead of a requirements.txt
file, the Python buildpack determines the
package manager based on your configuration settings in the pyproject.toml
file. The buildpack supports pip, uv and Poetry package
managers. For more information, see Deploy Python applications with a pyproject.toml
file
.
Python 3.14 and later
Starting from Python version 3.14 (preview) and later, the Python
buildpack uses the uv
package manager as the default installer for the dependencies you specify
in your requirements.txt
file.
To use pip
as the package manager,
configure the environment variable GOOGLE_PYTHON_PACKAGE_MANAGER="pip"
.
Run the gcloud run deploy
command to set the package manager environment
variable to pip
:
gcloud run deploy SERVICE
--source . \
--set-build-env-vars=GOOGLE_PYTHON_PACKAGE_MANAGER=pip
Replace SERVICE with the name of your Cloud Run service.
Python 3.13 and earlier
For Python version 3.13 and earlier, the Python
buildpack uses the pip
package manager to install dependencies you define in the requirements.txt
file.
To use uv
(preview) as the package manager,
configure the environment variable GOOGLE_PYTHON_PACKAGE_MANAGER="uv"
.
Run the gcloud beta run deploy
command to set the package manager environment
variable to uv
:
gcloud beta run deploy SERVICE
--source . \
--set-build-env-vars=GOOGLE_PYTHON_PACKAGE_MANAGER=uv
Replace SERVICE with the name of your Cloud Run service.
Package local dependencies
Package and deploy dependencies alongside your function. This approach is useful if your dependency isn't available when you use a supported package manager or if your Cloud Run environment's internet access is restricted.
You can also use a requirements.txt
file to specify additional
dependencies 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 from localpackage
using the following import
statement:
# code in main.py
from
localpackage
import
script
This approach won't run any setup.py
files. You can bundle the packages with those
files, but the package might not run correctly on Cloud Run functions.
Copied dependencies
Copied dependencies are dependencies whose source is included directly
in your source code package and rebuilt alongside your own code.
Use the GOOGLE_VENDOR_PIP_DEPENDENCIES
build environment variable
to create copied pip dependencies and avoid installing them
during deployment.
Create copied dependencies
-
Ensure that python3 is installed on your development system.
-
Declare your application dependencies in a
requirements.txtfile in the root directory of your development tree. -
Declare Functions Framework as a requirement by including
functions-frameworkon a separate line in yourrequirements.txtfile. -
Download your function's dependencies to your local directory. The steps to do this depend on whether the dependency is a Python wheel (*.whl) file or a tar file (*.tar.gz).
-
If the dependency is a Python wheel (*.whl), download it into the root directory of your development tree with this pip command:
python3 - m pip download - r requirements . txt -- only - binary = : all : \ - d DIRECTORY \ -- python - version PYTHON_RUNTIME_VERSION \ -- platform manylinux2014_x86_64 \ -- implementation cpReplace the following:
- DIRECTORY : the name of the local directory to download to.
- PYTHON_RUNTIME_VERSION
: the Python version to use for
compatibility checks. For example
314for Python 3.14.
This version must match one of the supported Python runtimes .
The resulting directory structure should look like this:
myfunction/ ├── main.py └── requirements.txt └── DIRECTORY ├── dependency1.whl └── dependency2.whl
-
If the dependency is a tar file (*.tar.gz):
-
If the dependency is written in Python, use pip to download it:
python3 - m pip download - r requirements . txt \ - d DIRECTORY -
If a dependency consists of code written in C or C++, download and compile the code separately.
-
-
-
Deploy your function and its copied dependencies:
gcloud functions deploy FUNCTION_NAME \ --runtime PYTHON_RUNTIME_NAME \ --set-build-env-vars GOOGLE_VENDOR_PIP_DEPENDENCIES = DIRECTORYReplace the following:
- FUNCTION_NAME : the name of the function you're deploying.
- PYTHON_RUNTIME_NAME : the name of one of the supported Python runtimes to run your deployed function under - for example python311. This must be the same Python runtime version as you've used in your local development environment.
- DIRECTORY : the name of the directory containing your copied dependencies.
For more details about using buildpacks, see Build a function with buildpacks .
Use private dependencies
You can use private dependencies from Artifact Registry or from other repositories.
Private dependencies from Artifact Registry
An Artifact Registry Python
repository
hosts private
dependencies for your Python function. When deploying to Cloud Run,
the build process automatically generates Artifact Registry credentials for the Cloud Build service account
.
Include the Artifact Registry URL in your requirements.txt
without
generating additional credentials. For example:
--
index
-
url
REPOSITORY_URL
sampleapp
Flask
==
0.10.1
google
-
cloud
-
storage
If your build needs multiple repositories, use an Artifact Registry virtual repository to safely control the order that pip searches your repositories.
Private dependencies from other repositories
Buildpacks installs dependencies in a Cloud Build environment that doesn't provide access to SSH keys. Copy the packages you host in repositories that require SSH-based authentication and upload the packages with your project's code.
Use the pip install
command with the -t DIRECTORY
flag to copy private dependencies into
a local directory before deploying your app, as follows:
- Copy your dependency into a local directory:
pip install -t DIRECTORY DEPENDENCY - Add an empty
__init__.pyfile to theDIRECTORYdirectory to turn it into a module. - Import from this module to use your dependency:
import DIRECTORY . DEPENDENCY
Pre-installed packages
The Python buildpack installs the following Python packages
when you deploy your function. If you are using any of these packages in your
function code, include the following versions in your requirements.txt
file:
To avoid issues with dependency version updates, pin the package to a specific version.
The Python buildpack installs the following packages pinned to a specific version:
-
pip(latest version) -
setuptools(latest version) -
wheel(determined by product requirements)
The Python runtime also includes a number of system packages in the execution environment.

