Azure Storage Management Client Library for Python
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.
Warnings
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Install
-
pip install azure-mgmt-storage azure-identity
Imports
- StorageManagementClient
from azure.mgmt.storage import StorageManagementClient
- DefaultAzureCredential
from azure.identity import DefaultAzureCredential
Quickstart
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}")