Stay organized with collections Save and categorize content based on your preferences.
There are two ways to specify dependencies for Cloud Run functions written in Python: using the pip package manager's requirements.txt
file or packaging local dependencies alongside your function.
Dependency specification using the Pipfile/Pipfile.lock standard is not supported. Your project shouldn't include these files.
The Functions Framework is a required dependency for all functions. Although Cloud Run installs it on your behalf when the function is created, we recommend that you include it as an explicit dependency.
Specify dependencies with pipDependencies in Python are managed with pip and expressed in a metadata file called requirements.txt
. This file must be in the same directory as the main.py
file that contains your function code.
When you deploy or redeploy your function, Cloud Run uses pip to download and install the latest version of your dependencies as declared in the requirements.txt
file. The requirements.txt
file contains one line per package. Each line contains the package name, and optionally, the requested version. For more details, see the requirements.txt
reference.
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.txt
file:
functions-framework requests==2.20.0 numpyPackage local dependencies
You can also package and deploy dependencies alongside your function. This approach is useful if your dependency is not available using the pip package manager or if your Cloud Run environment's internet access is restricted.
Note: You can still use arequirements.txt
file to specify additional dependencies you haven't packaged alongside your function.
For example, you might use a directory structure such as the following:
myfunction/ ├── main.py └── localpackage/ ├── __init__.py └── script.py
You can then import the code as usual from localpackage
using the following import
statement.
# Code in main.py from localpackage import script
Note that this approach will not run any setup.py
files. Packages with those files can still be bundled, but may not run correctly on Cloud Run functions.
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.
Ensure that python3 is installed on your development system.
Declare your application dependencies in a requirements.txt
file in the root directory of your development tree.
Declare Functions Framework as a requirement by including functions-framework
on a separate line in your requirements.txt
file.
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 cp
Replace:
311
for Python 3.11. 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++, you must download and compile it 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=DIRECTORY
Replace:
For more details about using buildpacks, see Build a function with buildpacks.
Use private dependenciesYou can use private dependencies from Artifact Registry or from other repositories.
Private dependencies from Artifact RegistryAn Artifact Registry Python repository can host private dependencies for your Python function. When deploying to Cloud Run, the build process will automatically generate Artifact Registry credentials for the Cloud Build service account. You only need to 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 repositoriesDependencies are installed in a Cloud Build environment that does not provide access to SSH keys. Packages hosted in repositories that require SSH-based authentication must be copied and uploaded alongside your project's code, as described in the previous section.
You can 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__.py
file to the DIRECTORY
directory to turn it into a module.
Import from this module to use your dependency:
import DIRECTORY.DEPENDENCY
The following Python packages are automatically 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:
requirements.txt
file, the following packages will always be pinned to a specific version:
* `pip` (latest version)
* `setuptools` (latest version)
* `wheel` (determined by product requirements)
In addition, the Python runtime includes a number of system packages in the execution environment.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4