Azure Storage Management Client Library for Python

24.0.1 · active · verified Sun Mar 29

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

Install

Imports

Quickstart

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

view raw JSON →