Azure Storage Management Client Library for Python

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

The `azure-mgmt-storage` library is the Microsoft Azure Storage Management Client Library for Python, part of the Azure SDK. It enables programmatic management of Azure Storage resources, including creating, updating, and deleting storage accounts, blob containers, file shares, queues, and retrieving access keys. It focuses on the management plane operations for Azure Storage. The library is currently at version 24.0.1 and follows an active release cadence with regular updates and improvements.

pip install azure-mgmt-storage azure-identity
error ModuleNotFoundError: No module named 'azure.mgmt.storage'
cause This error occurs when the `azure-mgmt-storage` package is not installed in your Python environment or is not accessible within the current Python path.
fix
Ensure the package is correctly installed using pip: pip install azure-mgmt-storage
error (SubscriptionNotFound) The subscription 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' could not be found.
cause This error indicates that the provided subscription ID is either incorrect, you do not have access to it, or your current authentication context is not set to the correct Azure subscription.
fix
Verify the subscription ID is correct and you have the necessary permissions. Ensure your Azure CLI or environment variables (AZURE_SUBSCRIPTION_ID) are set to the correct subscription, or explicitly pass the correct subscription_id to the StorageManagementClient constructor after authenticating. You might need to log in to Azure CLI (az login) and set the active subscription (az account set --subscription <your_subscription_id>).
error (ResourceGroupNotFound) Resource group 'my-resource-group' could not be found.
cause This error means that the specified Azure Resource Group does not exist in the selected subscription or is misspelled.
fix
Check for typos in the resource group name. Confirm the resource group exists in the Azure portal or via Azure CLI (az group show --name my-resource-group --subscription <your_subscription_id>). If it doesn't exist, create it before attempting to manage resources within it.
error (StorageAccountNotFound) The storage account 'myuniquestorageaccount' was not found.
cause This error occurs when the storage account with the given name does not exist in the specified resource group and subscription, or your identity lacks permission to view it.
fix
Verify the storage account name and the resource group name are correct. Ensure the storage account exists and is accessible to the authenticated principal in the specified subscription. Check permissions (e.g., 'Storage Account Contributor' role).
error TypeError: __init__() takes exactly 1 argument (2 given)
cause This typically occurs with older versions of `azure-mgmt-storage` (pre-2.x) when model classes (like `Sku`, `StorageAccountCreateParameters`) were updated to use keyword-only arguments instead of positional arguments, causing a mismatch if you're passing values positionally.
fix
Update your code to pass all arguments to model constructors using keyword arguments (e.g., Sku(name="Standard_RAGRS") instead of Sku("Standard_RAGRS")). Consider upgrading azure-mgmt-storage to a newer version if you are on a very old one.
breaking The credential system was completely revamped. Old `azure.common.credentials` or `msrestazure.azure_active_directory` instances are no longer supported. Users must migrate to `azure-identity` classes (e.g., `DefaultAzureCredential`). Additionally, the `credentials` parameter was renamed to `credential` in client constructors.
fix Replace legacy credential imports and objects with classes from `azure.identity`. Update client constructor parameter from `credentials` to `credential`.
breaking The `StorageManagementClient` can no longer be imported from `azure.mgmt.storage.storage_management_client`. It must be imported directly from the top-level `azure.mgmt.storage` package.
fix Change import statement from `from azure.mgmt.storage.storage_management_client import StorageManagementClient` to `from azure.mgmt.storage import StorageManagementClient`.
breaking As of v24.0.0, the package primarily targets only the *latest* API-Version available on Azure, removing APIs of other versions. If your application relies on a specific older (non-latest) API-Version, it is recommended to pin the `azure-mgmt-storage` package to a previous major version that supported that API.
fix For applications requiring a specific, non-latest API version, explicitly pin the `azure-mgmt-storage` package to a previous version (e.g., `azure-mgmt-storage==21.2.1` for API version '2023-05-01') in your `requirements.txt` or `setup.py`.
gotcha This library (`azure-mgmt-storage`) is for *management plane* operations (e.g., creating storage accounts, managing keys, policies). For *data plane* operations (e.g., uploading blobs, reading files, sending queue messages), you need the specific data client libraries like `azure-storage-blob`, `azure-storage-file-share`, `azure-storage-queue`, etc.
fix Ensure you are using the correct library for your task: `azure-mgmt-storage` for management and `azure-storage-*` libraries for data operations.
gotcha Users upgrading to the latest beta or even some generally available versions of the Azure Storage SDKs (including management libraries) might encounter `InvalidHeaderValue` error messages in rare scenarios. This could be due to internal SDK changes.
fix If this issue occurs, downgrade to the previous generally available version of the SDK to see if it resolves. If the problem persists or downgrading is not feasible, open a support ticket with Microsoft.
gotcha Newer API versions, which the `azure-mgmt-storage` package now targets by default, might not be immediately available in all Azure regions, particularly in sovereign clouds like Azure China. This can lead to deployment failures if trying to use the latest API version in an unsupported region.
fix Check the Azure documentation for API version availability in your target region. If the latest API is not supported, pin `azure-mgmt-storage` to an older package version that uses a supported API version for your region.
gotcha The `AZURE_SUBSCRIPTION_ID` environment variable is required by many Azure management SDKs to identify the target subscription for operations. If not set, operations may fail or prompt for this variable.
fix Ensure the `AZURE_SUBSCRIPTION_ID` environment variable is set in your environment (e.g., `export AZURE_SUBSCRIPTION_ID="<your-subscription-id>"` on Linux/macOS or `$env:AZURE_SUBSCRIPTION_ID="<your-subscription-id>"` on PowerShell) before running your application.
gotcha Azure management clients require the `AZURE_SUBSCRIPTION_ID` environment variable to be set to identify the target subscription for operations. Failure to set this variable will result in runtime errors.
fix Ensure the `AZURE_SUBSCRIPTION_ID` environment variable is set in your environment with a valid Azure subscription ID before initializing and using Azure management clients.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.49s 46.0M
3.10 alpine (musl) - - 0.49s 44.9M
3.10 slim (glibc) wheel 3.9s 0.35s 46M
3.10 slim (glibc) - - 0.33s 45M
3.11 alpine (musl) wheel - 0.67s 50.0M
3.11 alpine (musl) - - 0.73s 48.8M
3.11 slim (glibc) wheel 3.8s 0.59s 50M
3.11 slim (glibc) - - 0.55s 49M
3.12 alpine (musl) wheel - 0.84s 41.4M
3.12 alpine (musl) - - 0.87s 40.3M
3.12 slim (glibc) wheel 3.3s 0.78s 42M
3.12 slim (glibc) - - 0.79s 41M
3.13 alpine (musl) wheel - 0.83s 41.1M
3.13 alpine (musl) - - 0.84s 39.8M
3.13 slim (glibc) wheel 3.4s 0.78s 41M
3.13 slim (glibc) - - 0.82s 40M
3.9 alpine (musl) wheel - 0.47s 46.0M
3.9 alpine (musl) - - 0.48s 45.0M
3.9 slim (glibc) wheel 4.4s 0.45s 46M
3.9 slim (glibc) - - 0.46s 45M

This quickstart demonstrates how to initialize the `StorageManagementClient` using `DefaultAzureCredential` for authentication and then list all storage accounts within your Azure subscription. Ensure you have the `AZURE_SUBSCRIPTION_ID` environment variable set, and authenticate via Azure CLI (`az login`) or by setting service principal environment variables (`AZURE_CLIENT_ID`, `AZURE_TENANT_ID`, `AZURE_CLIENT_SECRET`).

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.storage import StorageManagementClient

# Set environment variables for authentication and subscription
# AZURE_SUBSCRIPTION_ID
# AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET (for Service Principal)
# Or use 'az login' for Azure CLI credential

try:
    subscription_id = os.environ['AZURE_SUBSCRIPTION_ID']
except KeyError:
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
    exit(1)

# Acquire a credential object
credential = DefaultAzureCredential()

# Initialize the Storage Management client
storage_client = StorageManagementClient(credential, subscription_id)

# List all storage accounts in the subscription
print("Listing storage accounts...")
for account in storage_client.storage_accounts.list():
    print(f"  Name: {account.name}, Location: {account.location}")