Azure Storage Common Client Library (Track 1 SDK)

2.1.0 · maintenance · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `CloudStorageAccount` using a connection string. This object is the entry point for interacting with Azure Storage services when using the older Track 1 SDKs (v2.x of `azure-storage-blob`, `azure-storage-queue`, etc.). Ensure your Azure Storage connection string is set in the `AZURE_STORAGE_CONNECTION_STRING` environment variable.

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

view raw JSON →