Azure Management Client Libraries

5.0.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list all resource groups within a specified subscription. It requires the `AZURE_SUBSCRIPTION_ID` environment variable to be set and the `azure-identity` package installed. The `ResourceManagementClient` is imported from `azure.mgmt.resource`, which is part of the `azure-mgmt` meta-package.

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).")

view raw JSON →