Simple Azure Blob Downloader
simple-azure-blob-downloader is a Python library designed to simplify the process of downloading blobs from Azure Blob Storage. It provides a straightforward interface, acting as a wrapper around the official Azure Storage Blob client library. As of version 0.1.0, it offers basic download functionality.
Common errors
-
azure.core.exceptions.ResourceNotFoundError: The specified container does not exist.
cause The Azure Blob Storage container specified in `container_name` does not exist in the provided storage account, or the credentials do not have permission to access it.fixVerify that `container_name` is correct and the storage account connection string has the necessary permissions (e.g., 'Storage Blob Data Reader' role or appropriate SAS token) to access the container. -
azure.core.exceptions.ResourceNotFoundError: The specified blob does not exist.
cause The blob specified by `blob_name` was not found within the designated Azure container.fixDouble-check the `blob_name` for typos, including case sensitivity and correct pathing if the blob is in a virtual directory. Ensure the blob actually exists in the specified container. -
azure.core.exceptions.ClientAuthenticationError: Authentication failed, content: '...
cause The provided `AZURE_STORAGE_CONNECTION_STRING` is incorrect, malformed, or lacks the necessary permissions to perform the download operation.fixVerify the `AZURE_STORAGE_CONNECTION_STRING` is correct. Ensure it includes the `AccountName` and `AccountKey`, or is a valid Shared Access Signature (SAS) token with read permissions for the target container and blobs.
Warnings
- gotcha The library is a wrapper around `azure-storage-blob`. For advanced features or debugging, understanding the underlying Azure SDK documentation is beneficial, as this library provides a simplified interface for common download operations.
- gotcha Direct error handling from `simple-azure-blob-downloader` might be limited. Errors originating from the underlying `azure-storage-blob` library will be propagated, requiring familiarity with its exception types (e.g., `ResourceNotFoundError` for missing blobs or containers) for robust error management.
Install
-
pip install simple-azure-blob-downloader
Imports
- download_blob
from simple_azure_blob_downloader import download_blob
Quickstart
import os
from simple_azure_blob_downloader import download_blob
# Set environment variables for secure access
# AZURE_STORAGE_CONNECTION_STRING should be your storage account's connection string
# e.g., 'DefaultEndpointsProtocol=https;AccountName=youraccount;AccountKey=yourkey;EndpointSuffix=core.windows.net'
connection_string = os.environ.get('AZURE_STORAGE_CONNECTION_STRING', 'YOUR_AZURE_STORAGE_CONNECTION_STRING')
container_name = os.environ.get('AZURE_BLOB_CONTAINER_NAME', 'my-container')
blob_name = os.environ.get('AZURE_BLOB_NAME', 'my-file.txt')
local_destination_path = os.environ.get('LOCAL_DOWNLOAD_PATH', 'downloaded_file.txt')
if connection_string == 'YOUR_AZURE_STORAGE_CONNECTION_STRING':
print("Please set the AZURE_STORAGE_CONNECTION_STRING environment variable or replace the placeholder.")
else:
try:
# Download a single blob
download_blob(connection_string, container_name, blob_name, local_destination_path)
print(f"Successfully downloaded '{blob_name}' to '{local_destination_path}'.")
except Exception as e:
print(f"An error occurred: {e}")