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
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-bindings-cosmosdb-v2-input.md
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -246,7 +246,7 @@ The following example shows a [C# function](functions-dotnet-class-library.md) t
246
246
The example shows how to use a binding expression in the `SqlQuery` parameter. You can pass route data to the `SqlQuery` parameter as shown, but currently [you can't pass query string values](https://github.com/Azure/azure-functions-host/issues/2554#issuecomment-392084583).
247
247
248
248
> [!NOTE]
249
-
> If you need to query by just the ID, it is recommended to use a look up, like the [previous examples](#http-trigger-look-up-id-from-query-string-c), as it will consume less [request units](/azure/cosmos-db/request-units). Point read operations (GET) are [more efficient](/azure/cosmos-db/optimize-cost-reads-writes) than queries by ID.
249
+
> If you need to query by just the ID, it is recommended to use a lookup, like the [previous examples](#http-trigger-look-up-id-from-query-string-c), as it consumes less [request units](/azure/cosmos-db/request-units). Point read operations (GET) are [more efficient](/azure/cosmos-db/optimize-cost-reads-writes) than queries by ID.
250
250
>
251
251
252
252
```cs
@@ -635,7 +635,7 @@ public class DocByIdFromRoute {
635
635
The following example shows a Java function that retrieves a single document. The function is triggered by an HTTP request that uses a route parameter to specify the ID to look up. That ID is used to retrieve a document from the specified database and collection, converting the result set to a `ToDoItem[]`, since many documents may be returned, depending on the query criteria.
636
636
637
637
> [!NOTE]
638
-
> If you need to query by just the ID, it is recommended to use a look up, like the [previous examples](#http-trigger-look-up-id-from-query-string---pojo-parameter-java), as it will consume less [request units](/azure/cosmos-db/request-units). Point read operations (GET) are [more efficient](/azure/cosmos-db/optimize-cost-reads-writes) than queries by ID.
638
+
> If you need to query by just the ID, it is recommended to use a lookup, like the [previous examples](#http-trigger-look-up-id-from-query-string---pojo-parameter-java), as it consumes less [request units](/azure/cosmos-db/request-units). Point read operations (GET) are [more efficient](/azure/cosmos-db/optimize-cost-reads-writes) than queries by ID.
639
639
>
640
640
641
641
```java
@@ -1260,6 +1260,34 @@ This section contains the following examples that read a single document by spec
1260
1260
1261
1261
The examples depend on whether you use the [v1 or v2 Python programming model](functions-reference-python.md).
1262
1262
1263
+
### Using SDK-Type Bindings for Cosmos DB (Preview)
1264
+
This example uses SDK types to directly access the underlying [`CosmosClient`](https://github.com/Azure/azure-functions-python-extensions/blob/dev/azurefunctions-extensions-bindings-cosmosdb/samples/cosmosdb_samples_cosmosclient/function_app.py) object provided by the Cosmos DB input binding:
1265
+
1266
+
The function loops through all the databases and logs their IDs.
1267
+
```python
1268
+
import logging
1269
+
import azure.functions as func
1270
+
import azurefunctions.extensions.bindings.cosmosdb as cosmos
logging.info(f"Found database with ID: {db.get('id')}")
1283
+
1284
+
return"ok"
1285
+
```
1286
+
1287
+
For examples of using other SDK types, see the [`ContainerProxy`](https://github.com/Azure/azure-functions-python-extensions/blob/dev/azurefunctions-extensions-bindings-cosmosdb/samples/cosmosdb_samples_containerproxy/function_app.py) and [`DatabaseProxy`](https://github.com/Azure/azure-functions-python-extensions/blob/dev/azurefunctions-extensions-bindings-cosmosdb/samples/cosmosdb_samples_databaseproxy/function_app.py) samples. For a step-by-step tutorial on how to include SDK-type bindings in your function app, follow the [Python SDK Bindings for CosmosDB Sample](https://github.com/Azure-Samples/azure-functions-cosmosdb-sdk-bindings-python).
1288
+
1289
+
To learn more, including what other SDK type bindings are supported, see [SDK type bindings](functions-reference-python.md#sdk-type-bindings).
1290
+
1263
1291
### Queue trigger, look up ID from JSON
1264
1292
1265
1293
The following example shows an Azure Cosmos DB input binding. The function reads a single document and updates the document's text value.
@@ -1682,6 +1710,15 @@ Updates to documents are not made automatically upon function exit. To update do
1682
1710
::: zone-end
1683
1711
::: zone pivot="programming-language-python"
1684
1712
Data is made available to the function via a `DocumentList` parameter. Changes made to the document are not automatically persisted.
1713
+
Functions also support Python SDK type bindings for Azure Cosmos, which lets you work with data using these underlying SDK types:
> > Support for CosmosDB SDK types for Python is in Preview and is only supported for the Python v2 programming model. For more information, see [SDK types in Python](./functions-reference-python.md#sdk-type-bindings).
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-bindings-cosmosdb-v2.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -199,6 +199,27 @@ Earlier versions of extensions in the isolated worker process only support bindi
199
199
200
200
:::zone-end
201
201
202
+
::: zone pivot="programming-language-python"
203
+
204
+
## SDK Binding Types
205
+
206
+
SDK Type support for Azure Cosmos is in Preview. Follow the [Python SDK Bindings for CosmosDB Sample](https://github.com/Azure-Samples/azure-functions-cosmosdb-sdk-bindings-python) to get started with SDK Types for Cosmos in Python.
207
+
> [!IMPORTANT]
208
+
> Using SDK type bindings requires the [Python v2 programming model](functions-reference-python.md?pivots=python-mode-decorators#sdk-type-bindings).
This example uses [HTTP streams](functions-reference-python.md#http-streams-preview) 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-preview).
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-1).
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-preview)
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](functions-reference-python.md?tabs=get-started&pivots=python-mode-decorators#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:
0 commit comments