{"id":1486,"library":"functions-framework","title":"Functions Framework for Python","description":"Functions Framework for Python is an open-source FaaS (Function as a Service) framework designed for writing portable Python functions. It allows developers to test their Google Cloud Functions locally, run them in other serverless environments, or deploy them directly to Google Cloud. The current version is 3.10.1, and it maintains an active release cadence with frequent patch and minor updates, typically every 1-3 months.","status":"active","version":"3.10.1","language":"en","source_language":"en","source_url":"https://github.com/googlecloudplatform/functions-framework-python","tags":["serverless","google cloud","cloud functions","faas","http","events","local development"],"install":[{"cmd":"pip install functions-framework","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Used for handling HTTP functions. Requires Flask 2.0+ since functions-framework v3.8.3.","package":"Flask","optional":false},{"reason":"Used for handling CloudEvent functions. Version ranges are managed by functions-framework.","package":"cloudevents","optional":true},{"reason":"Used as the default WSGI web server for running functions locally or in deployed environments.","package":"gunicorn","optional":false}],"imports":[{"note":"For HTTP functions, the primary input argument is a Flask Request object. No direct import of `functions_framework` is typically needed in your function code.","symbol":"Request","correct":"from flask import Request"},{"note":"For CloudEvent functions, the primary input argument is a CloudEvent object. No direct import of `functions_framework` is typically needed in your function code.","symbol":"CloudEvent","correct":"from cloudevents.http import CloudEvent"}],"quickstart":{"code":"# main.py\n\ndef hello_http(request):\n    \"\"\"Responds to any HTTP request.\n    Args:\n        request (flask.Request): The request object.\n    Returns:\n        The response text, or any set of values that can be turned into a Response object \n        using `make_response`.\n    \"\"\"\n    request_json = request.get_json(silent=True)\n    request_args = request.args\n\n    if request_json and 'name' in request_json:\n        name = request_json['name']\n    elif request_args and 'name' in request_args:\n        name = request_args['name']\n    else:\n        name = 'World'\n    return f'Hello {name}!'\n\n# To run locally:\n# 1. Save this as main.py\n# 2. Run from your terminal: functions-framework --target hello_http\n# 3. Access at http://localhost:8080/","lang":"python","description":"Define an HTTP function `hello_http` in a file (e.g., `main.py`). The function receives a `flask.Request` object. Run it locally using the `functions-framework` CLI, specifying the function name with `--target`. By default, it runs on port 8080."},"warnings":[{"fix":"Upgrade Flask to version 2.0 or newer: `pip install 'Flask>=2.0'` or ensure your environment satisfies this requirement.","message":"Functions Framework v3.8.3 and later require Flask 2.0 or higher. If your project uses an older version of Flask, you may encounter `ImportError` or other compatibility issues.","severity":"breaking","affected_versions":">=3.8.3"},{"fix":"Always provide `--target <your_function_name>` when invoking `functions-framework` from the command line.","message":"When running locally, you must specify the target function using the `--target` flag (e.g., `functions-framework --target my_function`). Failing to do so will result in an error indicating no target was found.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review the function signature: `def my_http_function(request: Request):` for HTTP or `def my_cloud_event_function(event: CloudEvent):` for CloudEvent types.","message":"Ensure your function signature matches the expected type (HTTP or CloudEvent). HTTP functions take a `flask.Request` object. CloudEvent functions take a `cloudevents.CloudEvent` object.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly access `event.data` for the actual payload. For example, `event_data = event.data` or `message = json.loads(event.data)['message']` for Pub/Sub events.","message":"For CloudEvents, access the event data via `event.data` for the actual payload. CloudEvents often wrap the original payload (e.g., Pub/Sub messages are nested).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `functions-framework` v3.10.1 or newer to ensure correct `cloudevents` dependency handling. If stuck on an older version, manually pin `cloudevents` to a compatible range (e.g., `<1.11.0` if using an older `functions-framework` version).","message":"Version 3.10.1 corrected the `cloudevents` dependency to allow `1.11.0`. Older `functions-framework` versions might have had improperly constrained `cloudevents` dependencies, potentially leading to issues if `cloudevents` was upgraded to an incompatible version.","severity":"breaking","affected_versions":"<3.10.1"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}