Azure Resource Management Client Library

25.0.0 · active · verified Sun Mar 29

The `azure-mgmt-resource` library is the Microsoft Azure Resource Management Client Library for Python. It provides programmatic access to the Azure Resource Manager (ARM) API, enabling developers to create, update, query, and delete Azure resources and resource groups. Part of the comprehensive Azure SDK for Python, it's currently at version 25.0.0 and maintains an active development and release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with `DefaultAzureCredential` and create an instance of `ResourceManagementClient` to list existing resource groups and shows an example of how to create a new one. Ensure required environment variables like `AZURE_SUBSCRIPTION_ID` are set.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient

# Set your Azure Subscription ID as an environment variable: AZURE_SUBSCRIPTION_ID
# For local development, also set: AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "")

# Acquire a credential object using DefaultAzureCredential. 
# This will attempt to authenticate in various environments.
credential = DefaultAzureCredential()

# Create a Resource Management client
resource_client = ResourceManagementClient(credential, subscription_id)

# Example: List resource groups in the subscription
print("Listing resource groups...")
for rg in resource_client.resource_groups.list():
    print(f"  Resource Group: {rg.name} (Location: {rg.location})")

# Example: Create a new resource group (uncomment to run)
# RESOURCE_GROUP_NAME = "my-new-resource-group"
# RESOURCE_GROUP_LOCATION = "eastus"
# print(f"Creating resource group '{RESOURCE_GROUP_NAME}' in '{RESOURCE_GROUP_LOCATION}'...")
# creation_result = resource_client.resource_groups.begin_create_or_update(
#     RESOURCE_GROUP_NAME,
#     {"location": RESOURCE_GROUP_LOCATION}
# ).result() # .result() waits for the long-running operation to complete
# print(f"Resource group '{creation_result.name}' created.")

view raw JSON →