Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/services/app-service/templates/recipes/cosmos/source/python.md
1# Cosmos DB Recipe — Python — REFERENCE ONLY23## Cosmos SDK Setup45### Requirements67Add to `requirements.txt`:89```10azure-cosmos>=4.711azure-identity12```1314### Database Module1516Create `cosmos_client.py`:1718```python19import os20from azure.cosmos import CosmosClient21from azure.identity import DefaultAzureCredential2223credential = DefaultAzureCredential()24client = CosmosClient(os.environ["COSMOS_ENDPOINT"], credential)25database = client.get_database_client(os.environ["COSMOS_DATABASE_NAME"])26container = database.get_container_client(os.environ["COSMOS_CONTAINER_NAME"])27```2829### CRUD Endpoints3031Add to `main.py`:3233```python34from cosmos_client import container3536@app.get("/api/items")37async def list_items():38items = list(container.read_all_items())39return items4041@app.post("/api/items", status_code=201)42async def create_item(item: dict):43return container.create_item(body=item)44```4546## Files to Modify4748| File | Action |49|------|--------|50| `cosmos_client.py` | Create — Cosmos client + container reference |51| `main.py` | Modify — add CRUD endpoints |52| `requirements.txt` | Modify — add azure-cosmos, azure-identity |53