From 877114df5e38564de866503e4a7ca1473cbc5dd3 Mon Sep 17 00:00:00 2001 From: divyanshu-iitian Date: Wed, 18 Feb 2026 02:02:32 +0530 Subject: [PATCH] Fix README Typos Review the README file and fix any typos, grammatical errors, or formatting issues to improve readability and clarity It helps to create a professional and polished first impression for new users and maintainers, making it easier for them to understand the project --- README.md | 159 ++++++------------------------------------------------ 1 file changed, 17 insertions(+), 142 deletions(-) diff --git a/README.md b/README.md index d564ad92..9b0ae765 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPI version](https://badge.fury.io/py/functions-framework.svg)](https://badge.fury.io/py/functions-framework) -[![Python unit CI][ff_python_unit_img]][ff_python_unit_link] [![Python lint CI][ff_python_lint_img]][ff_python_lint_link] [![Python conformace CI][ff_python_conformance_img]][ff_python_conformance_link] ![Security Scorecard](https://api.securityscorecards.dev/projects/github.com/GoogleCloudPlatform/functions-framework-python/badge) +[![Python unit CI][ff_python_unit_img]][ff_python_unit_link] [![Python lint CI][ff_python_lint_img]][ff_python_lint_link] [![Python conformance CI][ff_python_conformance_img]][ff_python_conformance_link] ![Security Scorecard](https://api.securityscorecards.dev/projects/github.com/GoogleCloudPlatform/functions-framework-python/badge) An open source FaaS (Function as a service) framework for writing portable Python functions -- brought to you by the Google Cloud Functions team. @@ -16,17 +16,13 @@ different environments, including: The framework allows you to go from: -```python def hello(request): return "Hello world!" -``` To: -```sh curl http://my-url # Output: Hello world! -``` All without needing to worry about writing an HTTP server or complicated request handling logic. @@ -41,15 +37,11 @@ All without needing to worry about writing an HTTP server or complicated request Install the Functions Framework via `pip`: -```sh pip install functions-framework -``` Or, for deployment, add the Functions Framework to your `requirements.txt` file: -``` functions-framework==3.* -``` ## Quickstarts @@ -57,20 +49,17 @@ functions-framework==3.* Create an `main.py` file with the following contents: -```python import flask import functions_framework @functions_framework.http def hello(request: flask.Request) -> flask.typing.ResponseReturnValue: return "Hello world!" -``` > Your function is passed a single parameter, `(request)`, which is a Flask [`Request`](https://flask.palletsprojects.com/en/3.0.x/api/#flask.Request) object. Run the following command: -```sh functions-framework --target hello --debug * Serving Flask app "hello" (lazy loading) * Environment: production @@ -78,7 +67,6 @@ functions-framework --target hello --debug Use a production WSGI server instead. * Debug mode: on * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit) -``` (You can also use `functions-framework-python` if you have multiple language frameworks installed). @@ -87,35 +75,28 @@ Open http://localhost:8080/ in your browser and see *Hello world!*. Or send requests to this function using `curl` from another terminal window: -```sh curl localhost:8080 # Output: Hello world! -``` ### Quickstart: CloudEvent Function Create an `main.py` file with the following contents: -```python import functions_framework from cloudevents.http.event import CloudEvent @functions_framework.cloud_event def hello_cloud_event(cloud_event: CloudEvent) -> None: print(f"Received event with ID: {cloud_event['id']} and data {cloud_event.data}") -``` > Your function is passed a single [CloudEvent](https://github.com/cloudevents/sdk-python/blob/main/cloudevents/sdk/event/v1.py) parameter. Run the following command to run `hello_cloud_event` target locally: -```sh functions-framework --target=hello_cloud_event -``` In a different terminal, `curl` the Functions Framework server: -```sh curl -X POST localhost:8080 \ -H "Content-Type: application/cloudevents+json" \ -d '{ @@ -127,12 +108,10 @@ curl -X POST localhost:8080 \ "time" : "2018-04-05T17:31:00Z", "data" : "hello world" }' -``` Output from the terminal running `functions-framework`: -``` Received event with ID: A234-1234-1234 and data hello world -``` + More info on sending [CloudEvents](http://cloudevents.io) payloads, see [`examples/cloud_run_cloud_events`](examples/cloud_run_cloud_events/) instruction. @@ -143,7 +122,6 @@ The framework includes an error handler that is similar to the [`flask.Flask.errorhandler`](https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask.errorhandler) function, which allows you to handle specific error types with a decorator: -```python import functions_framework @@ -155,7 +133,6 @@ def handle_zero_division(e): def function(request): 1 / 0 return "Success", 200 -``` This function will catch the `ZeroDivisionError` and return a different response instead. @@ -163,36 +140,27 @@ response instead. ### Quickstart: Pub/Sub emulator 1. Create a `main.py` file with the following contents: - ```python - def hello(event, context): + def hello(event, context): print("Received", context.event_id) - ``` - + 1. Start the Functions Framework on port 8080: - ```sh - functions-framework --target=hello --signature-type=event --debug --port=8080 - ``` - + functions-framework --target=hello --signature-type=event --debug --port=8080 + 1. In a second terminal, start the Pub/Sub emulator on port 8085. - ```sh - export PUBSUB_PROJECT_ID=my-project + export PUBSUB_PROJECT_ID=my-project gcloud beta emulators pubsub start \ --project=$PUBSUB_PROJECT_ID \ --host-port=localhost:8085 - ``` - + You should see the following after the Pub/Sub emulator has started successfully: - ```none - [pubsub] INFO: Server started, listening on 8085 - ``` - + [pubsub] INFO: Server started, listening on 8085 + 1. In a third terminal, create a Pub/Sub topic and attach a push subscription to the topic, using `http://localhost:8080` as its push endpoint. [Publish](https://cloud.google.com/pubsub/docs/quickstart-client-libraries#publish_messages) some messages to the topic. Observe your function getting triggered by the Pub/Sub messages. - ```sh - export PUBSUB_PROJECT_ID=my-project + export PUBSUB_PROJECT_ID=my-project export TOPIC_ID=my-topic export PUSH_SUBSCRIPTION_ID=my-subscription $(gcloud beta emulators pubsub env-init) @@ -204,12 +172,10 @@ response instead. python publisher.py $PUBSUB_PROJECT_ID create $TOPIC_ID python subscriber.py $PUBSUB_PROJECT_ID create-push $TOPIC_ID $PUSH_SUBSCRIPTION_ID http://localhost:8080 python publisher.py $PUBSUB_PROJECT_ID publish $TOPIC_ID - ``` - + You should see the following after the commands have run successfully: - ```none - Created topic: projects/my-project/topics/my-topic + Created topic: projects/my-project/topics/my-topic topic: "projects/my-project/topics/my-topic" push_config { @@ -232,12 +198,10 @@ response instead. 8 9 Published messages to projects/my-project/topics/my-topic. - ``` - + And in the terminal where the Functions Framework is running: - ```none - * Serving Flask app "hello" (lazy loading) + * Serving Flask app "hello" (lazy loading) * Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. @@ -264,95 +228,6 @@ response instead. 127.0.0.1 - - [11/Aug/2021 14:42:39] "POST / HTTP/1.1" 200 - Received 4 127.0.0.1 - - [11/Aug/2021 14:42:39] "POST / HTTP/1.1" 200 - - ``` - + For more details on extracting data from a Pub/Sub event, see -https://cloud.google.com/functions/docs/tutorials/pubsub#functions_helloworld_pubsub_tutorial-python - -### Quickstart: Build a Deployable Container - -1. Install [Docker](https://store.docker.com/search?type=edition&offering=community) and the [`pack` tool](https://buildpacks.io/docs/install-pack/). - -1. Build a container from your function using the Functions [buildpacks](https://github.com/GoogleCloudPlatform/buildpacks): - - pack build \ - --builder gcr.io/buildpacks/builder:v1 \ - --env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \ - --env GOOGLE_FUNCTION_TARGET=hello \ - my-first-function - -1. Start the built container: - - docker run --rm -p 8080:8080 my-first-function - # Output: Serving function... - -1. Send requests to this function using `curl` from another terminal window: - - curl localhost:8080 - # Output: Hello World! - -## Run your function on serverless platforms - -### Google Cloud Run functions - -This Functions Framework is based on the [Python Runtime on Google Cloud Functions](https://cloud.google.com/functions/docs/concepts/python-runtime). - -On Cloud Functions, using the Functions Framework is not necessary: you don't need to add it to your `requirements.txt` file. - -After you've written your function, you can simply deploy it from your local machine using the `gcloud` command-line tool. [Check out the Cloud Functions quickstart](https://cloud.google.com/functions/docs/quickstart). - -### Container environments based on Knative - -Cloud Run and Cloud Run on GKE both implement the [Knative Serving API](https://www.knative.dev/docs/). The Functions Framework is designed to be compatible with Knative environments. Just build and deploy your container to a Knative environment. - -## Configure the Functions Framework - -You can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored. - -| Command-line flag | Environment variable | Description | -| ------------------ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| `--host` | `HOST` | The host on which the Functions Framework listens for requests. Default: `0.0.0.0` | -| `--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080` | -| `--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function` | -| `--signature-type` | `FUNCTION_SIGNATURE_TYPE` | The signature used when writing your function. Controls unmarshalling rules and determines which arguments are used to invoke your function. Default: `http`; accepted values: `http`, `event` or `cloudevent` | -| `--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory) | -| `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` | - -## Enable Google Cloud Run function Events - -The Functions Framework can unmarshall incoming -Google Cloud Run functions [event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) payloads to `event` and `context` objects. -These will be passed as arguments to your function when it receives a request. -Note that your function must use the `event`-style function signature: - -```python -def hello(event, context): - print(event) - print(context) -``` - -To enable automatic unmarshalling, set the function signature type to `event` - using the `--signature-type` command-line flag or the `FUNCTION_SIGNATURE_TYPE` environment variable. By default, the HTTP -signature will be used and automatic event unmarshalling will be disabled. - -For more details on this signature type, see the Google Cloud Functions -documentation on -[background functions](https://cloud.google.com/functions/docs/writing/background#cloud_pubsub_example). - -See the [running example](examples/cloud_run_event). - -## Advanced Examples - -More advanced guides can be found in the [`examples/`](examples/) directory. -You can also find examples on using the CloudEvent Python SDK [here](https://github.com/cloudevents/sdk-python). - -## Contributing - -Contributions to this library are welcome and encouraged. See [CONTRIBUTING](CONTRIBUTING.md) for more information on how to get started. - -[ff_python_unit_img]: https://github.com/GoogleCloudPlatform/functions-framework-python/workflows/Python%20Unit%20CI/badge.svg -[ff_python_unit_link]: https://github.com/GoogleCloudPlatform/functions-framework-python/actions?query=workflow%3A"Python+Unit+CI" -[ff_python_lint_img]: https://github.com/GoogleCloudPlatform/functions-framework-python/workflows/Python%20Lint%20CI/badge.svg -[ff_python_lint_link]: https://github.com/GoogleCloudPlatform/functions-framework-python/actions?query=workflow%3A"Python+Lint+CI" -[ff_python_conformance_img]: https://github.com/GoogleCloudPlatform/functions-framework-python/workflows/Python%20Conformance%20CI/badge.svg -[ff_python_conformance_link]: https://github.com/GoogleCloudPlatform/functions-framework-python/actions?query=workflow%3A"Python+Conformance+CI" +https://cloud.google.com/pubsub/docs/push