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
This example uses [HTTP streams](functions-reference-python.md#http-streams) to return chunked response data.
417
+
This example is an HTTP triggered function that uses [HTTP streams](functions-reference-python.md#http-streams) to return chunked response data. You might use these capabilities to support scenarios like sending event data through a pipeline for real time visualization or detecting anomalies in large sets of data and providing instant notifications.
To learn more, including how to enable HTTP streams in your project, see [HTTP streams](functions-reference-python.md#http-streams).
421
+
To learn more, including how to enable HTTP streams in your project, see [HTTP streams](functions-bindings-http-webhook-trigger.md?tabs=python-v2&pivots=programming-language-python#http-streams).
422
422
423
423
This example shows a trigger binding and a Python function that uses the binding. The function looks for a `name` parameter either in the query string or the body of the HTTP request.
424
424
@@ -1011,10 +1011,86 @@ You can now stream requests to and responses from your HTTP endpoint in Node.js
1011
1011
::: zone pivot="programming-language-python"
1012
1012
### HTTP streams
1013
1013
1014
-
HTTP streams support in Python lets you accept and return data from your HTTP endpoints using FastAPI request and response APIs enabled in your functions. These APIs enable the host to process data in HTTP messages as chunks instead of having to read an entire message into memory. For more information, see [HTTP streams in Python](./functions-reference-python.md#http-streams)
1014
+
HTTP streams support in Python lets you accept and return data from your HTTP endpoints using FastAPI request and response APIs enabled in your functions. These APIs enable the host to process data in HTTP messages as chunks instead of having to read an entire message into memory.
1015
+
1016
+
### Prerequisites
1017
+
1018
+
*[Azure Functions runtime](functions-versions.md?pivots=programming-language-python) version 4.34.1, or a later version.
1019
+
*[Python](https://www.python.org/downloads/) version 3.8, or a later [supported version](#python-version).
1020
+
1021
+
### Enable HTTP streams
1022
+
1023
+
HTTP streams are disabled by default. You need to enable this feature in your application settings and also update your code to use the FastAPI package. Note that when enabling HTTP streams, the function app will default to using HTTP streaming, and the original HTTP functionality will not work.
1024
+
1025
+
1. Add the `azurefunctions-extensions-http-fastapi` extension package to the `requirements.txt` file in the project, which should include at least these packages:
1. When you deploy to Azure, add the following [application setting](./functions-how-to-use-azure-function-app-settings.md#settings) in your function app:
1034
+
1035
+
`"PYTHON_ENABLE_INIT_INDEXING": "1"`
1036
+
1037
+
When running locally, you also need to add these same settings to the `local.settings.json` project file.
1038
+
1039
+
### HTTP streams examples
1040
+
1041
+
After you enable the HTTP streaming feature, you can create functions that stream data over HTTP.
1042
+
1043
+
This example is an HTTP triggered function that receives and processes streaming data from a client in real time. It demonstrates streaming upload capabilities that can be helpful for scenarios like processing continuous data streams and handling event data from IoT devices.
You must use an HTTP client library to make streaming calls to a function's FastAPI endpoints. The client tool or browser you're using might not natively support streaming or could only return the first chunk of data.
1050
+
1051
+
You can use a client script like this to send streaming data to an HTTP endpoint:
1052
+
1053
+
```python
1054
+
import httpx # Be sure to add 'httpx' to 'requirements.txt'
1055
+
import asyncio
1056
+
1057
+
asyncdefstream_generator(file_path):
1058
+
chunk_size =2*1024# Define your own chunk size
1059
+
withopen(file_path, 'rb') asfile:
1060
+
while chunk :=file.read(chunk_size):
1061
+
yield chunk
1062
+
print(f"Sent chunk: {len(chunk)} bytes")
1063
+
1064
+
asyncdefstream_to_server(url, file_path):
1065
+
timeout = httpx.Timeout(60.0, connect=60.0)
1066
+
asyncwith httpx.AsyncClient(timeout=timeout) as client:
@@ -535,91 +535,15 @@ For select triggers and bindings, you can work with data types implemented by th
535
535
HTTP streams lets you accept and return data from your HTTP endpoints using FastAPI request and response APIs enabled in your functions. These APIs lets the host process large data in HTTP messages as chunks instead of reading an entire message into memory.
536
536
537
537
This feature makes it possible to handle large data stream, OpenAI integrations, deliver dynamic content, and support other core HTTP scenarios requiring real-time interactions over HTTP. You can also use FastAPI response types with HTTP streams. Without HTTP streams, the size of your HTTP requests and responses are limited by memory restrictions that can be encountered when processing entire message payloads all in memory.
538
+
539
+
To learn more, including how to enable HTTP streams in your project, see [HTTP Streams](functions-bindings-http-webhook-trigger.md?tabs=python-v2&pivots=programming-language-python#http-streams).
538
540
::: zone pivot="python-mode-configuration"
539
541
> [!IMPORTANT]
540
542
> Support for HTTP streams requires the [Python v2 programming model](functions-reference-python.md?pivots=python-mode-decorators#http-streams).
541
543
::: zone-end
542
544
::: zone pivot="python-mode-decorators"
543
545
> [!IMPORTANT]
544
-
> HTTP streams support for Python is Generally Available and requires you to use the Python v2 programming model.
545
-
546
-
### Prerequisites
547
-
548
-
*[Azure Functions runtime](functions-versions.md?pivots=programming-language-python) version 4.34.1, or a later version.
549
-
*[Python](https://www.python.org/downloads/) version 3.8, or a later [supported version](#python-version).
550
-
551
-
### Enable HTTP streams
552
-
553
-
HTTP streams are disabled by default. You need to enable this feature in your application settings and also update your code to use the FastAPI package. Note that when enabling HTTP streams, the function app will default to using HTTP streaming, and the original HTTP functionality will not work.
554
-
555
-
1. Add the `azurefunctions-extensions-http-fastapi` extension package to the `requirements.txt` file in the project, which should include at least these packages:
1. When you deploy to Azure, add the following [application setting](./functions-how-to-use-azure-function-app-settings.md#settings) in your function app:
564
-
565
-
`"PYTHON_ENABLE_INIT_INDEXING": "1"`
566
-
567
-
When running locally, you also need to add these same settings to the `local.settings.json` project file.
568
-
569
-
### HTTP streams examples
570
-
571
-
After you enable the HTTP streaming feature, you can create functions that stream data over HTTP.
572
-
573
-
This example is an HTTP triggered function that streams HTTP response data. You might use these capabilities to support scenarios like sending event data through a pipeline for real time visualization or detecting anomalies in large sets of data and providing instant notifications.
This example is an HTTP triggered function that receives and processes streaming data from a client in real time. It demonstrates streaming upload capabilities that can be helpful for scenarios like processing continuous data streams and handling event data from IoT devices.
You must use an HTTP client library to make streaming calls to a function's FastAPI endpoints. The client tool or browser you're using might not natively support streaming or could only return the first chunk of data.
584
-
585
-
You can use a client script like this to send streaming data to an HTTP endpoint:
586
-
587
-
```python
588
-
import httpx # Be sure to add 'httpx' to 'requirements.txt'
589
-
import asyncio
590
-
591
-
asyncdefstream_generator(file_path):
592
-
chunk_size =2*1024# Define your own chunk size
593
-
withopen(file_path, 'rb') asfile:
594
-
while chunk :=file.read(chunk_size):
595
-
yield chunk
596
-
print(f"Sent chunk: {len(chunk)} bytes")
597
-
598
-
asyncdefstream_to_server(url, file_path):
599
-
timeout = httpx.Timeout(60.0, connect=60.0)
600
-
asyncwith httpx.AsyncClient(timeout=timeout) as client:
0 commit comments