Setup & Installation
What This Skill Does
Guides Python and FastAPI code toward production-ready Azure Cosmos DB NoSQL integrations. Covers client setup with dual authentication (DefaultAzureCredential for Azure, key-based for the local emulator), service layer patterns with CRUD operations, partition key strategies, and parameterized queries. Includes TDD fixtures for mocking the Cosmos container in pytest.
It encodes the non-obvious production details — RBAC auth, parameterized queries, partition key isolation, async wrapping, and graceful degradation — that are easy to get wrong when wiring Cosmos DB into FastAPI for the first time.
When to use it
- Setting up a Cosmos DB singleton client that switches between Azure RBAC and the local emulator automatically
- Writing a service class with get, create, update, and delete methods backed by Cosmos DB documents
- Designing partition key schemes to avoid cross-partition scans on a multi-tenant dataset
- Adding pytest fixtures that mock the Cosmos container without a live database connection
- Mapping Pydantic models to Cosmos documents with camelCase JSON aliases and a five-tier model hierarchy