Skip to content

Commit c2f67fc

Browse files
committed
Swap in and use links to real code in repo.
1 parent 4d0de31 commit c2f67fc

File tree

3 files changed

+1
-83
lines changed

3 files changed

+1
-83
lines changed

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -43,41 +43,12 @@ To create a container, call one of the following methods:
4343

4444
The following example creates a container with the [``DatabaseProxy.create_container``](/python/api/azure-cosmos/azure.cosmos.databaseproxy#azure-cosmos-databaseproxy-create-container) method. This method throws an exception if the container with the same name already exists.
4545

46-
```python
47-
try:
48-
partition_key_path = PartitionKey(path="/categoryId")
49-
container = database.create_container(
50-
id=CONTAINER_ID,
51-
partition_key=partition_key_path,
52-
offer_throughput=400
53-
)
54-
print(f'Container created: {container.id}')
55-
56-
except CosmosResourceExistsError:
57-
print("Container already exists.")
58-
```
59-
6046
:::code language="python" source="~/cosmos-db-nosql-python-samples/005-create-container/app.py" id="create_container":::
6147

6248
### Create a container if it doesn't already exist
6349

64-
6550
The following example creates a container with the [``DatabaseProxy.create_container_if_not_exists``](/python/api/azure-cosmos/azure.cosmos.databaseproxy#azure-cosmos-databaseproxy-create-container-if-not-exist) method. Compared to the previous create method, this method doesn't throw an exception if the database already exists. This method is useful for avoiding errors if you run the same code multiple times.
6651

67-
```python
68-
try:
69-
partition_key_path = PartitionKey(path="/categoryId")
70-
container = database.create_container_if_not_exists(
71-
id=CONTAINER_ID,
72-
partition_key=partition_key_path,
73-
offer_throughput=400
74-
)
75-
print(f'Container created or returned: {container.id}')
76-
77-
except CosmosHttpResponseError:
78-
print("Request to the Azure Cosmos database service failed.")
79-
```
80-
8152
:::code language="python" source="~/cosmos-db-nosql-python-samples/005-create-container/app_exists.py" id="create_container":::
8253

8354
### Create a container asynchronously

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,12 @@ To create a database, call one of the following methods:
4343

4444
The following example creates a database with the [`CosmosClient.create_database`](/python/api/azure-cosmos/azure.cosmos.cosmosclient#azure-cosmos-cosmosclient-create-database) method. This method throws an exception if a database with the same name exists.
4545

46-
```python
47-
try:
48-
database = client.create_database(id=DATABASE_ID)
49-
print(f'Database created: {database.id}')
50-
51-
except CosmosResourceExistsError:
52-
print("Database already exists.")
53-
```
54-
5546
:::code language="python" source="~/cosmos-db-nosql-python-samples/004-create-db/app.py" id="create_database":::
5647

5748
### Create a database if it doesn't already exist
5849

5950
The following example creates a database with the [`CosmosClient.create_database_if_not_exists`](/python/api/azure-cosmos/azure.cosmos.cosmosclient#azure-cosmos-cosmosclient-create-database-if-not-exists) method. If the database exists, this method returns the database settings. Compared to the previous create method, this method doesn't throw an exception if the database already exists. This method is useful for avoiding errors if you run the same code multiple times.
6051

61-
```python
62-
try:
63-
database = client.create_database_if_not_exists(id=DATABASE_ID)
64-
print(f'Database created and/or returned: {database.id}')
65-
66-
except CosmosHttpResponseError:
67-
print("Request to the Azure Cosmos database service failed.")
68-
```
69-
7052
:::code language="python" source="~/cosmos-db-nosql-python-samples/004-create-db/app_exists.py" id="create_database":::
7153

7254
### Create a database asynchronously

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ pip install azure-cosmos
6262

6363
In your environment, create a new *app.py* file and add the following code to it:
6464

65-
```python
66-
import json
67-
import os
68-
import sys
69-
import uuid
70-
71-
from azure.core.exceptions import AzureError
72-
from azure.cosmos import CosmosClient, PartitionKey
73-
```
74-
7565
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app.py" id="imports":::
7666

7767
The preceding code imports modules that you'll use in the rest of the article.
@@ -225,13 +215,6 @@ export COSMOS_KEY="<cosmos-account-PRIMARY-KEY>"
225215

226216
Create a new instance of the **CosmosClient** class with the ``COSMOS_ENDPOINT`` and ``COSMOS_KEY`` environment variables as parameters.
227217

228-
```python
229-
ENDPOINT = os.environ["COSMOS_ENDPOINT"]
230-
KEY = os.environ["COSMOS_KEY"]
231-
232-
client = CosmosClient(url=ENDPOINT, credential=KEY)
233-
```
234-
235218
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app.py" id="client":::
236219

237220
### Connect with a connection string
@@ -331,14 +314,6 @@ export COSMOS_CONNECTION_STRING="<cosmos-account-PRIMARY-CONNECTION-STRING>"
331314

332315
Create a new instance of the **CosmosClient** class with the ``COSMOS_CONNECTION_STRING`` environment variable as the only parameter.
333316

334-
```Python
335-
CONN_STR = os.environ["COSMOS_CONNECTION_STRING"]
336-
DATABASE_ID = "cosmicworks"
337-
CONTAINER_ID = "products"
338-
339-
client = CosmosClient.from_connection_string(conn_str=CONN_STR)
340-
```
341-
342317
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app_connection_string.py" id="connection_string":::
343318

344319
### Connect using the Microsoft Identity Platform
@@ -373,16 +348,6 @@ In your *app.py*:
373348

374349
* Create a new instance of the **CosmosClient** class with the **ENDPOINT** and **credential** as parameters.
375350

376-
```python
377-
from azure.identity import DefaultAzureCredential
378-
379-
ENDPOINT = os.environ["COSMOS_ENDPOINT"]
380-
381-
credential = DefaultAzureCredential()
382-
383-
client = CosmosClient(ENDPOINT, credential)
384-
```
385-
386351
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app_aad_default.py" id="credential":::
387352

388353
> [!IMPORTANT]
@@ -419,7 +384,7 @@ credential = ClientSecretCredential(
419384
client = CosmosClient(ENDPOINT, credential)
420385
```
421386

422-
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app_add_principal.py" id="credential":::
387+
:::code language="python" source="~/cosmos-db-nosql-python-samples/003-how-to/app_aad_principal.py" id="credential":::
423388

424389
## Build your application
425390

0 commit comments

Comments
 (0)