Azure Cosmos Rust
MicrosoftOfficialCreated by Microsoft
- Skill
- Tool integration
- Software development
- MIT
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The azure_data_cosmos library provides a Rust interface for Azure Cosmos DB, enabling developers to perform CRUD operations on documents, manage containers, and handle globally distributed data. It supports both Entra ID authentication and account key-based access, providing a structured client hierarchy for account, database, and container-level operations.
What it does
- Performs CRUD operations on Cosmos DB items using partition keys
- Manages database and container resources
- Supports patch operations for partial document updates
- Provides authentication via Entra ID or account keys
- Configures client routing strategies for regional proximity
When to use it
- When building Rust applications that require NoSQL storage in Azure
- When you need to perform document-level operations in Cosmos DB
- When implementing RBAC or key-based authentication for database access
- When you need to integrate Azure Cosmos DB into a Rust backend service
Advantages
- Official Microsoft-supported library for Rust
- Thread-safe client design for efficient resource sharing
- Native support for Rust's async ecosystem
- Flexible authentication options for development and production environments
Usage examples
- “How do I initialize a CosmosClient in Rust?”
- Use the CosmosClient builder with an AccountReference and appropriate credentials like DeveloperToolsCredential for local development.
- “How do I perform a CRUD operation on a Cosmos DB item in Rust?”
- Use the container_client to call methods such as create_item, read_item, replace_item, or delete_item, ensuring you provide the required partition key.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/microsoft/azure-cosmos-rust/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip azure-cosmos-rust.zip -d .agents/skills
Documentation by Microsoft
Azure Cosmos DB library for Rust
Client library for Azure Cosmos DB NoSQL API — document CRUD, containers, and globally distributed data.
Use this skill when:
An app needs to store or query documents in Cosmos DB from Rust
You need CRUD operations on items with partition keys
You need key-based auth as an alternative to Entra ID
IMPORTANT: Only use the official
azure_data_cosmoscrate published by the azure-sdk crates.io user. Do NOT use the unofficialazure_cosmosorazure_sdk_for_rustcommunity crates. Official crates use underscores in names and none have version 0.21.0.
Installation
cargo add azure_data_cosmos azure_identity serde serde_json tokioIf your code uses
azure_coretypes directly (for example,azure_core::credentials::TokenCredential), addazure_coretoCargo.toml. If you only useazure_data_cosmosre-exports, directazure_coredependency is optional.
Environment Variables
COSMOS_ENDPOINT=https://<account>.documents.azure.com/ # Required for all operationsAuthentication
Rust Azure SDK code must not use DefaultAzureCredential. The Rust identity crate does not provide that type.
use azure_identity::DeveloperToolsCredential;
use azure_data_cosmos::{
CosmosClient, AccountReference, AccountEndpoint, RoutingStrategy,
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Local dev: DeveloperToolsCredential. Production: use ManagedIdentityCredential.
let credential = DeveloperToolsCredential::new(None)?;
let endpoint: AccountEndpoint = "https://<account>.documents.azure.com/"
.parse()?;
let account = AccountReference::with_credential(endpoint, credential);
let client = CosmosClient::builder()
.build(account, RoutingStrategy::ProximityTo("East US".into()))
.await?;
Ok(())
}Prefer the crate README/examples when checking builder signatures and CRUD method shapes instead of reconstructing APIs from memory or generated internals.
Client Hierarchy
| Client | Purpose | Access |
|---|---|---|
CosmosClient | Account-level operations | CosmosClient::builder().build(account).await? |
DatabaseClient | Database operations | client.database_client("db") |
ContainerClient | Container/item operations | database.container_client("c").await |
Core Workflow
use serde::{Serialize, Deserialize};
use azure_data_cosmos::CosmosClient;
#[derive(Serialize, Deserialize)]
struct Item {
pub id: String,
pub partition_key: String,
pub value: String,
}
async fn crud(client: CosmosClient) -> Result<(), Box<dyn std::error::Error>> {
let container = client
.database_client("myDatabase")
.container_client("myContainer")
.await;
let item = Item {
id: "1".into(),
partition_key: "pk1".into(),
value: "hello".into(),
};
// Create
container.create_item("pk1", "1", item, None).await?;
// Read
let resp = container.read_item("pk1", "1", None).await?;
let mut item: Item = resp.into_model()?;
// Update
item.value = "updated".into();
container.replace_item("pk1", "1", item, None).await?;
// Delete
container.delete_item("pk1", "1", None).await?;
Ok(())
}Patch Item
use azure_data_cosmos::{PatchInstructions, PatchOperation};
let patch = PatchInstructions::from(vec![
PatchOperation::set("/value", serde_json::json!("patched")),
]);
let patched: Item = container
.patch_item("pk1", "1", patch, None)
.await?
.into_model()?;
println!("Patched value: {}", patched.value);Key Auth (Optional)
Enable account key authentication with the feature flag:
cargo add azure_data_cosmos --features key_authRBAC Roles
For Entra ID auth, assign one of these built-in Cosmos DB roles:
| Role | Access |
|---|---|
Cosmos DB Built-in Data Reader | Read-only |
Cosmos DB Built-in Data Contributor | Read/write |
Best Practices
Use
cargo addto manage dependencies, never editCargo.tomldirectly. Add and remove Rust SDK dependencies with cargo commands instead of manual manifest edits.Add
azure_coreonly when importingazure_coretypes directly. If your code importsazure_core::http::Url,azure_core::http::RequestContent, orazure_core::error::ErrorKind, includeazure_core; otherwise a direct dependency is optional.Use
DeveloperToolsCredentialfor local dev,ManagedIdentityCredentialfor production — Rust does not provide a singleDefaultAzureCredentialtypeNever hardcode credentials — use environment variables or managed identity
Reuse
CosmosClient— clients are thread-safe; create once, share across tasksUse
RoutingStrategy::ProximityTo— route to the nearest region for lowest latencyAlways specify partition key for item operations — Cosmos DB requires it for all CRUD
Run
cargo clippy -- -D warningswhen the prompt, eval, or CI expects lint-clean outputFuture-proof
#[non_exhaustive]SDK models — when constructing SDK model/options structs, end the initializer with..Default::default()(add#[allow(clippy::needless_update)]) and use a_wildcard arm when matching SDK enums, so new service-added fields/variants don't break your build
Reference Links
Files
- ATTRIBUTION.mdAdded by AutoGineer958 B
- LICENSELicence file added by AutoGineer1.1 KiB
- SKILL.md6.4 KiB
ATTRIBUTION.md
Attribution
This folder is an unmodified copy of the Agent Skill "azure-cosmos-rust", distributed by AutoGineer (https://autogineer.com/agent-skills).
Commit: 0696600436a9669184ce47e8d8b2ceac62e4bfac
Created by: Microsoft (https://github.com/microsoft/skills/tree/0696600436a9669184ce47e8d8b2ceac62e4bfac/.github/plugins/azure-sdk-rust/skills/azure-cosmos-rust)
Publisher: Microsoft (https://github.com/microsoft)
Licence: MIT License (https://spdx.org/licenses/MIT.html)
Licence evidence: declared in the frontmatter ("license: MIT")
Retrieved: 2026-11-07
The skill's own files are unmodified copies. AutoGineer is not affiliated with or endorsed by the author or the publisher.
Files added by AutoGineer
ATTRIBUTION.md: this file, written by AutoGineer
LICENSE: copied from LICENSE
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Microsoft
- Publisher
- Microsoft (Official)
- Source
- microsoft/skills · .github/plugins/azure-sdk-rust/skills/azure-cosmos-rust · commit 0696600
- Licence
- MIT License (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Microsoft.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-cosmos-rust.zip