azure-cosmos-db-py
Build Azure Cosmos DB Services with Python
Implement production-grade Azure Cosmos DB NoSQL services with proper authentication, clean architecture, and test-driven development. This skill provides templates and patterns for secure database integration in FastAPI applications.
Download the skill ZIP
Upload in Claude
Go to Settings → Capabilities → Skills → Upload skill
Toggle on and start using
Test it
Using "azure-cosmos-db-py". Create a Cosmos DB client module with dual authentication
Expected outcome:
A complete cosmos.py file with get_container() singleton function, _is_emulator_endpoint() detection helper, and support for both DefaultAzureCredential and emulator key authentication modes.
Using "azure-cosmos-db-py". Build a ProjectService with CRUD operations
Expected outcome:
Service class with get_by_id, create, update, and delete methods using async wrappers, proper Pydantic model conversion, and graceful degradation returning None when Cosmos is unavailable.
Security Audit
SafeAll 37 static analysis findings are false positives. The scanned file (SKILL.md) is a documentation file containing code examples in markdown format, not executable code. External command detections are bash examples in documentation blocks. Network and environment variable references are configuration templates for Azure Cosmos DB connectivity. The skill demonstrates proper security practices including RBAC via DefaultAzureCredential, parameterized queries, and secure secret management.
Quality Score
What You Can Build
Backend Developer Building SaaS Application
Implement multi-tenant data storage using Cosmos DB with partition key isolation per workspace, leveraging DefaultAzureCredential for secure production deployment.
DevOps Engineer Setting Up Development Environment
Configure local development with Cosmos DB emulator, using environment variables for endpoint configuration and test fixtures for CI/CD pipelines.
Solution Architect Designing Cloud-Native Applications
Apply clean architecture patterns with repository and service layers, ensuring separation of business logic from database implementation for long-term maintainability.
Try These Prompts
Create a Cosmos DB client module with singleton pattern that uses DefaultAzureCredential for production and emulator key for local development. Include SSL configuration and container initialization.
Build a service class for Project entity with CRUD operations. Use five-tier Pydantic model pattern and implement graceful degradation when Cosmos DB is unavailable.
Implement Cosmos DB SQL queries using @parameter syntax for filtering projects by workspace_id and name. Include proper error handling for CosmosResourceNotFoundError.
Create pytest fixtures for mocking Cosmos DB container operations. Include async test examples for service layer methods with proper mocking of get_container function.
Best Practices
- Always use DefaultAzureCredential in production environments - never hardcode keys or secrets in source code
- Use parameterized queries with @parameter syntax to prevent SQL injection in Cosmos DB queries
- Implement graceful degradation by returning None or empty lists when Cosmos DB is unavailable instead of throwing exceptions
Avoid
- Hardcoding connection keys or secrets directly in source code instead of using environment variables or managed identity
- Using string concatenation to build queries instead of parameterized query syntax with @parameter placeholders
- Creating new CosmosClient instances per request instead of using singleton pattern for connection pooling
Frequently Asked Questions
What is the difference between DefaultAzureCredential and emulator key authentication?
How do I handle Cosmos DB unavailability gracefully?
Why use async wrappers for synchronous Cosmos SDK calls?
What is the five-tier model pattern?
How do I choose a partition key for Cosmos DB?
Can I use this skill with other Azure Cosmos DB APIs like MongoDB or SQL?
Developer Details
Author
sickn33License
MIT
Repository
https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/azure-cosmos-db-pyRef
main
File structure
📄 SKILL.md