{"id":4555,"library":"google-cloud-functions","title":"Google Cloud Functions Client Library","description":"The `google-cloud-functions` Python client library provides a programmatic interface for managing Google Cloud Functions. Cloud Functions is a scalable, pay-as-you-go Functions-as-a-Service (FaaS) offering that allows you to run event-driven code without managing servers. This library is part of the larger `google-cloud-python` monorepo, with its latest version being 1.23.0, and it requires Python 3.9 or higher. While the monorepo sees frequent updates, this specific client library updates less frequently. [3, 19, 25]","status":"active","version":"1.23.0","language":"en","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-functions","tags":["google-cloud","gcp","serverless","functions-as-a-service","faas","cloud-run"],"install":[{"cmd":"pip install google-cloud-functions","lang":"bash","label":"Install the client library"},{"cmd":"pip install functions-framework","lang":"bash","label":"Install Functions Framework (for writing/testing functions)"}],"dependencies":[{"reason":"Essential for writing and locally testing Python Google Cloud Functions, and should be included in your function's `requirements.txt`. [4, 6, 8, 11]","package":"functions-framework","optional":false}],"imports":[{"note":"Use the versioned client for managing functions (v1 or v2). Older patterns might reference `functions_v1` or a non-versioned `functions` module directly, which might be deprecated or lack features. [17, 27]","wrong":"from google.cloud.functions import Client","symbol":"CloudFunctionsServiceClient","correct":"from google.cloud.functions_v2 import CloudFunctionsServiceClient"},{"note":"When writing a Cloud Function, you use decorators from `functions_framework` to define HTTP or event-driven functions, not the `google-cloud-functions` client library directly. [4, 11]","symbol":"http, CloudEvent","correct":"import functions_framework\n@functions_framework.http\n# or\n@functions_framework.cloud_event"}],"quickstart":{"code":"import functions_framework\nimport os\n\n@functions_framework.http\ndef hello_http(request):\n    \"\"\"HTTP Cloud Function that responds to HTTP requests.\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\n        Response object using `make_response`.\n    \"\"\"\n    request_json = request.get_json(silent=True)\n    request_args = request.args\n\n    # Example of accessing an environment variable set during deployment\n    target_name = os.environ.get('FUNCTION_TARGET_NAME', 'World')\n\n    name = target_name\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\n    return f'Hello {name}!'\n\n# To deploy this function (save as main.py):\n# gcloud functions deploy hello-http --gen2 --runtime=python312 \\\n# --region=us-central1 --source=. --entry-point=hello_http --trigger-http \\\n# --set-env-vars=FUNCTION_TARGET_NAME=Pythonista\n\n# To test locally after `pip install functions-framework`:\n# functions-framework --target hello_http --debug\n# Then send a request to http://localhost:8080/\n","lang":"python","description":"This quickstart demonstrates how to write a simple HTTP-triggered Google Cloud Function using the `functions-framework` library, which is the standard for defining and running Python Cloud Functions. To deploy, save the code as `main.py` and use the `gcloud functions deploy` command. For local testing, install `functions-framework` and run it against your function. [4, 8, 11]"},"warnings":[{"fix":"Review the migration guide for 1st to 2nd Gen functions. This involves updating function signatures, trigger definitions (now Eventarc), and potentially `gcloud` deployment commands. Plan for phased rollout or new deployments. [14, 21]","message":"Migration from Cloud Functions 1st generation to 2nd generation (now often referred to as 'Cloud Run functions') involves significant architectural changes. Direct redeployment of a 1st Gen function as 2nd Gen can break existing triggers due to the shift from native triggers to Eventarc. [14, 21, 29]","severity":"breaking","affected_versions":"All versions when migrating between generations"},{"fix":"Ensure your local development environment and deployed Cloud Function runtimes use Python 3.9 or higher. Update your `runtime` specification in `gcloud functions deploy` if necessary (e.g., `--runtime=python312`). [3, 19]","message":"Python versions older than 3.9 are no longer supported. Deploying functions with unsupported Python runtimes will fail. [3, 19]","severity":"breaking","affected_versions":"< 1.0.0"},{"fix":"Grant the `Cloud Functions Invoker` role to the service account or user invoking the function. For programmatic invocation, use `google.oauth2.id_token.fetch_id_token` to generate an ID token for the target function's URL and include it in the `Authorization: Bearer` header. [16, 20]","message":"Authentication for HTTP-triggered Cloud Functions, especially when invoked programmatically, requires proper IAM permissions (`roles/cloudfunctions.invoker`) for the calling identity and often the use of an Identity Token (ID Token), not just an OAuth Access Token. Unauthenticated invocations must be explicitly enabled during deployment. [15, 16, 20, 26]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `requirements.txt` for your function's dependencies. If using private packages, refer to Google Cloud documentation for integrating with Artifact Registry or packaging local dependencies. Ensure `functions-framework` is listed. [1, 2, 8]","message":"Python dependencies for Cloud Functions are exclusively managed via a `requirements.txt` file in the root of your function's source directory. Tools like `Pipfile`/`Pipfile.lock` are not supported. For private dependencies or local packages, specific bundling or Artifact Registry configurations are required. The `functions-framework` library should be explicitly listed in `requirements.txt`. [1, 6, 8]","severity":"gotcha","affected_versions":"All versions"},{"fix":"Familiarize yourself with the differences between 1st and 2nd generation functions and the features inherited from Cloud Run. When deploying 2nd Gen functions, consider using the `--gen2` flag with `gcloud functions deploy` or directly leveraging Cloud Run deployment commands for finer control. [12, 14, 29]","message":"Cloud Functions (2nd gen) are now referred to as 'Cloud Run functions' due to their underlying infrastructure being Cloud Run. While the `google-cloud-functions` client library can manage both generations, understanding this naming convention and the benefits of 2nd gen (concurrency, longer timeouts, Eventarc integration) is crucial. [12, 14, 29]","severity":"gotcha","affected_versions":"All versions (conceptual shift)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}