Skip to content

Commit dca32c2

Browse files
Merge pull request #271017 from AbhinavTrips/main
Computed properties addition to Python SDK
2 parents 9fb1f66 + 2831db4 commit dca32c2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
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]

articles/cosmos-db/priority-based-execution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ To get started using priority-based execution, navigate to the **Features** page
4343
- Java v4: [v4.45.0](https://mvnrepository.com/artifact/com.azure/azure-cosmos/4.45.0) or later
4444
- Spark 3.2: [v4.19.0](https://central.sonatype.com/artifact/com.azure.cosmos.spark/azure-cosmos-spark_3-2_2-12/4.19.0) or later
4545
- JavaScript v4: [v4.0.0](https://www.npmjs.com/package/@azure/cosmos) or later
46-
- Python 4.6.0: [v4.6.0](https://pypi.org/project/azure-cosmos/4.6.0/) or later
46+
- Python: [v4.5.2b2](https://pypi.org/project/azure-cosmos/4.5.2b2/) or later. Available only in preview version.
4747

4848
## Code samples
4949

0 commit comments

Comments
 (0)