Registry / azure / azure-mgmt-msi

azure-mgmt-msi

JSON →
library7.1.0pypypi✓ verified 24d ago

The Microsoft Azure Msi Management Client Library for Python provides functionality to manage Managed Service Identities (MSI) within Azure. These identities facilitate secure, credential-less authentication for Azure resources. It is part of the actively developed Azure SDK for Python, with a consistent release cadence for both stable and preview versions. The current stable version is 7.1.0.

pip install azure-mgmt-msi
INSTALL
IMPORT
SIG · AZURE-MGMT-MSI
A
azure-mgmt-msi
azurepythonv7.1.0
Install
3.2s avg
Import
541ms
Disk
54MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.580s · 98.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.2s · import 0.502s · 27MB
54MB installed
● package 54MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ManagedServiceIdentityClient
from azure.mgmt.msi import ManagedServiceIdentityClient
DefaultAzureCredential
from azure.identity import DefaultAzureCredential
from azure.common.credentials import ServicePrincipalCredentials
Older Azure SDK versions used `azure.common.credentials` or `msrestazure.azure_active_directory` for authentication. The current standard is `azure-identity`.

Initializes the `ManagedServiceIdentityClient` using `DefaultAzureCredential` for authentication, requiring environment variables for Azure AD credentials and subscription ID. It then demonstrates listing user-assigned identities in the specified subscription.

import os from azure.identity import DefaultAzureCredential from azure.mgmt.msi import ManagedServiceIdentityClient # Set environment variables for authentication: # AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET # And AZURE_SUBSCRIPTION_ID subscription_id = os.environ.get('AZURE_SUBSCRIPTION_ID', '') if not subscription_id: raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.") # Authenticate using DefaultAzureCredential credential = DefaultAzureCredential() # Create the MSI management client # For production, consider specifying api_version for stability, e.g., api_version='2023-01-31' client = ManagedServiceIdentityClient(credential=credential, subscription_id=subscription_id) # Example: List user-assigned identities in a subscription print(f"Listing user-assigned identities in subscription: {subscription_id}") for identity in client.user_assigned_identities.list_by_subscription(): print(f" Identity Name: {identity.name}, Location: {identity.location}") print("Quickstart finished successfully.")
Debug
Known issues
breakingAuthentication in versions 6.0.0b1 and later transitioned from legacy modules (e.g., `azure.common.credentials`, `msrestazure.azure_active_directory`) to the `azure-identity` library. The `credentials` parameter was also renamed to `credential`.
fix
Migrate your authentication code to use classes from the `azure-identity` package, such as `DefaultAzureCredential`. Update client instantiation to use the `credential` parameter.
affects: >=6.0.0b1
breakingMajor architectural changes were introduced in versions 6.0.0b1 and later, including the adoption of 'hybrid models' (which behave as both dictionaries and objects) and significant changes to method signatures. Long-running operations (LROs) are now prefixed with `begin_` (e.g., `create_or_update` becomes `begin_create_or_update`), and most exceptions are now `azure.core.exceptions.HttpResponseError` instead of `CloudError`.
fix
Consult the official Azure SDK for Python migration guides, specifically for hybrid models (https://aka.ms/azsdk/python/migrate/hybrid-models) and operation changes (https://aka.ms/azsdk/python/migrate/operations).
affects: >=6.0.0b1
breakingPython 2.7 support was officially dropped, and Python < 3.7.0 support was removed in version 7.1.0b1. The current stable version 7.1.0 requires Python 3.9+.
fix
Ensure your development and deployment environments use Python 3.9 or a newer compatible version.
affects: >=7.1.0b1
gotchaThe `ManagedServiceIdentityClient` is a multi-API version client. While it defaults to the latest API version, it's a best practice for production applications to explicitly pin to a specific API version in the client constructor for consistent behavior and to avoid unexpected changes from new API versions.
fix
Pass the `api_version` parameter with a specific date string (e.g., `api_version='2023-01-31'`) to the `ManagedServiceIdentityClient` constructor.
affects: All versions
gotchaThe test script failed because the AZURE_SUBSCRIPTION_ID environment variable was not set. This environment variable is often required by Azure SDK samples and tests to specify the target subscription for resource management operations.
fix
Set the AZURE_SUBSCRIPTION_ID environment variable to a valid Azure subscription ID before running the script (e.g., export AZURE_SUBSCRIPTION_ID='your-subscription-id').
affects: All versions
gotchaClient instantiation and operations typically require Azure credentials and configuration. The `ValueError: AZURE_SUBSCRIPTION_ID environment variable not set` indicates a missing prerequisite for using the Azure SDK.
fix
Ensure necessary environment variables, such as `AZURE_SUBSCRIPTION_ID`, are set before initializing Azure SDK clients or executing operations. Refer to the Azure SDK for Python documentation on authentication for details.
affects: All versions
Errors
Common errors & fixes
ManagedIdentityCredential authentication unavailable, no managed identity endpoint found.
This error occurs when the code attempts to use a Managed Service Identity (MSI) for authentication in an environment where a managed identity is not enabled, is misconfigured, or cannot be reached (e.g., running locally without Azure context, or network issues in Azure). The underlying `azure-identity` library tries to connect to the Azure Instance Metadata Service (IMDS) endpoint, which is not available outside of an Azure environment or is blocked.
fix
If running on an Azure resource (e.g., VM, App Service, Function App), ensure a system-assigned or user-assigned managed identity is enabled for that resource and has the necessary Role-Based Access Control (RBAC) permissions to access the target Azure resources. Verify network settings if within a Virtual Network. If running locally, use an alternative credential type for local development, such as `DefaultAzureCredential` (which will fall back to environment variables or Azure CLI login), `ClientSecretCredential`, `InteractiveBrowserCredential`, or `AzureCliCredential`.
ModuleNotFoundError: No module named 'azure.mgmt.msi'
This error indicates that the `azure-mgmt-msi` package is not installed or is not accessible within the Python environment where the code is being executed. This can happen due to incorrect installation, running in a different virtual environment, or package conflicts.
fix
Install the `azure-mgmt-msi` package using pip. It is also recommended to install `azure-identity` for modern Azure SDK authentication. If using virtual environments, ensure the correct environment is activated before installation and execution.
```bash
pip install azure-mgmt-msi azure-identity
```
AttributeError: 'ManagedIdentityCredential' object has no attribute 'signed_session'
This error typically arises from using an older version of an Azure management client library (not `azure-mgmt-msi` itself, but potentially another `azure.mgmt.*` client) that expects a credential object from the legacy `msrestazure.azure_active_directory.MSIAuthentication` class, which had a `signed_session` attribute. Newer `azure-identity` credential objects like `ManagedIdentityCredential` do not expose this attribute, leading to incompatibility.
fix
The recommended solution is to update all Azure SDK packages, especially the specific management client causing the error, to their latest versions. Newer clients are designed to directly accept `azure-identity` credential objects. If updating is not immediately possible and you must use an older client, you can use `AzureIdentityCredentialWrapper` from `azure.mgmt.core.tools` to adapt the `ManagedIdentityCredential` for compatibility.
```python
from azure.identity import ManagedIdentityCredential
from azure.mgmt.core.tools import AzureIdentityCredentialWrapper
from azure.mgmt.msi import ManagedServiceIdentityClient # Example of a compatible client
import os

credential = ManagedIdentityCredential()
# If an older client requires 'signed_session', wrap the credential:
# wrapped_credential = AzureIdentityCredentialWrapper(credential)

subscription_id = os.getenv("AZURE_SUBSCRIPTION_ID")
if not subscription_id:
    raise ValueError("AZURE_SUBSCRIPTION_ID environment variable not set.")

# Use the credential directly if the client is modern and compatible
client = ManagedServiceIdentityClient(credential=credential, subscription_id=subscription_id)
# Or use the wrapped_credential if the specific client requires it for older versions
# client = SomeOldManagementClient(wrapped_credential, subscription_id)
```
ClientSecretCredential authentication failed: A configuration issue is preventing authentication - check the error message from the server for details. Original exception: AADSTS7000222: The provided client secret keys are expired.
This detailed error message indicates that the client secret provided for `ClientSecretCredential` (used for Service Principal authentication) has expired. Azure Active Directory (AAD) rejects the authentication request due to the invalid secret.
fix
Generate a new client secret for your Azure AD Application (Service Principal) in the Azure portal under 'App registrations' -> 'Certificates & secrets'. Update your application's configuration with the new client secret. Consider using certificate credentials for enhanced security and longer validity.
Upgrade
Version history
7.1.0latest on PyPI · released Jul 21, 2025
Audit
Dependencies
azure-identityrequiredRequired for Azure Active Directory token authentication with `DefaultAzureCredential` and other credential types.
Agent activity
52 hits · last 30 days
node
42
OpenAI (training)
1
Resources