Install & Compatibility
Where this runs
tested against v? · 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
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BlockBlobService
✓ from azure.storage.blob.baseblobservice import BaseBlobService
# Note: This is for the legacy azure-storage package (v0.x).
# For new development, use BlobServiceClient from azure-storage-blob (v12.x+).
✗ from azure.storage.blob import BlobServiceClient
BlockBlobService is from the legacy package; BlobServiceClient is the modern equivalent but from a different package (`azure-storage-blob`). Do not mix them or assume direct compatibility.
BlobServiceClient
✓ from azure.storage.blob import BlobServiceClient
✗ from azure.storage import BlobServiceClient
BlobServiceClient is part of the modern `azure-storage-blob` package, not the legacy `azure-storage` package (v0.x).
This quickstart demonstrates how to use the *modern* `azure-storage-blob` library (v12.x+) for interacting with Azure Blob Storage. This is the recommended approach for all new development. It shows container creation, blob upload, listing, and download using either a connection string or `DefaultAzureCredential` for authentication. Remember to install `azure-storage-blob` and `azure-identity`.
import os
from azure.identity import DefaultAzureCredential
from azure.storage.blob import BlobServiceClient
# Recommended: Use the modern azure-storage-blob package
# Ensure AZURE_STORAGE_CONNECTION_STRING or AZURE_STORAGE_ACCOUNT_NAME is set
# Or configure Azure Identity credentials for DefaultAzureCredential
try:
# Option 1: Using connection string (simpler for quickstart)
connection_string = os.environ.get('AZURE_STORAGE_CONNECTION_STRING')
if connection_string:
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
else:
# Option 2: Using DefaultAzureCredential (recommended for production)
account_url = os.environ.get('AZURE_STORAGE_ACCOUNT_URL', 'https://<your_account_name>.blob.core.windows.net')
if not account_url.startswith('https://') and 'AZURE_STORAGE_ACCOUNT_NAME' in os.environ:
account_name = os.environ['AZURE_STORAGE_ACCOUNT_NAME']
account_url = f'https://{account_name}.blob.core.windows.net'
credential = DefaultAzureCredential()
blob_service_client = BlobServiceClient(account_url, credential=credential)
container_name = 'mytestcontainer'
blob_name = 'mytestblob.txt'
local_file_name = 'sample.txt'
data = 'Hello, Azure Blob Storage!'
print(f"Creating container: {container_name}")
container_client = blob_service_client.get_container_client(container_name)
try:
container_client.create_container()
except Exception as e:
if 'ContainerAlreadyExists' not in str(e):
raise
print(f"Container '{container_name}' already exists.")
with open(local_file_name, 'w') as file:
file.write(data)
print(f"Uploading blob: {blob_name}")
with open(local_file_name, 'rb') as data_file:
container_client.upload_blob(name=blob_name, data=data_file, overwrite=True)
print(f"Listing blobs in '{container_name}':")
for blob in container_client.list_blobs():
print(f" - {blob.name}")
print(f"Downloading blob: {blob_name}")
download_blob_client = container_client.get_blob_client(blob_name)
download_data = download_blob_client.download_blob().readall()
print(f"Downloaded content: {download_data.decode('utf-8')}")
# Clean up
# print(f"Deleting blob: {blob_name}")
# container_client.delete_blob(blob_name)
# print(f"Deleting container: {container_name}")
# container_client.delete_container()
except Exception as ex:
print(f"Error: {ex}")
print("Please ensure environment variables (AZURE_STORAGE_CONNECTION_STRING or AZURE_STORAGE_ACCOUNT_URL/NAME and Azure Identity vars) are set correctly.")
Debug
Known issues
breakingThe `azure-storage` package (v0.x) has been entirely superseded by the modular client libraries (`azure-storage-blob`, `azure-storage-queue`, `azure-storage-file-share`, all v12.x+). There is no direct upgrade path; code written for `azure-storage` will require a complete rewrite to use the new client libraries due to different class names, API signatures, and object models.fixMigrate to `azure-storage-blob` (for blobs), `azure-storage-queue` (for queues), and `azure-storage-file-share` (for files). Review Microsoft's migration guides for detailed instructions.
affects: 0.1.0 - 0.37.0
deprecatedThe `azure-storage` package itself is deprecated and no longer receives active development or new features. Using it for new projects is strongly discouraged.fixAlways use the modern, modular Azure Storage SDKs (e.g., `azure-storage-blob` v12.x+) for new development. For existing projects, plan a migration to the newer libraries.
affects: 0.1.0 - 0.37.0
gotchaAuthentication methods and client initialization patterns are completely different between the legacy `azure-storage` (v0.x) and the modern modular SDKs (v12.x+). The modern SDKs leverage `azure-identity` for robust, token-based authentication (e.g., `DefaultAzureCredential`), alongside connection strings or SAS tokens.fixFamiliarize yourself with the authentication mechanisms of the modern SDKs, prioritizing `DefaultAzureCredential` for production environments and connection strings for development ease. Install `azure-identity` for credential management.
affects: All versions of `azure-storage` (v0.x) vs `azure-storage-blob` (v12.x+)
gotchaThe Python Azure SDK underwent a complete redesign in its V2 efforts, resulting in entirely new client classes and method names. For instance, `BlockBlobService` from `azure-storage` is replaced by `BlobServiceClient`, `ContainerClient`, and `BlobClient` in `azure-storage-blob`.fixRefer to the official documentation for the modern `azure-storage-blob` (or `queue`, `file-share`) packages to understand the new API structure and client hierarchy.
affects: All versions of `azure-storage` (v0.x) vs `azure-storage-blob` (v12.x+)
Upgrade
Version history
0.37.0latest on PyPI · released May 11, 2020
Audit
Dependencies
No dependency data recorded yet.