Azure Cosmos DB SDK Documentation
The Azure Cosmos DB SDK provides developers with a set of libraries to interact with Cosmos DB from a variety of programming languages. It offers support for CRUD operations, query execution, transactions, and more, while handling retries, connection management, and diagnostics.
Supported languages
- .NET (C# / F#)
- Java
- JavaScript / TypeScript (Node.js)
- Python
- Go
Getting started
Below is a quick example of creating a client, a database, and a container using the .NET SDK.
using Azure.Cosmos;
var client = new CosmosClient("", "");
await client.CreateDatabaseIfNotExistsAsync("SamplesDB");
var database = client.GetDatabase("SamplesDB");
await database.CreateContainerIfNotExistsAsync("Items", "/partitionKey");
var container = database.GetContainer("Items");
var item = new { id = "item1", partitionKey = "pk1", name = "Hello Cosmos!" };
await container.CreateItemAsync(item, new PartitionKey(item.partitionKey));
Node.js example
const { CosmosClient } = require("@azure/cosmos");
const endpoint = "";
const key = "";
const client = new CosmosClient({ endpoint, key });
async function run() {
const { database } = await client.databases.createIfNotExists({ id: "SamplesDB" });
const { container } = await database.containers.createIfNotExists({
id: "Items",
partitionKey: { paths: ["/partitionKey"] }
});
const item = { id: "item1", partitionKey: "pk1", name: "Hello Cosmos!" };
await container.items.create(item);
}
run().catch(console.error);
Key features
- Automatic retry and transient fault handling
- Connection pooling and multiplexing
- Integrated diagnostics and logging
- Support for LINQ queries (C#) and fluent query builder (JS, Java)
- Transactional batch operations
Further resources
Explore the full SDK documentation, migration guides, and API reference: