Azure Storage Common Client Library (Track 1 SDK)
The `azure-storage-common` library provides common functionalities and utilities shared across the older Microsoft Azure Storage 'Track 1' client libraries for Python (e.g., `azure-storage-blob` v2.x, `azure-storage-queue` v2.x). It includes classes for managing storage accounts, shared access signatures, and handling exceptions. The current version is 2.1.0, with releases historically tied to new Azure Storage REST API versions, though it is now largely in maintenance mode.
Warnings
- breaking This library (`azure-storage-common` v2.x) is part of the older 'Track 1' Azure SDK for Python. The newer, recommended 'Track 2' SDK (e.g., `azure-storage-blob` v12.x+, `azure-storage-queue` v12.x+) does NOT use `azure-storage-common`. Migrating from Track 1 to Track 2 requires substantial code changes and a complete re-import strategy.
- deprecated `azure-storage-common` is in maintenance mode for the Track 1 SDK. No new features are being added; only critical bug fixes are provided. For new development, it is highly recommended to use the Track 2 SDKs for Azure Storage.
- gotcha Mixing Track 1 (`azure-storage-common` and its dependent v2.x libraries) with Track 2 (e.g., `azure-storage-blob` v12.x+) within the same application is highly discouraged and can lead to dependency conflicts, unexpected behavior, and increased bundle size.
- gotcha The connection string format expected by `CloudStorageAccount.create_from_connection_string` is specific, requiring keys like `AccountName`, `AccountKey`, `DefaultEndpointsProtocol`, and `EndpointSuffix`. Incorrectly formatted strings will raise a `ValueError`.
Install
-
pip install azure-storage-common
Imports
- CloudStorageAccount
from azure.storage.common import CloudStorageAccount
Quickstart
import os
from azure.storage.common import CloudStorageAccount
# Retrieve the connection string from an environment variable.
# Example: AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;AccountName=youraccount;AccountKey=yourkey;EndpointSuffix=core.windows.net"
connection_string = os.environ.get("AZURE_STORAGE_CONNECTION_STRING", "")
if not connection_string:
print("Please set the AZURE_STORAGE_CONNECTION_STRING environment variable.")
else:
try:
# Create a CloudStorageAccount object from the connection string
# This object is then used to create specific service clients (e.g., blob, queue, file).
account = CloudStorageAccount.create_from_connection_string(connection_string)
print(f"Successfully created CloudStorageAccount for: {account.account_name}")
print("This library provides common utilities for the Azure Storage Track 1 SDK (v2.x).")
print("To perform storage operations, you would typically use this 'account' object")
print("to instantiate a service client from another Track 1 library (e.g., azure-storage-blob v2.x).")
# Example of how you would use it with azure-storage-blob v2.x (if installed):
# from azure.storage.blob import BlockBlobService
# block_blob_service = account.create_block_blob_service()
# print(f"BlockBlobService created successfully using account: {block_blob_service.account_name}")
except ValueError as e:
print(f"Error creating storage account: {e}")
print("Please ensure the AZURE_STORAGE_CONNECTION_STRING format is correct.")
except Exception as e:
print(f"An unexpected error occurred: {e}")