Skip to content

Commit 877114d

Browse files
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
1 parent 80fdae7 commit 877114d

1 file changed

Lines changed: 17 additions & 142 deletions

File tree

README.md

Lines changed: 17 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![PyPI version](https://badge.fury.io/py/functions-framework.svg)](https://badge.fury.io/py/functions-framework)
44

5-
[![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)
5+
[![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)
66

77
An open source FaaS (Function as a service) framework for writing portable
88
Python functions -- brought to you by the Google Cloud Functions team.
@@ -16,17 +16,13 @@ different environments, including:
1616

1717
The framework allows you to go from:
1818

19-
```python
2019
def hello(request):
2120
return "Hello world!"
22-
```
2321

2422
To:
2523

26-
```sh
2724
curl http://my-url
2825
# Output: Hello world!
29-
```
3026

3127
All without needing to worry about writing an HTTP server or complicated request handling logic.
3228

@@ -41,44 +37,36 @@ All without needing to worry about writing an HTTP server or complicated request
4137

4238
Install the Functions Framework via `pip`:
4339

44-
```sh
4540
pip install functions-framework
46-
```
4741

4842
Or, for deployment, add the Functions Framework to your `requirements.txt` file:
4943

50-
```
5144
functions-framework==3.*
52-
```
5345

5446
## Quickstarts
5547

5648
### Quickstart: HTTP Function (Hello World)
5749

5850
Create an `main.py` file with the following contents:
5951

60-
```python
6152
import flask
6253
import functions_framework
6354

6455
@functions_framework.http
6556
def hello(request: flask.Request) -> flask.typing.ResponseReturnValue:
6657
return "Hello world!"
67-
```
6858

6959
> 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.
7060
7161
Run the following command:
7262

73-
```sh
7463
functions-framework --target hello --debug
7564
* Serving Flask app "hello" (lazy loading)
7665
* Environment: production
7766
WARNING: This is a development server. Do not use it in a production deployment.
7867
Use a production WSGI server instead.
7968
* Debug mode: on
8069
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
81-
```
8270

8371
(You can also use `functions-framework-python` if you have multiple
8472
language frameworks installed).
@@ -87,35 +75,28 @@ Open http://localhost:8080/ in your browser and see *Hello world!*.
8775

8876
Or send requests to this function using `curl` from another terminal window:
8977

90-
```sh
9178
curl localhost:8080
9279
# Output: Hello world!
93-
```
9480

9581
### Quickstart: CloudEvent Function
9682

9783
Create an `main.py` file with the following contents:
9884

99-
```python
10085
import functions_framework
10186
from cloudevents.http.event import CloudEvent
10287

10388
@functions_framework.cloud_event
10489
def hello_cloud_event(cloud_event: CloudEvent) -> None:
10590
print(f"Received event with ID: {cloud_event['id']} and data {cloud_event.data}")
106-
```
10791

10892
> Your function is passed a single [CloudEvent](https://github.com/cloudevents/sdk-python/blob/main/cloudevents/sdk/event/v1.py) parameter.
10993
11094
Run the following command to run `hello_cloud_event` target locally:
11195

112-
```sh
11396
functions-framework --target=hello_cloud_event
114-
```
11597

11698
In a different terminal, `curl` the Functions Framework server:
11799

118-
```sh
119100
curl -X POST localhost:8080 \
120101
-H "Content-Type: application/cloudevents+json" \
121102
-d '{
@@ -127,12 +108,10 @@ curl -X POST localhost:8080 \
127108
"time" : "2018-04-05T17:31:00Z",
128109
"data" : "hello world"
129110
}'
130-
```
131111

132112
Output from the terminal running `functions-framework`:
133-
```
134113
Received event with ID: A234-1234-1234 and data hello world
135-
```
114+
136115

137116
More info on sending [CloudEvents](http://cloudevents.io) payloads, see [`examples/cloud_run_cloud_events`](examples/cloud_run_cloud_events/) instruction.
138117

@@ -143,7 +122,6 @@ The framework includes an error handler that is similar to the
143122
[`flask.Flask.errorhandler`](https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask.errorhandler)
144123
function, which allows you to handle specific error types with a decorator:
145124

146-
```python
147125
import functions_framework
148126

149127

@@ -155,44 +133,34 @@ def handle_zero_division(e):
155133
def function(request):
156134
1 / 0
157135
return "Success", 200
158-
```
159136

160137
This function will catch the `ZeroDivisionError` and return a different
161138
response instead.
162139

163140
### Quickstart: Pub/Sub emulator
164141
1. Create a `main.py` file with the following contents:
165142

166-
```python
167-
def hello(event, context):
143+
def hello(event, context):
168144
print("Received", context.event_id)
169-
```
170-
145+
171146
1. Start the Functions Framework on port 8080:
172147

173-
```sh
174-
functions-framework --target=hello --signature-type=event --debug --port=8080
175-
```
176-
148+
functions-framework --target=hello --signature-type=event --debug --port=8080
149+
177150
1. In a second terminal, start the Pub/Sub emulator on port 8085.
178151

179-
```sh
180-
export PUBSUB_PROJECT_ID=my-project
152+
export PUBSUB_PROJECT_ID=my-project
181153
gcloud beta emulators pubsub start \
182154
--project=$PUBSUB_PROJECT_ID \
183155
--host-port=localhost:8085
184-
```
185-
156+
186157
You should see the following after the Pub/Sub emulator has started successfully:
187158

188-
```none
189-
[pubsub] INFO: Server started, listening on 8085
190-
```
191-
159+
[pubsub] INFO: Server started, listening on 8085
160+
192161
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.
193162

194-
```sh
195-
export PUBSUB_PROJECT_ID=my-project
163+
export PUBSUB_PROJECT_ID=my-project
196164
export TOPIC_ID=my-topic
197165
export PUSH_SUBSCRIPTION_ID=my-subscription
198166
$(gcloud beta emulators pubsub env-init)
@@ -204,12 +172,10 @@ response instead.
204172
python publisher.py $PUBSUB_PROJECT_ID create $TOPIC_ID
205173
python subscriber.py $PUBSUB_PROJECT_ID create-push $TOPIC_ID $PUSH_SUBSCRIPTION_ID http://localhost:8080
206174
python publisher.py $PUBSUB_PROJECT_ID publish $TOPIC_ID
207-
```
208-
175+
209176
You should see the following after the commands have run successfully:
210177

211-
```none
212-
Created topic: projects/my-project/topics/my-topic
178+
Created topic: projects/my-project/topics/my-topic
213179

214180
topic: "projects/my-project/topics/my-topic"
215181
push_config {
@@ -232,12 +198,10 @@ response instead.
232198
8
233199
9
234200
Published messages to projects/my-project/topics/my-topic.
235-
```
236-
201+
237202
And in the terminal where the Functions Framework is running:
238203

239-
```none
240-
* Serving Flask app "hello" (lazy loading)
204+
* Serving Flask app "hello" (lazy loading)
241205
* Environment: production
242206
WARNING: This is a development server. Do not use it in a production deployment.
243207
Use a production WSGI server instead.
@@ -264,95 +228,6 @@ response instead.
264228
127.0.0.1 - - [11/Aug/2021 14:42:39] "POST / HTTP/1.1" 200 -
265229
Received 4
266230
127.0.0.1 - - [11/Aug/2021 14:42:39] "POST / HTTP/1.1" 200 -
267-
```
268-
231+
269232
For more details on extracting data from a Pub/Sub event, see
270-
https://cloud.google.com/functions/docs/tutorials/pubsub#functions_helloworld_pubsub_tutorial-python
271-
272-
### Quickstart: Build a Deployable Container
273-
274-
1. Install [Docker](https://store.docker.com/search?type=edition&offering=community) and the [`pack` tool](https://buildpacks.io/docs/install-pack/).
275-
276-
1. Build a container from your function using the Functions [buildpacks](https://github.com/GoogleCloudPlatform/buildpacks):
277-
278-
pack build \
279-
--builder gcr.io/buildpacks/builder:v1 \
280-
--env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \
281-
--env GOOGLE_FUNCTION_TARGET=hello \
282-
my-first-function
283-
284-
1. Start the built container:
285-
286-
docker run --rm -p 8080:8080 my-first-function
287-
# Output: Serving function...
288-
289-
1. Send requests to this function using `curl` from another terminal window:
290-
291-
curl localhost:8080
292-
# Output: Hello World!
293-
294-
## Run your function on serverless platforms
295-
296-
### Google Cloud Run functions
297-
298-
This Functions Framework is based on the [Python Runtime on Google Cloud Functions](https://cloud.google.com/functions/docs/concepts/python-runtime).
299-
300-
On Cloud Functions, using the Functions Framework is not necessary: you don't need to add it to your `requirements.txt` file.
301-
302-
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).
303-
304-
### Container environments based on Knative
305-
306-
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.
307-
308-
## Configure the Functions Framework
309-
310-
You can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.
311-
312-
| Command-line flag | Environment variable | Description |
313-
| ------------------ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
314-
| `--host` | `HOST` | The host on which the Functions Framework listens for requests. Default: `0.0.0.0` |
315-
| `--port` | `PORT` | The port on which the Functions Framework listens for requests. Default: `8080` |
316-
| `--target` | `FUNCTION_TARGET` | The name of the exported function to be invoked in response to requests. Default: `function` |
317-
| `--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` |
318-
| `--source` | `FUNCTION_SOURCE` | The path to the file containing your function. Default: `main.py` (in the current working directory) |
319-
| `--debug` | `DEBUG` | A flag that allows to run functions-framework to run in debug mode, including live reloading. Default: `False` |
320-
321-
## Enable Google Cloud Run function Events
322-
323-
The Functions Framework can unmarshall incoming
324-
Google Cloud Run functions [event](https://cloud.google.com/functions/docs/concepts/events-triggers#events) payloads to `event` and `context` objects.
325-
These will be passed as arguments to your function when it receives a request.
326-
Note that your function must use the `event`-style function signature:
327-
328-
```python
329-
def hello(event, context):
330-
print(event)
331-
print(context)
332-
```
333-
334-
To enable automatic unmarshalling, set the function signature type to `event`
335-
using the `--signature-type` command-line flag or the `FUNCTION_SIGNATURE_TYPE` environment variable. By default, the HTTP
336-
signature will be used and automatic event unmarshalling will be disabled.
337-
338-
For more details on this signature type, see the Google Cloud Functions
339-
documentation on
340-
[background functions](https://cloud.google.com/functions/docs/writing/background#cloud_pubsub_example).
341-
342-
See the [running example](examples/cloud_run_event).
343-
344-
## Advanced Examples
345-
346-
More advanced guides can be found in the [`examples/`](examples/) directory.
347-
You can also find examples on using the CloudEvent Python SDK [here](https://github.com/cloudevents/sdk-python).
348-
349-
## Contributing
350-
351-
Contributions to this library are welcome and encouraged. See [CONTRIBUTING](CONTRIBUTING.md) for more information on how to get started.
352-
353-
[ff_python_unit_img]: https://github.com/GoogleCloudPlatform/functions-framework-python/workflows/Python%20Unit%20CI/badge.svg
354-
[ff_python_unit_link]: https://github.com/GoogleCloudPlatform/functions-framework-python/actions?query=workflow%3A"Python+Unit+CI"
355-
[ff_python_lint_img]: https://github.com/GoogleCloudPlatform/functions-framework-python/workflows/Python%20Lint%20CI/badge.svg
356-
[ff_python_lint_link]: https://github.com/GoogleCloudPlatform/functions-framework-python/actions?query=workflow%3A"Python+Lint+CI"
357-
[ff_python_conformance_img]: https://github.com/GoogleCloudPlatform/functions-framework-python/workflows/Python%20Conformance%20CI/badge.svg
358-
[ff_python_conformance_link]: https://github.com/GoogleCloudPlatform/functions-framework-python/actions?query=workflow%3A"Python+Conformance+CI"
233+
https://cloud.google.com/pubsub/docs/push

0 commit comments

Comments
 (0)