You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
> 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.
70
60
71
61
Run the following command:
72
62
73
-
```sh
74
63
functions-framework --target hello --debug
75
64
* Serving Flask app "hello" (lazy loading)
76
65
* Environment: production
77
66
WARNING: This is a development server. Do not use it in a production deployment.
78
67
Use a production WSGI server instead.
79
68
* Debug mode: on
80
69
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
81
-
```
82
70
83
71
(You can also use `functions-framework-python` if you have multiple
84
72
language frameworks installed).
@@ -87,35 +75,28 @@ Open http://localhost:8080/ in your browser and see *Hello world!*.
87
75
88
76
Or send requests to this function using `curl` from another terminal window:
89
77
90
-
```sh
91
78
curl localhost:8080
92
79
# Output: Hello world!
93
-
```
94
80
95
81
### Quickstart: CloudEvent Function
96
82
97
83
Create an `main.py` file with the following contents:
print(f"Received event with ID: {cloud_event['id']} and data {cloud_event.data}")
106
-
```
107
91
108
92
> Your function is passed a single [CloudEvent](https://github.com/cloudevents/sdk-python/blob/main/cloudevents/sdk/event/v1.py) parameter.
109
93
110
94
Run the following command to run `hello_cloud_event` target locally:
111
95
112
-
```sh
113
96
functions-framework --target=hello_cloud_event
114
-
```
115
97
116
98
In a different terminal, `curl` the Functions Framework server:
117
99
118
-
```sh
119
100
curl -X POST localhost:8080 \
120
101
-H "Content-Type: application/cloudevents+json" \
121
102
-d '{
@@ -127,12 +108,10 @@ curl -X POST localhost:8080 \
127
108
"time" : "2018-04-05T17:31:00Z",
128
109
"data" : "hello world"
129
110
}'
130
-
```
131
111
132
112
Output from the terminal running `functions-framework`:
133
-
```
134
113
Received event with ID: A234-1234-1234 and data hello world
135
-
```
114
+
136
115
137
116
More info on sending [CloudEvents](http://cloudevents.io) payloads, see [`examples/cloud_run_cloud_events`](examples/cloud_run_cloud_events/) instruction.
138
117
@@ -143,7 +122,6 @@ The framework includes an error handler that is similar to the
1. In a second terminal, start the Pub/Sub emulator on port 8085.
178
151
179
-
```sh
180
-
export PUBSUB_PROJECT_ID=my-project
152
+
export PUBSUB_PROJECT_ID=my-project
181
153
gcloud beta emulators pubsub start \
182
154
--project=$PUBSUB_PROJECT_ID \
183
155
--host-port=localhost:8085
184
-
```
185
-
156
+
186
157
You should see the following after the Pub/Sub emulator has started successfully:
187
158
188
-
```none
189
-
[pubsub] INFO: Server started, listening on 8085
190
-
```
191
-
159
+
[pubsub] INFO: Server started, listening on 8085
160
+
192
161
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.
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 |
|`--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
-
defhello(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
0 commit comments