akshatnaruka/aidentity/azure-cosmos-py
Claude Code and agent skill by akshatnaruka/aidentity
Trust tier 2
- community
Source check pending
Checking that the SKILL.md file is still in the repository.
Azure Cosmos DB SDK for Python (NoSQL API). Use for document CRUD, queries, containers, and globally distributed data. Triggers: "cosmos db", "CosmosClient", "container", "document", "NoSQL", "partition key".
Install
npx vskill@latest install akshatnaruka/aidentity/azure-cosmos-pySKILL.md
The same SKILL.md was published earlier as samuelchien/mega-skills-collection/azure-cosmos-py.
Azure Cosmos DB SDK for Python
Client library for Azure Cosmos DB NoSQL API — globally distributed, multi-model database.
Installation
Environment Variables
Authentication & Lifecycle
🔑 Two rules apply to every code sample below:1. Prefer `DefaultAzureCredential`. It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.- Local dev:DefaultAzureCredentialworks as-is.- Production: setAZURE_TOKEN_CREDENTIALS=prod(orAZURE_TOKEN_CREDENTIALS=<specific_credential>) to constrain the credential chain to production-safe credentials.2. Wrap every client in a context manager so HTTP transports, sockets, and token caches are released deterministically:- Sync:with <Client>(...) as client:- Async:async with <Client>(...) as client:andasync with DefaultAzureCredential() as credential:(fromazure.identity.aio)Snippets may abbreviate this setup, but production code should always follow both rules.
Client Hierarchy
| Client | Purpose | Get From | |
|---|---|---|---|
CosmosClient | Account-level operations | Direct instantiation | |
DatabaseProxy | Database operations | client.get_database_client() | |
ContainerProxy | Container/item operations | database.get_container_client() |
Core Workflow
Setup Database and Container
Create Item
Read Item
Update Item (Replace)
Upsert Item
Delete Item
Queries
Basic Query
Cross-Partition Query
Query with Projection
Read All Items
Partition Keys
Critical: Always include partition key for efficient operations.
Throughput
Async Client
Error Handling
Best Practices
- Pick sync OR async and stay consistent. Do not mix
azure.cosmossync clients withazure.cosmos.aioasync clients in the same call path. Choose one mode per module. - Always use context managers for clients and async credentials. Wrap every client in
with CosmosClient(...) as client:(sync) orasync with CosmosClient(...) as client:(async). For asyncDefaultAzureCredentialfromazure.identity.aio, also useasync with credential:so tokens and transports are cleaned up. - Use `DefaultAzureCredential` for portable auth across local dev and Azure (avoid connection strings / API keys when possible).
- Always specify partition key for point reads and queries
- Use parameterized queries to prevent injection and improve caching
- Avoid cross-partition queries when possible
- Use `upsert_item` for idempotent writes
- Use async client for high-throughput scenarios
- Design partition key for even data distribution
- Use `read_item` instead of query for single document retrieval
Reference Files
| File | Contents | |
|---|---|---|
| references/partitioning.md | Partition key strategies, hierarchical keys, hot partition detection and mitigation | |
| references/query-patterns.md | Query optimization, aggregations, pagination, transactions, change feed | |
| scripts/setup_cosmos_container.py | CLI tool for creating containers with partitioning, throughput, and indexing |
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/microsoft-azure/azure-cosmos-py/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/akshatnaruka/aidentity/azure-cosmos-py)