Skip to content

Commit 7a9ed4d

Browse files
committed
added python sdk sections
1 parent 1486ed2 commit 7a9ed4d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

articles/cosmos-db/nosql/query/computed-properties.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ During the preview, computed properties must be created using the .NET v3 or Jav
7979
| --- | --- | --- |
8080
| **.NET SDK v3** | >= [3.34.0-preview](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.34.0-preview) | Computed properties are currently available only in preview package versions. |
8181
| **Java SDK v4** | >= [4.46.0](https://mvnrepository.com/artifact/com.azure/azure-cosmos/4.46.0) | Computed properties are currently under preview version. |
82+
| **Python SDK** | >= [v4.5.2b5](https://pypi.org/project/azure-cosmos/4.5.2b5/) | Computed properties are currently under preview version. |
8283

8384
### Create computed properties by using the SDK
8485

@@ -113,6 +114,26 @@ containerProperties.setComputedProperties(computedProperties);
113114
client.getDatabase("myDatabase").createContainer(containerProperties);
114115
```
115116

117+
### [Python](#tab/python)
118+
119+
You can define multiple computed properties in a list and then add them to the container properties. Python SDK currently doesn't support computed properties on existing containers.
120+
121+
```python
122+
computed_properties = [{'name': "cp_lower", 'query': "SELECT VALUE LOWER(c.db_group) FROM c"},
123+
{'name': "cp_power", 'query': "SELECT VALUE POWER(c.val, 2) FROM c"},
124+
{'name': "cp_str_len", 'query': "SELECT VALUE LENGTH(c.stringProperty) FROM c"}]
125+
126+
container_with_computed_props = db.create_container_if_not_exists(
127+
"myContainer", PartitionKey(path="/pk"), computed_properties=computed_properties)
128+
```
129+
Computed properties can be used like any other property in queries. For example, you can use the computed property `cp_lower` in a query like this:
130+
131+
```python
132+
queried_items = list(
133+
container_with_computed_props.query_items(query='Select * from c Where c.cp_power = 25', partition_key="test"))
134+
```
135+
136+
116137
---
117138

118139
Here's an example of how to update computed properties on an existing container:
@@ -156,6 +177,9 @@ containerProperties.setComputedProperties(modifiedComputedProperites);
156177
container.replace(containerProperties);
157178
```
158179

180+
### [Python](#tab/python)
181+
Updating computed properties on an existing container is not supported in Python SDK. You can only define computed properties when creating a new container. This is a work in progress currently.
182+
159183
---
160184

161185
> [!TIP]

0 commit comments

Comments
 (0)