Microsoft Azure Resource Management Client Library for Python providing comprehensive Azure resource lifecycle, governance, and deployment capabilities.
npx @tessl/cli install tessl/pypi-azure-mgmt-resource@24.0.0Microsoft Azure Resource Management Client Library for Python provides comprehensive Azure resource lifecycle, governance, and deployment capabilities. This library enables programmatic management of Azure resources, subscriptions, resource groups, policies, locks, and applications through multiple specialized client classes.
pip install azure-mgmt-resourcepip install azure-identity (required for authentication)from azure.mgmt.resource import (
ResourceManagementClient,
PolicyClient,
SubscriptionClient,
FeatureClient,
ManagementLockClient,
ManagementLinkClient,
ApplicationClient,
DataBoundaryMgmtClient
)For authentication:
from azure.identity import DefaultAzureCredentialimport os
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
# Authentication
credential = DefaultAzureCredential()
subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID")
# Create client
client = ResourceManagementClient(
credential=credential,
subscription_id=subscription_id
)
# List resource groups
resource_groups = client.resource_groups.list()
for rg in resource_groups:
print(f"Resource Group: {rg.name} in {rg.location}")
# Get a specific resource group
rg = client.resource_groups.get("my-resource-group")
print(f"Resource Group Tags: {rg.tags}")The Azure Resource Management SDK is organized into specialized client classes, each targeting specific Azure management capabilities:
Each client supports multiple API versions, async operations, and follows Azure SDK patterns for authentication, error handling, and pagination.
All clients require Azure credentials. Set these environment variables:
AZURE_CLIENT_ID - Azure client IDAZURE_TENANT_ID - Azure tenant IDAZURE_CLIENT_SECRET - Azure client secretAZURE_SUBSCRIPTION_ID - Azure subscription IDComprehensive resource lifecycle management including deployments, resource groups, providers, and resource operations. This is the primary client for most Azure resource management tasks.
class ResourceManagementClient:
def __init__(self, credential, subscription_id: str, **kwargs): ...
@property
def resources(self) -> ResourcesOperations: ...
@property
def resource_groups(self) -> ResourceGroupsOperations: ...
@property
def deployments(self) -> DeploymentsOperations: ...
@property
def providers(self) -> ProvidersOperations: ...
@property
def tags(self) -> TagsOperations: ...Azure Policy management for implementing governance, compliance, and security standards across Azure resources through policy definitions, assignments, and compliance monitoring.
class PolicyClient:
def __init__(self, credential, subscription_id: str, **kwargs): ...
@property
def policy_assignments(self) -> PolicyAssignmentsOperations: ...
@property
def policy_definitions(self) -> PolicyDefinitionsOperations: ...
@property
def policy_set_definitions(self) -> PolicySetDefinitionsOperations: ...Subscription operations and Azure feature management including feature registration, tenant-level operations, and subscription metadata management.
class SubscriptionClient:
def __init__(self, credential, **kwargs): ...
@property
def subscriptions(self) -> SubscriptionsOperations: ...
@property
def tenants(self) -> TenantsOperations: ...
class FeatureClient:
def __init__(self, credential, subscription_id: str, **kwargs): ...
@property
def features(self) -> FeaturesOperations: ...
@property
def subscription_feature_registrations(self) -> SubscriptionFeatureRegistrationsOperations: ...Resource locks for preventing accidental deletion or modification, resource links for creating relationships, managed applications, and data boundary management.
class ManagementLockClient:
def __init__(self, credential, subscription_id: str, **kwargs): ...
@property
def management_locks(self) -> ManagementLocksOperations: ...
class ManagementLinkClient:
def __init__(self, credential, subscription_id: str, **kwargs): ...
@property
def resource_links(self) -> ResourceLinksOperations: ...
class ApplicationClient:
def __init__(self, credential, subscription_id: str, **kwargs): ...
@property
def applications(self) -> ApplicationsOperations: ...
@property
def application_definitions(self) -> ApplicationDefinitionsOperations: ...
class DataBoundaryMgmtClient:
def __init__(self, credential, subscription_id: str, **kwargs): ...
@property
def data_boundaries(self) -> DataBoundariesOperations: ...Resource Protection and Linking
class Resource:
"""Base resource representation."""
id: str
name: str
type: str
location: str
tags: dict
class ResourceGroup:
"""Resource group representation."""
id: str
name: str
location: str
properties: ResourceGroupProperties
tags: dict
managed_by: str
class GenericResource(Resource):
"""Generic resource with extended properties."""
plan: Plan
properties: object
kind: str
managed_by: str
sku: Sku
identity: Identity
# Authentication and client types
class DefaultAzureCredential:
"""Default Azure credential provider."""
def __init__(self, **kwargs): ...
# Common result types
class ResourceListResult:
"""Paginated list of resources."""
value: List[GenericResource]
next_link: str
class ResourceGroupListResult:
"""Paginated list of resource groups."""
value: List[ResourceGroup]
next_link: strfrom azure.core.exceptions import (
HttpResponseError,
ResourceNotFoundError,
ResourceExistsError
)
try:
resource_group = client.resource_groups.get("nonexistent-rg")
except ResourceNotFoundError:
print("Resource group not found")
except HttpResponseError as e:
print(f"HTTP error: {e.status_code} - {e.message}")