You can use the Functions Framework for Python to run the function locally.

Given a function in a file named main.py like so:

def my_function(request):
    return 'Hello World'

You can do:

$ pip install functions-framework
$ functions-framework --target my_function

Which will start a local development server at http://localhost:8080.

To invoke it locally for an HTTP function:

$ curl http://localhost:8080

For a background function with non-binary data:

$ curl -d '{"data": {"hi": "there"}}' -X POST \
-H "Content-Type: application/json" \
http://localhost:8080

For a background function with binary data:

$ curl -d "@binary_file.file" -X POST \
-H "Ce-Type: true" \
-H "Ce-Specversion: true" \
-H "Ce-Source: true" \
-H "Ce-Id: true" \
-H "Content-Type: application/json" \
http://localhost:8080
Answer from Dustin Ingram on Stack Overflow
🌐
GitHub
github.com › GoogleCloudPlatform › functions-framework-python
GitHub - GoogleCloudPlatform/functions-framework-python: FaaS (Function as a service) framework for writing portable Python functions · GitHub
An open source FaaS (Function as a service) framework for writing portable Python functions -- brought to you by the Google Cloud Functions team.
Starred by 966 users
Forked by 120 users
Languages   Python
🌐
PyPI
pypi.org › project › functions-framework
functions-framework · PyPI
An open source FaaS (Function as a service) framework for writing portable Python functions -- brought to you by the Google Cloud Functions team.
      » pip install functions-framework
    
Published   Feb 17, 2026
Version   3.10.1
Discussions

firebase - Test Python Google Cloud Functions locally - Stack Overflow
Divisadero no longer maintains this pre-google-emulator one 2021-11-02T09:31:27.79Z+00:00 ... Sure @dinigo, I'll try using the official emulator. Thanks ^^ 2021-11-02T10:05:19.07Z+00:00 ... Currently there are only implementations in Node.js, Go, and PHP, but see Issue #5 about the Python implementation. I suggest, whatever implementation you use, to follow the Functions Framework ... More on stackoverflow.com
🌐 stackoverflow.com
How am I supposed to use functions-framework to test my cloud functions?
One option is to use a web framework in Cloud Functions, like Express or Flask. See the official doc here . If your backend exposes many endpoints to a frontend application, you might find it easier to use Cloud Run. You'd write an application in your favorite server-side web framework (Python/Flask, Node/Express, etc). You'd run that application on your local machine for testing, without using anything specific to Google Cloud. Then you'd deploy it to the cloud with gcloud run deploy --source . I recently worked on a project where the number of Cloud Functions had grown over time. We managed for a while by adding a framework. But in the end we migrated to Cloud Run to make management of all the endpoints easier, to simplify local development, and to standardize things like authentication. Now we use Cloud Functions only to react to events like database updates. For us, that is the sweet spot for Cloud Functions. We feel that Cloud Run is great at exposing a large API surface to clients. More on reddit.com
🌐 r/googlecloud
5
9
February 23, 2023
How to install google.cloud.functions_v1 in python? - Stack Overflow
I found this library: functions-framework on GoogleCloudPlatform/functions-framework-python github repository. More on stackoverflow.com
🌐 stackoverflow.com
What is the advantage to using the Function Framework to test my Google Cloud functions locally, instead of just invoking them directly?
Hey there, As others have pointed out, the point of Function Framework is to give you a local execution environment that mimics a production environment, without having to write the boilerplate for running an HTTP server nor having to write mocks and manual unmarshalling for things like CloudEvent messages. It's especially useful when you're working within a larger code base, where you have multiple teams of engineers writing lots of different functions. Having a single abstraction for handling how functions are tested, without each team or engineer writing their own harness, allows for a consistent (and less buggy) experience across the organization. Additionally, when working across many teams with many engineers, it's often desirable to test locally without having to have each engineer need a staging environment for each and every function that is run, which in turn let's you write fully hermetic tests . Internally at Google, our testing systems are heavily restricted from reaching out to production services during tests, specifically to avoid issues like "I just ran this RPC that deleted every user in the live database." We've come to find that even if you have a staging environment, it's incredibly easy to misconfigure your tests to run against a production environment, thus local testing frameworks and hermetic testing. As you have already noted, you definitely don't need to use Function Framework for your tests as it's mostly just convenience wrappers. You can achieve all of the above your self, without the framework. If you want to manually write the boilerplate for your language, that's entirely possible as you have noted. You can also just test directly on the real system -- this is a common pattern in the world of open source :) Hope this helps! More on reddit.com
🌐 r/googlecloud
24
2
July 9, 2022
🌐
GitHub
github.com › GoogleCloudPlatform › functions-framework
GitHub - GoogleCloudPlatform/functions-framework: The Contract for Building New Function Frameworks · GitHub
For this reason, it is important that the steps taken by the function-to-app converter are idiomatic to the programming language selected for the Functions Framework. For example, a function-to-app converter written for a Python Functions Framework should expose a WSGI app which can be used by multiple HTTP servers such as gunicorn.
Starred by 158 users
Forked by 15 users
🌐
Medium
medium.com › @jamiekt › til-debugging-google-cloud-functions-in-visual-studio-code-using-functions-framework-8c6feef2b51a
TIL: Debugging Google Cloud Functions, written in Python, in Visual Studio Code, using functions framework | by Jamie Thomson | Medium
March 11, 2022 - That is, test your function without having to deploy it to Google Cloud Platform (GCP). I currently use Visual Studio Code as my IDE so that’s what this blog post will be about. The trick is to use Functions Framework. I’m using Python for my Cloud Functions so I’ll need to install Functions Framework using pip:
🌐
DEV Community
dev.to › bornfightcompany › testing-cloud-functions-with-functions-framework-in-python-9cf
Testing Cloud Functions with functions-framework in python - DEV Community
September 5, 2021 - They work as you'd expect them ... to say the least. Google's functions-framework module sets up a local instance of your CF, but it doesn't run it automatically....
🌐
Google Cloud
cloud.google.com › cloud run › local functions development
Local functions development | Cloud Run | Google Cloud Documentation
Command-line arguments must be specified when you run the framework. Note: Command-line arguments take precedence over environment variables when running the Python Functions Framework.
Top answer
1 of 4
48

You can use the Functions Framework for Python to run the function locally.

Given a function in a file named main.py like so:

def my_function(request):
    return 'Hello World'

You can do:

$ pip install functions-framework
$ functions-framework --target my_function

Which will start a local development server at http://localhost:8080.

To invoke it locally for an HTTP function:

$ curl http://localhost:8080

For a background function with non-binary data:

$ curl -d '{"data": {"hi": "there"}}' -X POST \
-H "Content-Type: application/json" \
http://localhost:8080

For a background function with binary data:

$ curl -d "@binary_file.file" -X POST \
-H "Ce-Type: true" \
-H "Ce-Specversion: true" \
-H "Ce-Source: true" \
-H "Ce-Id: true" \
-H "Content-Type: application/json" \
http://localhost:8080
2 of 4
13

Update

Please, use the official emulator and serving framework from GCP https://github.com/GoogleCloudPlatform/functions-framework-python

You can install it with

pip install functions-framework

Deprecated

Based on Dustin's answer I've developed a package to serve as emulator:

pip install gcp-functions-emulator

Given you want to serve the following function

# mycloudfunction.py
def api(request):
  return 'important data'

To emulate we have to call it like so:

gcpfemu <path/to/file.py> <function_name>

For example, with the code above we will call it:

gcpfemu mycloudfunction.py api

And to access the data we can use for example curl:

curl localhost:5000/api
> important data
Find elsewhere
🌐
Google
docs.cloud.google.com › cloud run › write cloud run functions
Write Cloud Run functions | Google Cloud Documentation
import functions_framework # Register an HTTP function with the Functions Framework @functions_framework.http def my_http_function(request): # Your code here # Return an HTTP response return 'OK' In Python, you register an HTTP handler function with the Functions Framework for Python.
🌐
DeepWiki
deepwiki.com › GoogleCloudPlatform › functions-framework-python › 4-deployment-examples
Deployment | GoogleCloudPlatform/functions-framework-python | DeepWiki
November 15, 2025 - Functions can run on local development machines, Google Cloud Functions, Cloud Run, Knative clusters, or any container platform. ... The Functions Framework is distributed as a Python package on PyPI under the name functions-framework.
🌐
PyPI
pypi.org › project › google-cloud-functions
google-cloud-functions · PyPI
View this README to see the full list of Cloud APIs that we cover. This library uses the standard Python logging functionality to log some RPC events that could be of interest for debugging and monitoring purposes.
      » pip install google-cloud-functions
    
🌐
DEV Community
dev.to › googlecloud › portable-cloud-functions-with-the-python-functions-framework-a6a
Portable Cloud Functions with the Python Functions Framework - DEV Community
February 17, 2021 - I'll also show you how the Functions Framework gives you the ability to test your functions locally as well. The Function Frameworks are open source libraries for writing portable functions -- brought to you by the Google Cloud Functions team.
🌐
Medium
medium.com › google-cloud › setup-and-invoke-cloud-functions-using-python-e801a8633096
Setup and Invoke Cloud Functions using Python | by Warrick | Google Cloud - Community | Medium
July 7, 2020 - This post assumes you have the gcloud SDK already installed locally and that you have a Google Cloud project setup. I’ve got previous posts that cover these topics. I used Python 3.7 in the function and a Mac for local development. If you want to test your code before running in Cloud Functions then you can do that with Functions Framework for Python.
🌐
Medium
medium.com › ci-t › how-to-develop-debug-and-test-your-python-google-cloud-functions-on-your-local-dev-environment-d56ef94cb409
How to Develop, Debug and Test your Python Google Cloud Functions on Your Local Development Environment | by Ivam Luz | CI&T | Medium
July 6, 2020 - Disclaimer: this sample project will also serve as the basis for a future tutorial I intend to publish on how to automate the deployment of Google Cloud Functions using Google Cloud Build, hence the name. To achieve our objective, we’ll make use of the Functions Framework for Python, an open source FaaS (Function as a service) framework for writing portable Python functions — brought to you by the Google Cloud Functions team.
🌐
OneUptime
oneuptime.com › home › blog › how to write and deploy python cloud functions gen 2
How to Write and Deploy Python Cloud Functions Gen 2
February 17, 2026 - This post walks through writing Cloud Functions in Python with the Functions Framework, testing locally, and deploying to GCP. ... # Install the Functions Framework and any dependencies pip install functions-framework google-cloud-storage google-cloud-pubsub
🌐
Reddit
reddit.com › r/googlecloud › how am i supposed to use functions-framework to test my cloud functions?
r/googlecloud on Reddit: How am I supposed to use functions-framework to test my cloud functions?
February 23, 2023 -

It seems like whenever you run `functions-framework` locally, it deploys your function on localhost on a port of your choosing. This works great if you are developing a new function and just need to test it in a quick and easy way, but how are you supposed to write code that lets you easily develop and test multiple functions over time? I'm aware that firebase might solve that, but the reason I am asking this question is to understand what the state-of-the-art is outside of firebase.

The problem is, if I have code that hits my function URL, and then I want to update the function and test it as part of my application, it seems like I have to set a per-function environment variable that swaps out the HTTP trigger uri for the localhost:PORT testing URI. That's pretty annoying when you have to have a separate env variable for each function you might test.

Surely I'm missing something here? What do people do in this situation?

EDIT: Found this github issue (https://github.com/GoogleCloudPlatform/functions-framework-nodejs/issues/23) that seems to indicate that there's no equivalent solution to firebase/the old functions emulator for serving multiple functions locally, but you can fairly easily work around it by writing a little bit of code to multiplex your functions manually. I wish this was included in the official docs rather than just in the Github Issue!

🌐
GitHub
github.com › GoogleCloudPlatform › functions-framework-python › blob › main › src › functions_framework › __init__.py
functions-framework-python/src/functions_framework/__init__.py at main · GoogleCloudPlatform/functions-framework-python
FaaS (Function as a service) framework for writing portable Python functions - functions-framework-python/src/functions_framework/__init__.py at main · GoogleCloudPlatform/functions-framework-python
Author   GoogleCloudPlatform
🌐
Firebase
firebase.google.com › documentation › cloud functions
Cloud Functions for Firebase
1 week ago - Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by background events, HTTPS requests, the Admin SDK, or Cloud Scheduler jobs. Your JavaScript, TypeScript or Python code is stored on Google Cloud infrastructure ...
🌐
GitHub
github.com › GoogleCloudPlatform › functions-framework-python › blob › main › src › functions_framework › _cli.py
functions-framework-python/src/functions_framework/_cli.py at main · GoogleCloudPlatform/functions-framework-python
FaaS (Function as a service) framework for writing portable Python functions - functions-framework-python/src/functions_framework/_cli.py at main · GoogleCloudPlatform/functions-framework-python
Author   GoogleCloudPlatform