or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

async-operations.mdblob-client.mdblob-types-tiers.mdcontainer-client.mdindex.mdsas-generation.mdservice-client.mdutility-functions.md
tile.json

tessl/pypi-azure-storage-blob

Microsoft Azure Blob Storage Client Library for Python providing comprehensive APIs for blob storage operations.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/azure-storage-blob@12.26.x

To install, run

npx @tessl/cli install tessl/pypi-azure-storage-blob@12.26.0

index.mddocs/

Azure Storage Blob

A comprehensive Python client library for Azure Blob Storage, Microsoft's object storage solution for storing massive amounts of unstructured data. The library provides rich APIs for managing storage accounts, containers, and blobs with support for various blob types, authentication methods, and both synchronous and asynchronous operations.

Package Information

  • Package Name: azure-storage-blob
  • Language: Python
  • Installation: pip install azure-storage-blob
  • Optional Async Support: pip install azure-storage-blob[aio]

Core Imports

from azure.storage.blob import BlobServiceClient, ContainerClient, BlobClient

Common imports:

from azure.storage.blob import (
    BlobServiceClient,
    ContainerClient, 
    BlobClient,
    BlobType,
    StandardBlobTier,
    generate_blob_sas,
    upload_blob_to_url,
    download_blob_from_url
)

Async imports:

from azure.storage.blob.aio import BlobServiceClient, ContainerClient, BlobClient

Basic Usage

from azure.storage.blob import BlobServiceClient

# Create service client with connection string
client = BlobServiceClient.from_connection_string("your_connection_string")

# Create a container
container_client = client.create_container("my-container")

# Upload a blob using the container client
with open("local-file.txt", "rb") as data:
    blob_client = container_client.upload_blob(
        name="uploaded-file.txt", 
        data=data
    )

# Download a blob
blob_client = client.get_blob_client(container="my-container", blob="uploaded-file.txt")
with open("downloaded-file.txt", "wb") as download_file:
    download_file.write(blob_client.download_blob().readall())

# List containers
for container in client.list_containers():
    print(f"Container: {container.name}")

Architecture

Azure Storage Blob organizes data in a three-tier hierarchy:

  • Account: Top-level namespace with global settings, service properties, and authentication
  • Container: Logical grouping similar to a filesystem directory, with access policies and metadata
  • Blob: Individual data objects of three types (Block, Page, Append) with properties and metadata

The client library mirrors this hierarchy with corresponding client classes:

  • BlobServiceClient: Account-level operations, container management, service configuration
  • ContainerClient: Container-level operations, blob management within a container
  • BlobClient: Individual blob operations, data upload/download, metadata management

All clients support multiple authentication methods (connection strings, account keys, SAS tokens, Azure AD) and provide both synchronous and asynchronous APIs for integration with various application architectures.

Capabilities

Service Client Operations

Account-level operations including authentication, service configuration, container management, and cross-container blob queries. The BlobServiceClient provides the main entry point for interacting with Azure Blob Storage.

class BlobServiceClient:
    def __init__(self, account_url: str, credential=None, **kwargs): ...
    def from_connection_string(cls, conn_str: str, credential=None, **kwargs) -> BlobServiceClient: ...
    def get_service_properties(self, **kwargs): ...
    def set_service_properties(self, analytics_logging=None, hour_metrics=None, minute_metrics=None, cors=None, target_version=None, delete_retention_policy=None, static_website=None, **kwargs): ...
    def list_containers(self, name_starts_with=None, include_metadata=False, **kwargs): ...
    def create_container(self, name: str, metadata=None, public_access=None, **kwargs): ...
    def delete_container(self, container: str, **kwargs): ...
    def get_container_client(self, container: str) -> ContainerClient: ...
    def get_blob_client(self, container: str, blob: str, snapshot=None) -> BlobClient: ...

Service Client Operations

Container Management

Container-level operations including creation, deletion, property management, access control, and blob listing. ContainerClient provides comprehensive container management capabilities.

class ContainerClient:
    def __init__(self, account_url: str, container_name: str, credential=None, **kwargs): ...
    def from_container_url(cls, container_url: str, credential=None, **kwargs) -> ContainerClient: ...
    def create_container(self, metadata=None, public_access=None, **kwargs): ...
    def delete_container(self, **kwargs): ...
    def get_container_properties(self, **kwargs): ...
    def set_container_metadata(self, metadata=None, **kwargs): ...
    def list_blobs(self, name_starts_with=None, include=None, **kwargs): ...
    def upload_blob(self, name: str, data, blob_type=BlobType.BLOCKBLOB, **kwargs): ...
    def download_blob(self, blob: str, offset=None, length=None, **kwargs): ...
    def delete_blob(self, blob: str, delete_snapshots=None, **kwargs): ...

Container Management

Blob Operations

Individual blob operations including upload, download, properties management, and blob-type specific operations. BlobClient provides comprehensive blob management for all blob types.

class BlobClient:
    def __init__(self, account_url: str, container_name: str, blob_name: str, snapshot=None, credential=None, **kwargs): ...
    def from_blob_url(cls, blob_url: str, credential=None, **kwargs) -> BlobClient: ...
    def upload_blob(self, data, blob_type=BlobType.BLOCKBLOB, **kwargs): ...
    def download_blob(self, offset=None, length=None, **kwargs) -> StorageStreamDownloader: ...
    def delete_blob(self, delete_snapshots=None, **kwargs): ...
    def get_blob_properties(self, **kwargs): ...
    def set_blob_metadata(self, metadata=None, **kwargs): ...
    def create_snapshot(self, **kwargs): ...
    def start_copy_from_url(self, source_url: str, **kwargs): ...

Blob Operations

Shared Access Signatures

Generate time-limited, secure access tokens for Azure Storage resources without exposing account keys. SAS tokens enable granular permission control for external access.

def generate_account_sas(account_name: str, account_key: str, resource_types, permission, expiry, start=None, ip=None, protocol=None, **kwargs) -> str: ...
def generate_container_sas(account_name: str, container_name: str, account_key=None, user_delegation_key=None, permission=None, expiry=None, start=None, policy_id=None, ip=None, protocol=None, **kwargs) -> str: ...
def generate_blob_sas(account_name: str, container_name: str, blob_name: str, snapshot=None, version_id=None, account_key=None, user_delegation_key=None, permission=None, expiry=None, start=None, policy_id=None, ip=None, protocol=None, **kwargs) -> str: ...

Shared Access Signatures

Blob Types and Storage Tiers

Azure Blob Storage supports three blob types optimized for different scenarios, along with access tiers for cost optimization. Each blob type provides specific capabilities for different data patterns.

class BlobType:
    BLOCKBLOB: str
    PAGEBLOB: str  
    APPENDBLOB: str

class StandardBlobTier:
    HOT: str
    COOL: str
    COLD: str
    ARCHIVE: str

class PremiumPageBlobTier:
    P4: str
    P6: str
    P10: str
    P15: str
    P20: str
    P30: str
    P40: str
    P50: str
    P60: str

Blob Types and Storage Tiers

Async Operations

Asynchronous versions of all client classes for high-performance, concurrent operations. The async clients provide identical APIs with async/await patterns for scalable applications.

# All async clients have the same methods as sync versions but with async/await
from azure.storage.blob.aio import BlobServiceClient, ContainerClient, BlobClient

async def example():
    async with BlobServiceClient.from_connection_string(conn_str) as client:
        async for container in client.list_containers():
            print(container.name)

Async Operations

Utility Functions

Convenient helper functions for common blob operations without requiring client instantiation. These functions provide simplified access for basic upload and download scenarios.

def upload_blob_to_url(blob_url: str, data, credential=None, **kwargs) -> dict: ...
def download_blob_from_url(blob_url: str, output, credential=None, **kwargs) -> None: ...

Utility Functions

Data Models

Core Data Types

class BlobProperties:
    """Comprehensive blob properties and metadata."""
    name: str
    container: str
    snapshot: str
    blob_type: BlobType
    last_modified: datetime
    etag: str
    size: int
    content_type: str
    content_encoding: str
    content_language: str
    content_disposition: str
    cache_control: str
    content_md5: bytes
    metadata: dict
    lease: LeaseProperties
    copy: CopyProperties
    creation_time: datetime
    archive_status: str
    rehydrate_priority: str
    encryption_key_sha256: str
    encryption_scope: str
    request_server_encrypted: bool
    object_replication_source_properties: list
    object_replication_destination_policy: str
    tag_count: int
    tags: dict
    immutability_policy: ImmutabilityPolicy
    has_legal_hold: bool
    has_versions_only: bool

class ContainerProperties:
    """Container metadata and properties."""
    name: str
    last_modified: datetime
    etag: str
    lease: LeaseProperties
    public_access: PublicAccess
    has_immutability_policy: bool
    deleted: bool
    version: str
    has_legal_hold: bool
    metadata: dict
    encryption_scope: ContainerEncryptionScope
    immutable_storage_with_versioning_enabled: bool

class StorageStreamDownloader:
    """Streaming download with iteration support."""
    def readall(self) -> bytes: ...
    def readinto(self, stream) -> int: ...
    def download_to_stream(self, stream) -> None: ...
    def chunks(self) -> Iterator[bytes]: ...
    def content_as_bytes(self) -> bytes: ...
    def content_as_text(self, encoding: str = 'utf-8') -> str: ...