Skip to content

Commit 3bdbd2f

Browse files
authored
Minor formatting edits
1 parent 4188536 commit 3bdbd2f

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

articles/cosmos-db/nosql/quickstart-python.md

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,18 @@ From the project directory, open the *app.py* file. In your editor, import the `
103103

104104
Create constants for the `COSMOS_ENDPOINT` and `COSMOS_KEY` environment variables using `os.environ`.
105105

106-
#### [Sync](#tab/sync)
106+
#### [Sync / Async](#tab/sync+async)
107107

108108
:::code language="python" source="~/cosmos-db-nosql-python-samples/001-quickstart/app.py" id="environment_variables":::
109109

110-
#### [Async](#tab/async)
111-
112-
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" id="environment_variables":::
113-
114110
---
115111

116112
Create constants for the database and container names.
117113

118-
#### [Sync](#tab/sync)
114+
#### [Sync / Async](#tab/sync+async)
119115

120116
:::code language="python" source="~/cosmos-db-nosql-python-samples/001-quickstart/app.py" id="constants":::
121117

122-
#### [Async](#tab/async)
123-
124-
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" id="constants":::
125-
126118
---
127119

128120
Create a new client instance using the [`CosmosClient`](/python/api/azure-cosmos/azure.cosmos.cosmos_client.cosmosclient) class constructor and the two variables you created as parameters.
@@ -136,7 +128,9 @@ Create a new client instance using the [`CosmosClient`](/python/api/azure-cosmos
136128
> [!IMPORTANT]
137129
> Please the client instance in a coroutine function named `manage_cosmos`. Within the coroutine function, define the new client with the `async with` keywords. Outside of the coroutine function, use the `asyncio.run` function to execute the coroutine asynchronously.
138130
139-
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" range="24-26,70":::
131+
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" range="24-26":::
132+
133+
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" range="70":::
140134

141135
---
142136

@@ -178,14 +172,10 @@ The [`Databaseproxy.create_container_if_not_exists`](/python/api/azure-cosmos/az
178172

179173
Create a new item in the container by first creating a new variable (`new_item`) with a sample item defined. In this example, the unique identifier of this item is `70b63682-b93a-4c77-aad2-65501347265f`. The partition key value is derived from the `/categoryId` path, so it would be `61dba35b-4f02-45c5-b648-c6badc0cbd79`.
180174

181-
#### [Sync](#tab/sync)
175+
#### [Sync / Async](#tab/sync+async)
182176

183177
:::code language="python" source="~/cosmos-db-nosql-python-samples/001-quickstart/app.py" id="new_item":::
184178

185-
#### [Async](#tab/async)
186-
187-
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" range="38-45":::
188-
189179
---
190180

191181
> [!TIP]
@@ -223,28 +213,20 @@ In this example, the dictionary result is saved to a variable named `existing_it
223213

224214
After you insert an item, you can run a query to get all items that match a specific filter. This example runs the SQL query: ``SELECT * FROM products p WHERE p.categoryId = "61dba35b-4f02-45c5-b648-c6badc0cbd79"``. This example uses query parameterization to construct the query. The query uses a string of the SQL query, and a dictionary of query parameters.
225215

226-
#### [Sync](#tab/sync)
216+
#### [Sync / Async](#tab/sync+async)
227217

228218
:::code language="python" source="~/cosmos-db-nosql-python-samples/001-quickstart/app.py" id="build_query":::
229219

230-
#### [Async](#tab/async)
231-
232-
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" range="55-57":::
233-
234220
---
235221

236222
This example dictionary included the `@categoryId` query parameter and the corresponding value `61dba35b-4f02-45c5-b648-c6badc0cbd79`.
237223

238224
Once the query is defined, call [`ContainerProxy.query_items`](/python/api/azure-cosmos/azure.cosmos.containerproxy#azure-cosmos-containerproxy-query-items) to run the query and return the results as a paged set of items (`ItemPage[Dict[str, Any]]`).
239225

240-
#### [Sync](#tab/sync)
226+
#### [Sync / Async](#tab/sync+async)
241227

242228
:::code language="python" source="~/cosmos-db-nosql-python-samples/001-quickstart/app.py" id="query_items":::
243229

244-
#### [Async](#tab/async)
245-
246-
:::code language="python" source="~/cosmos-db-nosql-python-samples/002-quickstart-async/app.py" range="59-61":::
247-
248230
---
249231

250232
Finally, use a for loop to iterate over the results in each page and perform various actions.

0 commit comments

Comments
 (0)