Azure Storage Namespace Package (Legacy V2 SDK)
The `azure-storage-nspkg` package is an internal Microsoft Azure Storage namespace package, primarily associated with the V2 Python SDK for Azure Storage. This package served to define the `azure.storage` namespace, allowing older client libraries like `azure-storage-blob` (versions < 3), `azure-storage-file`, and `azure-storage-queue` to be imported under this common prefix. The V2 SDK is deprecated; users should migrate to the V12 SDK, which uses separate, hyphenated packages (e.g., `azure-storage-blob` version 12.x.x) and does not require or use `azure-storage-nspkg`.
Warnings
- breaking The Azure Storage SDK for Python has undergone a major redesign from V2 to V12. The V12 SDK introduces a completely new API surface, different package names (e.g., `azure-storage-blob` for V12 vs. `azure-storage-blob` for V2, but with different major version numbers), and improved idiomatic Python design. Code written for V2 will not work with V12 without significant refactoring.
- deprecated The `azure-storage-nspkg` package and the V2 Azure Storage SDK it supported are deprecated. Microsoft recommends using the V12 SDK for all new development and migrating existing applications.
- gotcha The package name `azure-storage-blob` exists for both the legacy V2 SDK (versions < 3) and the current V12 SDK (versions >= 12). Installing `pip install azure-storage-blob` without specifying a version might lead to installing the V12 SDK, but if `azure-storage-nspkg` (or other V2 dependencies) is already present, version conflicts or unexpected behavior can occur if you intend to use V2.
Install
-
pip install azure-storage-nspkg -
pip install azure-storage-blob azure-storage-file-share azure-storage-queue
Imports
- BlockBlobService
from azure.storage.blob import BlockBlobService
- BlobServiceClient
from azure.storage.blob import BlobServiceClient
Quickstart
import os
from azure.storage.blob import BlobServiceClient
connection_string = os.environ.get('AZURE_STORAGE_CONNECTION_STRING', 'DefaultEndpointsProtocol=https;AccountName=youraccount;AccountKey=yourkey;EndpointSuffix=core.windows.net')
try:
# Create the BlobServiceClient object which will be used to create a container client
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
# Create a unique name for the container
container_name = 'quickstart-container-12345'
# Create the container if it doesn't exist
try:
container_client = blob_service_client.create_container(container_name)
print(f"Container '{container_name}' created successfully.")
except Exception as e:
print(f"Container '{container_name}' already exists or another error: {e}")
container_client = blob_service_client.get_container_client(container_name)
# Example: List blobs in the container
print("Listing blobs...")
blob_list = container_client.list_blobs()
for blob in blob_list:
print(f"\t{blob.name}")
except ValueError as e:
print(f"Error: {e}. Please ensure AZURE_STORAGE_CONNECTION_STRING is set or configured correctly.")
except Exception as e:
print(f"An unexpected error occurred: {e}")