This sample shows how to deploy streaming functions to Cloud Run with the Functions Framework. The main.py file contains examples for both synchronous and asynchronous streaming.
Install the dependencies for this example:
pip install -r requirements.txtTo run the synchronous streaming function locally:
functions-framework --target=hello_streamThen, send a request to it from another terminal:
curl localhost:8080To run the asynchronous streaming function locally:
functions-framework --target=hello_stream_asyncThen, send a request to it from another terminal:
curl localhost:8080You can deploy these functions to Cloud Run using the gcloud CLI.
gcloud run deploy streaming-function \
--source . \
--function hello_stream \
--base-image python312 \
--region <YOUR_REGION>gcloud run deploy streaming-async-function \
--source . \
--function hello_stream_async \
--base-image python312 \
--region <YOUR_REGION>