There are two ways to specify dependencies for Cloud 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 should not include these files.
Specifying dependencies with pip
Dependencies in Python are managed with pip and expressed in a metadata file
This file must be in the same directory as the
main.py file that contains your
When you deploy your function, Cloud Functions downloads and installs
dependencies declared in the
requirements.txt file using pip.
requirements.txt file contains one line per package. Each line contains
the package name, and optionally, the requested version. For more details, see
The following is an example
Packaging local dependencies
You can also package and deploy dependencies alongside your function. This approach is useful if your dependency is not available via the pip package manager or if your Cloud Functions environment's internet access is restricted.
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
# 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 Functions.