Azure Resource Management Client Library

raw JSON →
25.0.0 verified Tue May 12 auth: no python install: verified

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.

pip install azure-mgmt-resource azure-identity
error ModuleNotFoundError: No module named 'azure.mgmt.resource.subscriptions'
cause In `azure-mgmt-resource` version 25.0.0, several modules, including `subscriptions`, were separated into their own independent packages as part of a breaking change to reduce package size.
fix
Install the specific module package (e.g., pip install azure-mgmt-resource-subscriptions) and update your import statement to from azure.mgmt.resource.subscriptions import SubscriptionClient.
error ImportError: cannot import name 'DeploymentWhatIf' from 'azure.mgmt.resource.resources.models'
cause With the release of `azure-mgmt-resource` 25.0.0, certain models, such as `DeploymentWhatIf`, were removed or relocated from the `azure.mgmt.resource.resources.models` module due to API version targeting changes.
fix
Review the official Azure SDK for Python documentation or changelog for the specific API version you are targeting to find the correct module path or the alternative class/method to achieve the desired functionality. You may need to pin to an older version of azure-mgmt-resource if your application strictly relies on these removed models.
error DefaultAzureCredential failed to retrieve a token from the included credentials.
cause This error occurs when `DefaultAzureCredential` cannot find valid credentials configured in the environment (e.g., environment variables, Azure CLI login, Managed Identity) or lacks the necessary permissions to acquire a token.
fix
Ensure that required environment variables like AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET are correctly set for EnvironmentCredential, or that you are logged in via az login for AzureCliCredential. Verify that the authenticated identity has the necessary Azure RBAC permissions on the target resources and subscription.
error Code=ResourceGroupNotFound; Message=Resource group 'resource_group_name' could not be found.
cause This API error indicates that the specified resource group does not exist in the active Azure subscription, or there is a typo in the resource group's name, or the authenticated identity does not have permission to view it, or the wrong subscription context is being used.
fix
Double-check the resource group name for typos. Verify that your Azure client is configured for the correct subscription ID. Ensure the service principal or user account has sufficient permissions (e.g., Reader role) on the subscription or resource group. You can use az account show to check your current CLI subscription and az account set --subscription <id> to change it.
error ModuleNotFoundError: No module named 'azure.mgmt.resource'
cause The `azure-mgmt-resource` package is not installed in the current Python environment.
fix
Install the library using pip: pip install azure-mgmt-resource
breaking Version 25.0.0 and later packages now exclusively target the latest API-Version available on Azure. If your application relies on a specific, non-latest API-Version, you must pin the package to a previous version to maintain compatibility.
fix Pin your `azure-mgmt-resource` package version to a previous release (e.g., `<25.0.0`) if you depend on an older API version. Otherwise, update your code to reflect changes in the latest API version if necessary.
breaking Many sub-modules and their corresponding clients, such as `subscriptions`, `features`, `links`, `locks`, `policy`, `managedapplications`, `databoundaries`, `changes`, `privatelinks`, `deploymentstacks`, `deploymentscripts`, and `templatespecs` have been separated from `azure-mgmt-resource` into independent packages or submodules.
fix Update your import statements. For example, `from azure.mgmt.resource import SubscriptionClient` should become `from azure.mgmt.resource.subscriptions import SubscriptionClient`. Similarly, operations like `client.deployments` have moved to a new client type, `DeploymentsMgmtClient`, in a dedicated package `azure-mgmt-resource-deployments`.
gotcha Many Azure operations, especially resource creation or deletion, are asynchronous and return a `Poller` object. Calling `.result()` on the poller is necessary to wait for the operation's completion and retrieve the final result.
fix Always use `.begin_` methods for long-running operations (e.g., `resource_groups.begin_create_or_update`) and then call `.result()` on the returned poller object to ensure the operation completes before proceeding.
gotcha The `DefaultAzureCredential` used for authentication relies on environment variables (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_SUBSCRIPTION_ID`) or other configured authentication mechanisms (like Azure CLI login, Managed Identity) for local development and deployment. Incorrect or missing environment variables will lead to authentication failures.
fix Ensure the necessary environment variables (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET` for service principal, and `AZURE_SUBSCRIPTION_ID` for the client) are correctly configured in your development or deployment environment.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.47s 43.6M
3.10 alpine (musl) - - 0.44s 42.5M
3.10 slim (glibc) wheel 3.8s 0.34s 44M
3.10 slim (glibc) - - 0.30s 43M
3.11 alpine (musl) wheel - 0.57s 47.1M
3.11 alpine (musl) - - 0.60s 46.0M
3.11 slim (glibc) wheel 3.8s 0.51s 47M
3.11 slim (glibc) - - 0.46s 46M
3.12 alpine (musl) wheel - 0.77s 38.6M
3.12 alpine (musl) - - 0.81s 37.5M
3.12 slim (glibc) wheel 3.3s 0.74s 39M
3.12 slim (glibc) - - 0.74s 38M
3.13 alpine (musl) wheel - 0.76s 38.3M
3.13 alpine (musl) - - 0.80s 37.1M
3.13 slim (glibc) wheel 3.4s 0.73s 39M
3.13 slim (glibc) - - 0.75s 37M
3.9 alpine (musl) wheel - 0.49s 43.6M
3.9 alpine (musl) - - 0.44s 42.5M
3.9 slim (glibc) wheel 4.4s 0.46s 44M
3.9 slim (glibc) - - 0.39s 43M

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