Azure Management Client Libraries
The `azure-mgmt` package is a meta-package providing Microsoft Azure Resource Management Client Libraries for Python. It aggregates all individual `azure-mgmt-xxx` packages, allowing Python applications to programmatically manage Azure resources like virtual machines, storage accounts, and networks. The current version is 5.0.0, following the 'Track 2' design guidelines for the Azure SDK. It typically follows a continuous release cadence with updates to individual service clients.
Warnings
- breaking Major API redesign between 'Track 1' (older) and 'Track 2' (current) versions. `azure-mgmt` versions 5.0.0 and later are 'Track 2' which includes unified authentication, asynchronous support, and consistent client construction. Code written for older `azure-mgmt` versions (pre-5.0.0) will not be compatible.
- gotcha The `azure-mgmt` package is a meta-package that installs *all* individual `azure-mgmt-xxx` packages (e.g., `azure-mgmt-resource`, `azure-mgmt-compute`). While convenient, this can lead to a large number of dependencies. For production applications, it is often more efficient to install only the specific `azure-mgmt-SERVICE_NAME` packages required.
- gotcha Authentication is handled by the separate `azure-identity` library. `azure-mgmt` client libraries do not include authentication mechanisms directly. Attempting to use clients without an `azure-identity` credential object will result in authentication errors.
Install
-
pip install azure-mgmt azure-identity -
pip install azure-mgmt-resource azure-identity
Imports
- ResourceManagementClient
from azure.mgmt.resource import ResourceManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
# Set your Azure Subscription ID as an environment variable
# E.g., export AZURE_SUBSCRIPTION_ID='YOUR_SUBSCRIPTION_ID'
subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', '')
if not subscription_id:
print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
else:
try:
# Authenticate using DefaultAzureCredential (looks for env vars, managed identity, etc.)
credential = DefaultAzureCredential()
# Create a ResourceManagementClient
resource_client = ResourceManagementClient(credential, subscription_id)
print(f"Listing resource groups in subscription: {subscription_id}")
for rg in resource_client.resource_groups.list():
print(f"- {rg.name} ({rg.location})")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure you have authenticated (e.g., `az login` or appropriate environment variables).")