| page_type | languages | products | urlFragment | |||
|---|---|---|---|---|---|---|
sample |
|
|
cosmos-db-samples |
The following are code samples that show common scenario operations with the Azure Cosmos DB SQL API client library. Note that the samples use the terms 'Document' and 'Item' interchangably.
-
examples.py - Examples of common tasks:
- Create Database
- Create Container
- CRUD operations on Items in Container
- Query a Container for Items
- Create a Database user
-
database_management.py - Example demonstrating:
- Basic CRUD operations on a Database resource
- Query for Database
- List all Database resources on an account
-
container_management.py - Example demonstrating:
- Basic CRUD operations on a Container resource
- Query for Container
- Manage Container Provisioned Throughput
- List all Container resources in a Database
-
document_management.py - Example demonstrating basic CRUD operations on an Item resource.
-
index_management.py - Example demonstrating basic CRUD operations on a Item resource in a non-partitioned Container.
-
change_feed_management.py - Example demontrating how to consume the Change Feed and iterate on the results.
-
access_cosmos_with_resource_token.py - Example demontrating how to get and use resource token that allows restricted access to data.
-
multi-master operations - Example demonstrating multi-master operations.
-
tracing-open-telemetry - Example demonstrating how to use OpenTelemetry tracing with our SDK.
-
diagnostics_handler_sample.py - Example demonstrating how to use diagnostics handler with our SDK.
- Python 3.8+
- You must have an Azure subscription and an Azure Cosmos DB account to run these samples.
- Install the latest beta version of Azure Cosmos that the samples use:
pip install azure-cosmos- Clone or download this sample repository.
- Open the sample folder in Visual Studio Code or your IDE of choice.
- Open a terminal window and
cdto the directory that the samples are saved in. - Set the environment variables specified in the sample file you wish to run.
- Follow the usage described in the file, e.g.
python database_management.py
Check out the API reference documentation to learn more about what you can do with the Azure Cosmos DB SQL API client library.