Azure Management Core Library for Python

1.6.0 · active · verified Sun Mar 29

The `azure-mgmt-core` library provides extensions to Azure Core that are specific to Azure Resource Management (ARM), primarily used by Azure SDK management client libraries (e.g., `azure-mgmt-resource`). As a foundational component, it handles common ARM-specific patterns such as long-running operations and authentication challenges. The current stable version is 1.6.0, and it follows the release cadence of the broader Azure SDK for Python.

Warnings

Install

Imports

Quickstart

This library is primarily an internal dependency for Azure management SDKs. As such, direct 'quickstarts' for `azure-mgmt-core` are uncommon. Instead, its functionality is consumed by service-specific management clients (e.g., `ResourceManagementClient`). This example demonstrates how to initialize and use a typical Azure management client, which implicitly leverages `azure-mgmt-core` for its core ARM functionalities like authentication and request handling. Ensure `AZURE_SUBSCRIPTION_ID` is set as an environment variable or replaced.

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

# NOTE: azure-mgmt-core is an internal dependency for Azure management SDKs.
# This quickstart demonstrates how a typical Azure management client is used,
# which indirectly relies on azure-mgmt-core.

# Your Azure subscription ID
# It's recommended to set this as an environment variable (AZURE_SUBSCRIPTION_ID)
# or retrieve it from your Azure context.
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "your-subscription-id")

if subscription_id == "your-subscription-id":
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable or replace 'your-subscription-id'.")
    exit()

# Authenticate with Azure using DefaultAzureCredential.
# This attempts to authenticate via various methods like environment variables, Azure CLI, managed identity, etc.
credential = DefaultAzureCredential()

# Create a ResourceManagementClient (which uses azure-mgmt-core internally)
resource_client = ResourceManagementClient(credential, subscription_id)

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

print("\nQuickstart finished. This demonstrates how an Azure management client (which relies on azure-mgmt-core) is typically used.")

view raw JSON →