Registry / azure / azure-storage-common

azure-storage-common

JSON →
library2.1.0pypypi✓ verified 25d ago

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.

pip install azure-storage-common
INSTALL
IMPORT
SIG · AZURE-STORAGE-COMM
A
azure-storage-common
azurepythonv2.1.0
Install
3.2s avg
Import
440ms
Disk
38MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.462s · 39.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.2s · import 0.418s · 40MB
38MB installed
● package 38MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CloudStorageAccount
from azure.storage.common import CloudStorageAccount
from azure.storage.blob import CloudStorageAccount
CloudStorageAccount is a common utility for Track 1 SDKs; it resides in azure.storage.common, not individual service clients.

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}")
Debug
Known issues
breakingThis 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.
fix
For new projects or migrations, use the Track 2 SDK (e.g., `pip install azure-storage-blob` for v12.x+). Avoid mixing Track 1 and Track 2 in the same application.
affects: All v2.x of `azure-storage-common` and its dependent Track 1 libraries.
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.
fix
Plan migration to the Track 2 SDKs (e.g., `azure-storage-blob` v12.x, `azure-storage-queue` v12.x, etc.) for future-proofing and access to new features.
affects: All v2.x.
gotchaMixing 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.
fix
Standardize on either the Track 1 or Track 2 SDK across your application. Prioritize Track 2 for new development.
affects: All versions.
gotchaThe 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`.
fix
Ensure the connection string exactly matches the format provided by the Azure portal or documented examples. Keys are case-sensitive.
affects: All v2.x.
gotchaThe library requires the Azure Storage connection string to be set, typically via the `AZURE_STORAGE_CONNECTION_STRING` environment variable, for operations that connect to Azure Storage. Failure to set this variable will prevent successful initialization or operation.
fix
Ensure the `AZURE_STORAGE_CONNECTION_STRING` environment variable is correctly set in your environment before running the application. Obtain the connection string from your Azure Storage account in the Azure portal.
affects: All v2.x.
gotchaThe `azure-storage-common` library, particularly when initializing `CloudStorageAccount` without explicit parameters, expects the `AZURE_STORAGE_CONNECTION_STRING` environment variable to be set. Failure to provide this will prevent initialization and raise an error.
fix
Ensure the `AZURE_STORAGE_CONNECTION_STRING` environment variable is properly set in your environment with a valid Azure Storage connection string. Alternatively, pass the connection string directly to the `CloudStorageAccount` constructor or `create_from_connection_string` method.
affects: All v2.x.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'azure.common'
This error typically occurs when the `azure-common` package or the older 'Track 1' Azure SDK packages (like `azure-storage-blob` v2.x) that depend on it are not installed, or when there's a conflict with newer 'Track 2' Azure SDK packages which have a different module structure.
fix
Ensure `azure-common` and the specific `azure-storage-*` v2.x packages you intend to use are installed: `pip install azure-common azure-storage-blob==2.1.0` (adjust version as needed). If you intend to use the newer 'Track 2' SDK, uninstall older packages and install the appropriate v12.x packages, e.g., `pip uninstall azure-common azure-storage-blob` then `pip install azure-storage-blob==12.11.0` or later.
ImportError: cannot import name 'BlockBlobService' from 'azure.storage.blob'
This error arises when code written for the older `azure-storage-blob` v2.x library, which used `BlockBlobService`, attempts to run with the newer `azure-storage-blob` v12.x (or later) installed. The v12.x library introduces new client classes like `BlobServiceClient`, `ContainerClient`, and `BlobClient`, deprecating `BlockBlobService`.
fix
If you need to use the older `BlockBlobService`, explicitly install version 2.1.0 of `azure-storage-blob`: `pip install azure-storage-blob==2.1.0`. If you intend to use the modern SDK, update your code to use `BlobServiceClient` and other v12.x classes: `from azure.storage.blob import BlobServiceClient`.
AttributeError: module 'azure.storage' has no attribute 'BlobService'
This error occurs when attempting to access an outdated class or attribute (`BlobService` in this case) from an `azure.storage` namespace, usually due to a mix of old and new Azure SDK packages being installed, or trying to use 'Track 1' code with a 'Track 2' installation. The structure and class names changed significantly in the v12 SDK.
fix
Verify your installed Azure Storage packages (`pip list | grep azure-storage`). If you have both old (e.g., `azure-storage` or `azure-storage-blob` v2.x) and new (`azure-storage-blob` v12.x) packages, uninstall both and reinstall only the version you intend to use. If targeting v12.x, update your code to use the new client objects such as `BlobServiceClient`, `ContainerClient`, or `BlobClient`.
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. (403 Forbidden)
This common authentication failure often indicates problems with the Shared Access Signature (SAS) token, such as it being expired, having incorrect permissions, or being malformed. It can also be due to an incorrect storage account key or an inactive/deleted storage account.
fix
Double-check the validity and permissions of your SAS token, including its start and expiration times, and the services/resource types/permissions it grants. Regenerate the SAS token if necessary, ensuring it's correctly applied to the URL. Verify the storage account name and access keys are correct and active. For more secure authentication, consider using Azure Identity with managed identities or service principals.
Upgrade
Version history
2.1.0latest on PyPI · released Aug 2, 2019
Audit
Dependencies
azure-commonrequiredProvides core Azure client library utilities.
Agent activity
41 hits · last 30 days
node
38
OpenAI (training)
1
Resources
azure-storage-common — pip install azure-storage-common · libregistry