Skip to content

Commit 4d0de31

Browse files
committed
Add samples pulled from repo.
1 parent ed35263 commit 4d0de31

File tree

3 files changed

+10
-22
lines changed

3 files changed

+10
-22
lines changed

articles/cosmos-db/nosql/how-to-python-create-container.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ try:
5656
except CosmosResourceExistsError:
5757
print("Container already exists.")
5858
```
59-
<!--
59+
6060
:::code language="python" source="~/cosmos-db-nosql-python-samples/005-create-container/app.py" id="create_container":::
61-
-->
6261

6362
### Create a container if it doesn't already exist
6463

@@ -78,9 +77,8 @@ try:
7877
except CosmosHttpResponseError:
7978
print("Request to the Azure Cosmos database service failed.")
8079
```
81-
<!--
80+
8281
:::code language="python" source="~/cosmos-db-nosql-python-samples/005-create-container/app_exists.py" id="create_container":::
83-
-->
8482

8583
### Create a container asynchronously
8684

@@ -102,9 +100,8 @@ container = database.create_container_if_not_exists(
102100
offer_throughput=400
103101
)
104102
```
105-
<!--
103+
106104
:::code language="python" source="~/cosmos-db-nosql-python-samples/005-create-container/app_exists.py" id="parse_response":::
107-
-->
108105

109106
## Next steps
110107

articles/cosmos-db/nosql/how-to-python-create-database.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ try:
5151
except CosmosResourceExistsError:
5252
print("Database already exists.")
5353
```
54-
<!--
54+
5555
:::code language="python" source="~/cosmos-db-nosql-python-samples/004-create-db/app.py" id="create_database":::
56-
-->
5756

5857
### Create a database if it doesn't already exist
5958

@@ -67,9 +66,8 @@ try:
6766
except CosmosHttpResponseError:
6867
print("Request to the Azure Cosmos database service failed.")
6968
```
70-
<!--
69+
7170
:::code language="python" source="~/cosmos-db-nosql-python-samples/004-create-db/app_exists.py" id="create_database":::
72-
-->
7371

7472
### Create a database asynchronously
7573

@@ -88,9 +86,8 @@ database = client.create_database_if_not_exists(id=DATABASE_ID)
8886
for container in database.list_containers():
8987
print(f'Container name: {container["id"]}')
9088
```
91-
<!--
89+
9290
:::code language="python" source="~/cosmos-db-nosql-python-samples/004-create-db/app_exists.py" id="parse_response":::
93-
-->
9491

9592
## Next steps
9693

articles/cosmos-db/nosql/how-to-python-get-started.md

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ from azure.core.exceptions import AzureError
7272
from azure.cosmos import CosmosClient, PartitionKey
7373
```
7474

75-
<!--
7675
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app.py" id="imports":::
77-
-->
7876

7977
The preceding code imports modules that you'll use in the rest of the article.
8078

@@ -233,9 +231,8 @@ KEY = os.environ["COSMOS_KEY"]
233231

234232
client = CosmosClient(url=ENDPOINT, credential=KEY)
235233
```
236-
<!--
234+
237235
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app.py" id="client":::
238-
-->
239236

240237
### Connect with a connection string
241238

@@ -341,9 +338,8 @@ CONTAINER_ID = "products"
341338

342339
client = CosmosClient.from_connection_string(conn_str=CONN_STR)
343340
```
344-
<!--
341+
345342
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app_connection_string.py" id="connection_string":::
346-
-->
347343

348344
### Connect using the Microsoft Identity Platform
349345

@@ -386,9 +382,8 @@ credential = DefaultAzureCredential()
386382

387383
client = CosmosClient(ENDPOINT, credential)
388384
```
389-
<!--
385+
390386
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app_aad_default.py" id="credential":::
391-
-->
392387

393388
> [!IMPORTANT]
394389
> For details on how to add the correct role to enable `DefaultAzureCredential` to work, see [Configure role-based access control with Azure Active Directory for your Azure Cosmos DB account](/azure/cosmos-db/how-to-setup-rbac). In particular, see the section on creating roles and assigning them to a principal ID.
@@ -423,9 +418,8 @@ credential = ClientSecretCredential(
423418

424419
client = CosmosClient(ENDPOINT, credential)
425420
```
426-
<!--
421+
427422
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app_add_principal.py" id="credential":::
428-
-->
429423

430424
## Build your application
431425

0 commit comments

Comments
 (0)