Microsoft Azure Client Runtime (msrestazure)
msrestazure provides Azure-specific functionality for the AutoRest-generated Python client runtime (`msrest`). It extends `msrest` with features like Azure Long-Running Operations (LRO) polling, Azure-specific authentication credentials, and error handling for Azure services. It is a foundational component for older versions of the Azure SDK for Python, with the current version being 0.6.4.post1. Its release cadence has been infrequent since 2020.
Warnings
- breaking Version 0.5.0 introduced breaking changes to credential classes (ServicePrincipalCredentials, UserPassCredentials, AADTokenCredentials). The 'auth_uri', 'state', and 'client' attributes/parameters were removed as they were unused or internal.
- gotcha Version 0.6.0 (and subsequent versions) requires 'msrest' version 0.6.x. The 'msrest' 0.6.x series itself introduced breaking changes. Upgrading msrestazure to 0.6.0+ might implicitly require adapting to msrest's breaking changes, even if msrestazure's direct API surface remained similar.
- gotcha msrestazure is part of the 'legacy' Azure SDK for Python ecosystem. For new development, it is generally recommended to use the newer 'azure-core' based SDKs (e.g., `azure-mgmt-compute`, `azure-identity`) which offer a more unified and modern experience and do not directly expose msrestazure's internal components.
Install
-
pip install msrestazure
Imports
- AzureOperationPoller
from msrestazure.azure_operation import AzureOperationPoller
- CloudError
from msrestazure.azure_exceptions import CloudError
- ServicePrincipalCredentials
from msrestazure.azure_active_directory import ServicePrincipalCredentials
- parse_resource_id
from msrestazure.tools import parse_resource_id
- AzureServiceClient
from msrestazure.azure_service_client import AzureServiceClient
Quickstart
from msrestazure.tools import parse_resource_id, is_valid_resource_id
# msrestazure provides utility functions for working with Azure resource IDs.
resource_id = "/subscriptions/subId/resourceGroups/rgName/providers/Microsoft.Compute/virtualMachines/vmName"
parsed_id = parse_resource_id(resource_id)
print(f"Original Resource ID: {resource_id}")
print(f"Subscription: {parsed_id.get('subscription')}")
print(f"Resource Group: {parsed_id.get('resource_group')}")
print(f"Provider: {parsed_id.get('resource_provider')}")
print(f"Resource Name: {parsed_id.get('resource_name')}")
print(f"\nIs valid resource ID '{resource_id}': {is_valid_resource_id(resource_id)}")
invalid_id = "/subscriptions/subId/resourceGroups/rgName/invalid"
print(f"Is valid resource ID '{invalid_id}': {is_valid_resource_id(invalid_id)}")