{"library":"azure-mgmt-cosmosdb","title":"Azure Cosmos DB Management Client Library for Python","description":"The Microsoft Azure Cosmos DB Management Client Library for Python provides capabilities to manage Azure Cosmos DB resources, such as creating, updating, and deleting Cosmos DB accounts, databases, and containers. It interacts with the Azure Cosmos DB resource provider (control plane). The current version is 9.9.0, and it generally follows a regular release cadence as part of the Azure SDK for Python updates.","status":"active","version":"9.9.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cosmosdb/azure-mgmt-cosmosdb","tags":["azure","cosmosdb","management","sdk","cloud","arm"],"install":[{"cmd":"pip install azure-mgmt-cosmosdb azure-identity","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Required for Azure Active Directory token authentication, used by DefaultAzureCredential.","package":"azure-identity"},{"reason":"Minimum Python version supported.","package":"python","version":">=3.9","optional":false}],"imports":[{"symbol":"CosmosDBManagementClient","correct":"from azure.mgmt.cosmosdb import CosmosDBManagementClient"},{"symbol":"DefaultAzureCredential","correct":"from azure.identity import DefaultAzureCredential"},{"note":"In older versions (e.g., prior to 0.8.0), some top-level client classes were accessible via a submodule. Current versions centralize client imports directly under `azure.mgmt.cosmosdb`.","wrong":"from azure.mgmt.cosmosdb.cosmos_db import CosmosDB","symbol":"CosmosDB","correct":"from azure.mgmt.cosmosdb import CosmosDBManagementClient"},{"note":"Prior to 0.8.0, some models were incorrectly importable from submodules. Direct import from `azure.mgmt.cosmosdb.models` is the correct pattern.","wrong":"from azure.mgmt.cosmosdb.models.<model_name> import <ModelName>","symbol":"models.*","correct":"from azure.mgmt.cosmosdb.models import <ModelName>"},{"note":"Similar to models, operations groups were incorrectly importable from submodules in older versions. Direct import from `azure.mgmt.cosmosdb.operations` is the correct pattern.","wrong":"from azure.mgmt.cosmosdb.operations.<operation_group_name> import <OperationGroup>","symbol":"operations.*","correct":"from azure.mgmt.cosmosdb.operations import <OperationGroup>"}],"quickstart":{"code":"import os\nfrom azure.identity import DefaultAzureCredential\nfrom azure.mgmt.cosmosdb import CosmosDBManagementClient\n\n# Set these environment variables for authentication\n# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET for service principal\n# AZURE_SUBSCRIPTION_ID\n\nsubscription_id = os.environ.get(\"AZURE_SUBSCRIPTION_ID\", \"YOUR_SUBSCRIPTION_ID\")\n\nif subscription_id == \"YOUR_SUBSCRIPTION_ID\":\n    print(\"Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'YOUR_SUBSCRIPTION_ID' in the code.\")\n    exit()\n\n# Authenticate using DefaultAzureCredential\n# This will try to authenticate using various methods (env vars, managed identity, CLI, etc.)\ncredential = DefaultAzureCredential()\n\n# Create a CosmosDB management client\nclient = CosmosDBManagementClient(credential, subscription_id)\n\n# Example: List all Cosmos DB accounts in the subscription\nprint(\"Listing Cosmos DB accounts...\")\nfor account in client.database_accounts.list():\n    print(f\" - {account.name} (Resource Group: {account.resource_group})\")\n\nprint(\"Client initialized successfully and listed accounts.\")","lang":"python","description":"Initializes the `CosmosDBManagementClient` using `DefaultAzureCredential` and lists existing Cosmos DB accounts. Ensure `AZURE_SUBSCRIPTION_ID` and other Azure authentication environment variables (like `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`) are set."},"warnings":[{"fix":"Consult the official release notes and update your code to reflect the new model structures and client operations.","message":"Version 9.9.0 introduced several breaking changes including removal of parameters from models (e.g., `BackupResource`, `CommandPostBody`, `ServiceResourceCreateUpdateParameters`) and deletion/renaming of client operation groups and enum values. Review release notes carefully when upgrading.","severity":"breaking","affected_versions":">=9.9.0"},{"fix":"Update import statements to use the streamlined `from azure.mgmt.cosmosdb import <Client/Class>` pattern and access models/operations via the client object or `azure.mgmt.cosmosdb.models`/`azure.mgmt.cosmosdb.operations` directly.","message":"Older versions (pre ~0.8.0) had module reorganization which changed import paths for `CosmosDB` client and direct access to models and operations submodules. This can cause `ImportError` for legacy code.","severity":"breaking","affected_versions":"<0.8.0 to current"},{"fix":"Ensure all necessary Azure authentication environment variables are correctly set for your chosen authentication method before initializing `DefaultAzureCredential`.","message":"`DefaultAzureCredential` relies on specific environment variables for non-interactive/service principal authentication (e.g., `AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`). Incorrect or missing configuration will lead to authentication failures.","severity":"gotcha","affected_versions":"All versions using `azure-identity`"},{"fix":"Upgrade your Python environment to Python 3.9 or newer. The library requires Python >=3.9.","message":"Support for Python 2.7 officially ended on January 1, 2022. Using `azure-mgmt-cosmosdb` with Python 2.7 is unsupported and will likely lead to issues.","severity":"deprecated","affected_versions":"<=3.8"},{"fix":"Embrace asynchronous programming patterns (`async`/`await`) where possible, especially for I/O bound operations. For management plane operations, utilize the built-in polling mechanisms for long-running operations.","message":"Synchronous I/O operations are generally discouraged and can be blocked by default in newer Azure SDKs. While primarily affecting data plane SDKs and .NET EF Core, it's a good practice to use async patterns or ensure long-running management operations are handled with polling for a responsive application.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}