Microsoft Azure Client Runtime (msrestazure)

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

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.

pip install msrestazure
error ModuleNotFoundError: No module named 'msrestazure'
cause The `msrestazure` package is not installed in your Python environment or is not accessible on the Python path.
fix
Install the package using pip: pip install msrestazure
error ImportError: You need to install 'msrestazure' to use this feature
cause Another Azure SDK package or a specific feature you are trying to use has a dependency on `msrestazure` which is not installed or correctly linked.
fix
Ensure msrestazure is explicitly installed: pip install msrestazure
error AttributeError: 'ServicePrincipalCredentials' object has no attribute 'get_token'
cause You are likely using an older `msrestazure` based credential class (`ServicePrincipalCredentials`) with a newer Azure SDK client that expects credentials from the `azure-identity` library, which uses a different authentication mechanism.
fix
Migrate your authentication code to use credential classes from the azure-identity library (e.g., ClientSecretCredential, DefaultAzureCredential) and ensure your client is compatible with azure-identity.
error AttributeError: 'ManagedIdentityCredential' object has no attribute 'signed_session'
cause This error occurs when an Azure SDK client built using older `msrestazure` patterns expects a credential object with a `signed_session` method, but it receives a credential object (like `ManagedIdentityCredential` from `azure-identity`) that does not expose this method directly.
fix
For newer azure-identity credentials, you may need to use msrestazure.azure_active_directory.AzureIdentityCredentialWrapper to adapt the azure-identity credential for older msrestazure-based clients, or preferably, migrate to newer versions of the Azure SDK clients that natively support azure-identity credentials.
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.
fix Review your code for direct access or usage of 'auth_uri', 'state', or 'client' on these credential objects and remove them. These were primarily internal attributes.
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.
fix When upgrading to msrestazure 0.6.0 or higher, also review the breaking changes for the corresponding msrest 0.6.x version, as your code might be affected indirectly by changes in the underlying runtime.
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.
fix For new projects, prefer using the latest 'azure-mgmt-*' and 'azure-identity' packages which are built on 'azure-core'. Consult the official Azure SDK for Python documentation for the most up-to-date guidance.
breaking The resource ID parsing functionality in `msrestazure` (e.g., `parse_resource_id`) may incorrectly extract the 'provider' field, returning `None` even when a provider namespace is explicitly present in the resource ID string (e.g., '.../providers/Microsoft.Compute/...'). This can lead to applications failing to correctly identify or interact with the resource provider.
fix Applications relying on extracting the 'provider' from resource IDs using `msrestazure` should verify the output. If the parsing is incorrect, consider implementing custom parsing logic or migrating to the newer `azure-core` based SDKs (e.g., `azure-mgmt-resource`) which offer more robust and accurate resource ID parsing capabilities.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 1.06s 43.5M
3.10 alpine (musl) - - 1.21s 42.4M
3.10 slim (glibc) wheel 3.9s 0.73s 44M
3.10 slim (glibc) - - 0.77s 43M
3.11 alpine (musl) wheel - 1.19s 46.9M
3.11 alpine (musl) - - 1.31s 45.8M
3.11 slim (glibc) wheel 3.8s 1.06s 47M
3.11 slim (glibc) - - 1.00s 46M
3.12 alpine (musl) wheel - 1.13s 38.4M
3.12 alpine (musl) - - 1.16s 37.3M
3.12 slim (glibc) wheel 3.3s 1.11s 39M
3.12 slim (glibc) - - 1.17s 38M
3.13 alpine (musl) wheel - 1.12s 38.2M
3.13 alpine (musl) - - 1.14s 37.0M
3.13 slim (glibc) wheel 3.4s 1.03s 39M
3.13 slim (glibc) - - 1.14s 37M
3.9 alpine (musl) wheel - 0.99s 43.5M
3.9 alpine (musl) - - 0.96s 42.5M
3.9 slim (glibc) wheel 4.4s 0.91s 44M
3.9 slim (glibc) - - 0.83s 43M

This quickstart demonstrates the use of `msrestazure.tools` for parsing and validating Azure resource IDs, a common utility provided by the library. While `msrestazure` is primarily a low-level runtime for AutoRest-generated clients, these utility functions are directly usable.

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