Skip to content

Commit 376347c

Browse files
Merge pull request #238907 from AbhinavTrips/abtripathi-python-patch
Updated python snippets
2 parents 0536b68 + 40ebaf3 commit 376347c

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

articles/cosmos-db/partial-document-update-getting-started.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
title: Get started with partial document update
33
titleSuffix: Azure Cosmos DB for NoSQL
44
description: Learn how to use the partial document update feature with the .NET, Java, and Node SDKs for Azure Cosmos DB for NoSQL.
5-
ms.author: sidandrews
6-
author: seesharprun
5+
author: AbhinavTrips
6+
ms.author: abtripathi
77
ms.service: cosmos-db
88
ms.subservice: nosql
99
ms.topic: how-to
10-
ms.date: 04/03/2023
11-
ms.custom: ignite-fall-2021, ignite-2022
10+
ms.date: 05/23/2023
1211
---
1312

1413
# Get started with Azure Cosmos DB Partial Document Update
@@ -281,6 +280,57 @@ Support for Partial Document Update (Patch API) in the [Azure Cosmos DB JavaScri
281280

282281
---
283282

283+
## [Python (Preview)](#tab/python)
284+
285+
Support for Partial Document Update (Patch API) in the [Azure Cosmos DB Python SDK](nosql/sdk-python.md) is available in Preview starting with version *4.4.0b2*. You can download it from the [pip Registry](https://pypi.org/project/azure-cosmos/4.4.0b2/).
286+
287+
> [!NOTE]
288+
> Find a complete Partial Document Update sample in the [python samples repository](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cosmos/azure-cosmos/samples/document_management.py#L105C8-L122) on GitHub.
289+
290+
- Run a single patch operation:
291+
292+
```python
293+
operations =
294+
[
295+
{ op: 'replace', path: '/price', value: 355.45 }
296+
]
297+
298+
response = container.patch_item(item='e379aea5-63f5-4623-9a9b-4cd9b33b91d5', partition_key='road-bikes', patch_operations=operations)
299+
300+
```
301+
302+
- Combine multiple patch operations:
303+
304+
```python
305+
operations =
306+
[
307+
{ op: 'add', path: '/color', value: 'silver' },
308+
{ op: 'remove', path: '/used' }
309+
]
310+
311+
response = container.patch_item(item='e379aea5-63f5-4623-9a9b-4cd9b33b91d5', partition_key='road-bikes', patch_operations=operations)
312+
313+
```
314+
315+
- Use conditional patch syntax based on filter predicate:
316+
317+
```python
318+
filter = "from products p WHERE p.used = false"
319+
320+
operations =
321+
[
322+
{ op: 'replace', path: '/price', value: 100.00 }
323+
]
324+
325+
try:
326+
container.patch_item(item='e379aea5-63f5-4623-9a9b-4cd9b33b91d5', partition_key='road-bikes', patch_operations=operations, filter_predicate=filter)
327+
except exceptions.CosmosHttpResponseError as e:
328+
print('\nError occured. {0}'.format(e.message))
329+
330+
```
331+
332+
---
333+
284334
## Support for server-side programming
285335

286336
Partial Document Update operations can also be [executed on the server-side](stored-procedures-triggers-udfs.md) using stored procedures, triggers, and user-defined functions.

0 commit comments

Comments
 (0)