azure.storage.blob.aio package

class azure.storage.blob.aio.BlobServiceClient(account_url: str, credential: Optional[Any] = None, **kwargs: Any)[source]

A client to interact with the Blob Service at the account level.

This client provides operations to retrieve and configure the account properties as well as list, create and delete containers within the account. For operations relating to a specific container or blob, clients for those entities can also be retrieved using the get_client functions.

Parameters
  • account_url (str) – The URL to the blob storage account. Any other entities included in the URL path (e.g. container or blob) will be discarded. This URL can be optionally authenticated with a SAS token.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the URL already has a SAS token, specifying an explicit credential will take priority.

Keyword Arguments
  • api_version (str) –

    The Storage API version to use for requests. Default value is ‘2019-07-07’. Setting to an older version may result in reduced feature compatibility.

    New in version 12.2.0.

  • secondary_hostname (str) – The hostname of the secondary endpoint.

  • max_block_size (int) – The maximum chunk size for uploading a block blob in chunks. Defaults to 4*1024*1024, or 4MB.

  • max_single_put_size (int) – If the blob size is less than or equal max_single_put_size, then the blob will be uploaded with only one http PUT request. If the blob size is larger than max_single_put_size, the blob will be uploaded in chunks. Defaults to 64*1024*1024, or 64MB.

  • min_large_block_upload_threshold (int) – The minimum chunk size required to use the memory efficient algorithm when uploading a block blob. Defaults to 4*1024*1024+1.

  • use_byte_buffer (bool) – Use a byte buffer for block blob uploads. Defaults to False.

  • max_page_size (int) – The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024, or 4MB.

  • max_single_get_size (int) – The maximum size for a blob to be downloaded in a single call, the exceeded part will be downloaded in chunks (could be parallel). Defaults to 32*1024*1024, or 32MB.

  • max_chunk_get_size (int) – The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024, or 4MB.

Example:

Creating the BlobServiceClient with account url and credential.
from azure.storage.blob.aio import BlobServiceClient
blob_service_client = BlobServiceClient(account_url=self.url, credential=self.shared_access_key)
Creating the BlobServiceClient with Azure Identity credentials.
# Get a token credential for authentication
from azure.identity.aio import ClientSecretCredential
token_credential = ClientSecretCredential(self.active_directory_tenant_id, self.active_directory_application_id,
                                          self.active_directory_application_secret)

# Instantiate a BlobServiceClient using a token credential
from azure.storage.blob.aio import BlobServiceClient
blob_service_client = BlobServiceClient(account_url=self.oauth_url, credential=token_credential)
async close()

This method is to close the sockets opened by the client. It need not be used when using with a context manager.

async create_container(name: str, metadata: Optional[Dict[str, str]] = None, public_access: Optional[Union[PublicAccess, str]] = None, **kwargs) → ContainerClient[source]

Creates a new container under the specified account.

If the container with the same name already exists, a ResourceExistsError will be raised. This method returns a client with which to interact with the newly created container.

Parameters
  • name (str) – The name of the container to create.

  • metadata (dict(str, str)) – A dict with name-value pairs to associate with the container as metadata. Example: {‘Category’:’test’}

  • public_access (str or PublicAccess) – Possible values include: ‘container’, ‘blob’.

Keyword Arguments
  • container_encryption_scope (dict or ContainerEncryptionScope) –

    Specifies the default encryption scope to set on the container and use for all future writes.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Return type

ContainerClient

Example:

Creating a container in the blob service.
try:
    new_container = await blob_service_client.create_container("containerfromblobserviceasync")
    properties = await new_container.get_container_properties()
except ResourceExistsError:
    print("Container already exists.")
async delete_container(container: Union[ContainerProperties, str], lease: Optional[Union[BlobLeaseClient, str]] = None, **kwargs)None[source]

Marks the specified container for deletion.

The container and any blobs contained within it are later deleted during garbage collection. If the container is not found, a ResourceNotFoundError will be raised.

Parameters
  • container (str or ContainerProperties) – The container to delete. This can either be the name of the container, or an instance of ContainerProperties.

  • lease – If specified, delete_container only succeeds if the container’s lease is active and matches this ID. Required if the container has an active lease.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

  • timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example:

Deleting a container in the blob service.
# Delete container if it exists
try:
    await blob_service_client.delete_container("containerfromblobserviceasync")
except ResourceNotFoundError:
    print("Container already deleted.")
find_blobs_by_tags(filter_expression: str, **kwargs: Any) → AsyncItemPaged[FilteredBlob][source]

The Filter Blobs operation enables callers to list blobs across all containers whose tags match a given search expression. Filter blobs searches across all containers within a storage account but can be scoped within the expression to a single container.

Parameters

filter_expression (str) – The expression to find blobs whose tags matches the specified condition. eg. “”yourtagname”=’firsttag’ and “yourtagname2”=’secondtag’” To specify a container, eg. “@container=’containerName’ and “Name”=’C’”

Keyword Arguments
  • results_per_page (int) – The max result per page when paginating.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

An iterable (auto-paging) response of BlobProperties.

Return type

AsyncItemPaged[FilteredBlob]

classmethod from_connection_string(conn_str: str, credential: Optional[Any] = None, **kwargs: Any) → azure.storage.blob._blob_service_client.BlobServiceClient[source]

Create BlobServiceClient from a Connection String.

Parameters
  • conn_str (str) – A connection string to an Azure Storage account.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.

Returns

A Blob service client.

Return type

BlobServiceClient

Example:

Creating the BlobServiceClient from a connection string.
from azure.storage.blob import BlobServiceClient
blob_service_client = BlobServiceClient.from_connection_string(self.connection_string)
async get_account_information(**kwargs: Any) → Dict[str, str][source]

Gets information related to the storage account.

The information can also be retrieved if the user has a SAS to a container or blob. The keys in the returned dictionary include ‘sku_name’ and ‘account_kind’.

Returns

A dict of account information (SKU and account type).

Return type

dict(str, str)

Example:

Getting account information for the blob service.
account_info = await blob_service_client.get_account_information()
print('Using Storage SKU: {}'.format(account_info['sku_name']))
get_blob_client(container: Union[ContainerProperties, str], blob: Union[BlobProperties, str], snapshot: Optional[Union[Dict[str, Any], str]] = None) → BlobClient[source]

Get a client to interact with the specified blob.

The blob need not already exist.

Parameters
  • container (str or ContainerProperties) – The container that the blob is in. This can either be the name of the container, or an instance of ContainerProperties.

  • blob (str or BlobProperties) – The blob with which to interact. This can either be the name of the blob, or an instance of BlobProperties.

  • snapshot (str or dict(str, Any)) – The optional blob snapshot on which to operate. This can either be the ID of the snapshot, or a dictionary output returned by create_snapshot().

Returns

A BlobClient.

Return type

BlobClient

Example:

Getting the blob client to interact with a specific blob.
blob_client = blob_service_client.get_blob_client(container="containertestasync", blob="my_blob")
try:
    stream = await blob_client.download_blob()
except ResourceNotFoundError:
    print("No blob found.")
get_container_client(container: Union[azure.storage.blob._models.ContainerProperties, str]) → azure.storage.blob.aio._container_client_async.ContainerClient[source]

Get a client to interact with the specified container.

The container need not already exist.

Parameters

container (str or ContainerProperties) – The container. This can either be the name of the container, or an instance of ContainerProperties.

Returns

A ContainerClient.

Return type

ContainerClient

Example:

Getting the container client to interact with a specific container.
# Get a client to interact with a specific container - though it may not yet exist
container_client = blob_service_client.get_container_client("containertestasync")
try:
    blobs_list = []
    async for blob in container_client.list_blobs():
        blobs_list.append(blob)

    for blob in blobs_list:
        print("Found blob: ", blob.name)
except ResourceNotFoundError:
    print("Container not found.")
async get_service_properties(**kwargs: Any) → Dict[str, Any][source]

Gets the properties of a storage account’s Blob service, including Azure Storage Analytics.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

An object containing blob service properties such as analytics logging, hour/minute metrics, cors rules, etc.

Return type

Dict[str, Any]

Example:

Getting service properties for the blob service.
properties = await blob_service_client.get_service_properties()
async get_service_stats(**kwargs: Any) → Dict[str, Any][source]

Retrieves statistics related to replication for the Blob service.

It is only available when read-access geo-redundant replication is enabled for the storage account.

With geo-redundant replication, Azure Storage maintains your data durable in two locations. In both locations, Azure Storage constantly maintains multiple healthy replicas of your data. The location where you read, create, update, or delete data is the primary storage account location. The primary location exists in the region you choose at the time you create an account via the Azure Management Azure classic portal, for example, North Central US. The location to which your data is replicated is the secondary location. The secondary location is automatically determined based on the location of the primary; it is in a second data center that resides in the same region as the primary location. Read-only access is available from the secondary location, if read-access geo-redundant replication is enabled for your storage account.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

The blob service stats.

Return type

Dict[str, Any]

Example:

Getting service stats for the blob service.
stats = await blob_service_client.get_service_stats()
async get_user_delegation_key(key_start_time: datetime, key_expiry_time: datetime, **kwargs: Any) → UserDelegationKey[source]

Obtain a user delegation key for the purpose of signing SAS tokens. A token credential must be present on the service object for this request to succeed.

Parameters
  • key_start_time (datetime) – A DateTime value. Indicates when the key becomes valid.

  • key_expiry_time (datetime) – A DateTime value. Indicates when the key stops being valid.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

The user delegation key.

Return type

UserDelegationKey

list_containers(name_starts_with: Optional[str] = None, include_metadata: Optional[bool] = False, **kwargs)azure.core.async_paging.AsyncItemPaged[azure.storage.blob._models.ContainerProperties][source]

Returns a generator to list the containers under the specified account.

The generator will lazily follow the continuation tokens returned by the service and stop when all containers have been returned.

Parameters
  • name_starts_with (str) – Filters the results to return only containers whose names begin with the specified prefix.

  • include_metadata (bool) – Specifies that container metadata to be returned in the response. The default value is False.

Keyword Arguments
  • results_per_page (int) – The maximum number of container names to retrieve per API call. If the request does not specify the server will return up to 5,000 items.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

An iterable (auto-paging) of ContainerProperties.

Return type

AsyncItemPaged[ContainerProperties]

Example:

Listing the containers in the blob service.
# List all containers
all_containers = []
async for container in blob_service_client.list_containers(include_metadata=True):
    all_containers.append(container)

for container in all_containers:
    print(container['name'], container['metadata'])

# Filter results with name prefix
test_containers = []
async for name in blob_service_client.list_containers(name_starts_with='test-'):
    test_containers.append(name)

for container in test_containers:
    await blob_service_client.delete_container(container)
async set_service_properties(analytics_logging: Optional[BlobAnalyticsLogging] = None, hour_metrics: Optional[Metrics] = None, minute_metrics: Optional[Metrics] = None, cors: Optional[List[CorsRule]] = None, target_version: Optional[str] = None, delete_retention_policy: Optional[RetentionPolicy] = None, static_website: Optional[StaticWebsite] = None, **kwargs)None[source]

Sets the properties of a storage account’s Blob service, including Azure Storage Analytics.

If an element (e.g. analytics_logging) is left as None, the existing settings on the service for that functionality are preserved.

Parameters
  • analytics_logging (BlobAnalyticsLogging) – Groups the Azure Analytics Logging settings.

  • hour_metrics (Metrics) – The hour metrics settings provide a summary of request statistics grouped by API in hourly aggregates for blobs.

  • minute_metrics (Metrics) – The minute metrics settings provide request statistics for each minute for blobs.

  • cors (list[CorsRule]) – You can include up to five CorsRule elements in the list. If an empty list is specified, all CORS rules will be deleted, and CORS will be disabled for the service.

  • target_version (str) – Indicates the default version to use for requests if an incoming request’s version is not specified.

  • delete_retention_policy (RetentionPolicy) – The delete retention policy specifies whether to retain deleted blobs. It also specifies the number of days and versions of blob to keep.

  • static_website (StaticWebsite) – Specifies whether the static website feature is enabled, and if yes, indicates the index document and 404 error document to use.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example:

Setting service properties for the blob service.
# Create service properties
from azure.storage.blob import BlobAnalyticsLogging, Metrics, CorsRule, RetentionPolicy

# Create logging settings
logging = BlobAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5))

# Create metrics for requests statistics
hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5))
minute_metrics = Metrics(enabled=True, include_apis=True,
                        retention_policy=RetentionPolicy(enabled=True, days=5))

# Create CORS rules
cors_rule = CorsRule(['www.xyz.com'], ['GET'])
cors = [cors_rule]

# Set the service properties
await blob_service_client.set_service_properties(logging, hour_metrics, minute_metrics, cors)
property api_version

The version of the Storage API used for requests.

Type

str

property location_mode

The location mode that the client is currently using.

By default this will be “primary”. Options include “primary” and “secondary”.

Type

str

property primary_endpoint

The full primary endpoint URL.

Type

str

property primary_hostname

The hostname of the primary endpoint.

Type

str

property secondary_endpoint

The full secondary endpoint URL if configured.

If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.

Type

str

Raises

ValueError

property secondary_hostname

The hostname of the secondary endpoint.

If not available this will be None. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.

Type

str or None

property url

The full endpoint URL to this entity, including SAS token if used.

This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode().

class azure.storage.blob.aio.ContainerClient(account_url: str, container_name: str, credential: Optional[Any] = None, **kwargs: Any)[source]

A client to interact with a specific container, although that container may not yet exist.

For operations relating to a specific blob within this container, a blob client can be retrieved using the get_blob_client() function.

Parameters
  • account_url (str) – The URI to the storage account. In order to create a client given the full URI to the container, use the from_container_url() classmethod.

  • container_name (str) – The name of the container for the blob.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the URL already has a SAS token, specifying an explicit credential will take priority.

Keyword Arguments
  • api_version (str) –

    The Storage API version to use for requests. Default value is ‘2019-07-07’. Setting to an older version may result in reduced feature compatibility.

    New in version 12.2.0.

  • secondary_hostname (str) – The hostname of the secondary endpoint.

  • max_block_size (int) – The maximum chunk size for uploading a block blob in chunks. Defaults to 4*1024*1024, or 4MB.

  • max_single_put_size (int) – If the blob size is less than or equal max_single_put_size, then the blob will be uploaded with only one http PUT request. If the blob size is larger than max_single_put_size, the blob will be uploaded in chunks. Defaults to 64*1024*1024, or 64MB.

  • min_large_block_upload_threshold (int) – The minimum chunk size required to use the memory efficient algorithm when uploading a block blob. Defaults to 4*1024*1024+1.

  • use_byte_buffer (bool) – Use a byte buffer for block blob uploads. Defaults to False.

  • max_page_size (int) – The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024, or 4MB.

  • max_single_get_size (int) – The maximum size for a blob to be downloaded in a single call, the exceeded part will be downloaded in chunks (could be parallel). Defaults to 32*1024*1024, or 32MB.

  • max_chunk_get_size (int) – The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024, or 4MB.

Example:

Get a ContainerClient from an existing BlobServiceClient.
# Instantiate a BlobServiceClient using a connection string
from azure.storage.blob.aio import BlobServiceClient
blob_service_client = BlobServiceClient.from_connection_string(self.connection_string)

# Instantiate a ContainerClient
container_client = blob_service_client.get_container_client("mynewcontainerasync")
Creating the container client directly.
from azure.storage.blob.aio import ContainerClient

sas_url = sas_url = "https://account.blob.core.windows.net/mycontainer?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D"
container = ContainerClient.from_container_url(sas_url)
async acquire_lease(lease_duration: int = - 1, lease_id: Optional[str] = None, **kwargs) → azure.storage.blob.aio._lease_async.BlobLeaseClient[source]

Requests a new lease. If the container does not have an active lease, the Blob service creates a lease on the container and returns a new lease ID.

Parameters
  • lease_duration (int) – Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. Default is -1 (infinite lease).

  • lease_id (str) – Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

A BlobLeaseClient object, that can be run in a context manager.

Return type

BlobLeaseClient

Example:

Acquiring a lease on the container.
# Acquire a lease on the container
lease = await container_client.acquire_lease()

# Delete container by passing in the lease
await container_client.delete_container(lease=lease)
async close()

This method is to close the sockets opened by the client. It need not be used when using with a context manager.

async create_container(metadata: Optional[Dict[str, str]] = None, public_access: Optional[Union[PublicAccess, str]] = None, **kwargs: Any)None[source]

Creates a new container under the specified account. If the container with the same name already exists, the operation fails.

Parameters
  • metadata (dict[str, str]) – A dict with name_value pairs to associate with the container as metadata. Example:{‘Category’:’test’}

  • public_access (PublicAccess) – Possible values include: ‘container’, ‘blob’.

Keyword Arguments
  • container_encryption_scope (dict or ContainerEncryptionScope) –

    Specifies the default encryption scope to set on the container and use for all future writes.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example:

Creating a container to store blobs.
await container_client.create_container()
async delete_blob(blob: Union[str, azure.storage.blob._models.BlobProperties], delete_snapshots: Optional[str] = None, **kwargs)None[source]

Marks the specified blob or snapshot for deletion.

The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the delete_blob operation.

If a delete retention policy is enabled for the service, then this operation soft deletes the blob or snapshot and retains the blob or snapshot for specified number of days. After specified number of days, blob’s data is removed from the service during garbage collection. Soft deleted blob or snapshot is accessible through list_blobs() specifying include=[“deleted”] option. Soft-deleted blob or snapshot can be restored using undelete()

Parameters
  • blob (str or BlobProperties) – The blob with which to interact. If specified, this value will override a blob value specified in the blob URL.

  • delete_snapshots (str) –

    Required if the blob has associated snapshots. Values include:
    • ”only”: Deletes only the blobs snapshots.

    • ”include”: Deletes the blob along with all snapshots.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a Lease object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

async delete_blobs(*blobs: List[Union[str, azure.storage.blob._models.BlobProperties, dict]], **kwargs) → AsyncIterator[azure.core.pipeline.transport._base_async.AsyncHttpResponse][source]

Marks the specified blobs or snapshots for deletion.

The blobs are later deleted during garbage collection. Note that in order to delete blobs, you must delete all of their snapshots. You can delete both at the same time with the delete_blobs operation.

If a delete retention policy is enabled for the service, then this operation soft deletes the blobs or snapshots and retains the blobs or snapshots for specified number of days. After specified number of days, blobs’ data is removed from the service during garbage collection. Soft deleted blobs or snapshots are accessible through list_blobs() specifying include=[“deleted”] Soft-deleted blobs or snapshots can be restored using undelete()

Parameters

blobs (list[str], list[dict], or list[BlobProperties]) –

The blobs to delete. This can be a single blob, or multiple values can be supplied, where each value is either the name of the blob (str) or BlobProperties.

Note

When the blob type is dict, here’s a list of keys, value rules.

blob name:

key: ‘name’, value type: str

snapshot you want to delete:

key: ‘snapshot’, value type: str

whether to delete snapthots when deleting blob:

key: ‘delete_snapshots’, value: ‘include’ or ‘only’

if the blob modified or not:

key: ‘if_modified_since’, ‘if_unmodified_since’, value type: datetime

etag:

key: ‘etag’, value type: str

match the etag or not:

key: ‘match_condition’, value type: MatchConditions

tags match condition:

key: ‘if_tags_match_condition’, value type: str

lease:

key: ‘lease_id’, value type: Union[str, LeaseClient]

timeout for subrequest:

key: ‘timeout’, value type: int

Keyword Arguments
  • delete_snapshots (str) –

    Required if a blob has associated snapshots. Values include:
    • ”only”: Deletes only the blobs snapshots.

    • ”include”: Deletes the blob along with all snapshots.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • raise_on_any_failure (bool) – This is a boolean param which defaults to True. When this is set, an exception is raised even if there is a single operation failure. For optimal performance, this should be set to False

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

An async iterator of responses, one for each blob in order

Return type

asynciterator[AsyncHttpResponse]

Example:

Deleting multiple blobs.
# Delete multiple blobs in the container by name
await container_client.delete_blobs("my_blob1", "my_blob2")

# Delete multiple blobs by properties iterator
my_blobs = container_client.list_blobs(name_starts_with="my_blob")
await container_client.delete_blobs(*[b async for b in my_blobs])  # async for in list comprehension after 3.6 only
async delete_container(**kwargs: Any)None[source]

Marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection.

Keyword Arguments
  • lease (BlobLeaseClient or str) – If specified, delete_container only succeeds if the container’s lease is active and matches this ID. Required if the container has an active lease.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

  • timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example:

Delete a container.
await container_client.delete_container()
async download_blob(blob: Union[str, BlobProperties], offset: Optional[int] = None, length: Optional[int] = None, **kwargs: Any) → StorageStreamDownloader[source]

Downloads a blob to the StorageStreamDownloader. The readall() method must be used to read all the content or readinto() must be used to download the blob into a stream.

Parameters
  • blob (str or BlobProperties) – The blob with which to interact. If specified, this value will override a blob value specified in the blob URL.

  • offset (int) – Start of byte range to use for downloading a section of the blob. Must be set if length is provided.

  • length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

Keyword Arguments
  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. If specified, download_blob only succeeds if the blob’s lease is active and matches this ID. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • max_concurrency (int) – The number of parallel connections with which to download.

  • encoding (str) – Encoding to decode the downloaded bytes. Default is None, i.e. no decoding.

  • timeout (int) – The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.

Returns

A streaming object. (StorageStreamDownloader)

Return type

StorageStreamDownloader

classmethod from_connection_string(conn_str: str, container_name: str, credential: Optional[Any] = None, **kwargs: Any) → azure.storage.blob._container_client.ContainerClient[source]

Create ContainerClient from a Connection String.

Parameters
  • conn_str (str) – A connection string to an Azure Storage account.

  • container_name (str) – The container name for the blob.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.

Returns

A container client.

Return type

ContainerClient

Example:

Creating the ContainerClient from a connection string.
from azure.storage.blob import ContainerClient
container_client = ContainerClient.from_connection_string(
    self.connection_string, container_name="mycontainer")
classmethod from_container_url(container_url: str, credential: Optional[Any] = None, **kwargs: Any) → azure.storage.blob._container_client.ContainerClient[source]

Create ContainerClient from a container url.

Parameters
  • container_url (str) – The full endpoint URL to the Container, including SAS token if used. This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.

Returns

A container client.

Return type

ContainerClient

async get_account_information(**kwargs: Any) → Dict[str, str][source]

Gets information related to the storage account.

The information can also be retrieved if the user has a SAS to a container or blob. The keys in the returned dictionary include ‘sku_name’ and ‘account_kind’.

Returns

A dict of account information (SKU and account type).

Return type

dict(str, str)

get_blob_client(blob: Union[azure.storage.blob._models.BlobProperties, str], snapshot: Optional[str] = None) → azure.storage.blob.aio._blob_client_async.BlobClient[source]

Get a client to interact with the specified blob.

The blob need not already exist.

Parameters
  • blob (str or BlobProperties) – The blob with which to interact.

  • snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot().

Returns

A BlobClient.

Return type

BlobClient

Example:

Get the blob client.
# Get the BlobClient from the ContainerClient to interact with a specific blob
blob_client = container_client.get_blob_client("mynewblob")
async get_container_access_policy(**kwargs: Any) → Dict[str, Any][source]

Gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly.

Keyword Arguments
  • lease (BlobLeaseClient or str) – If specified, get_container_access_policy only succeeds if the container’s lease is active and matches this ID.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Access policy information in a dict.

Return type

dict[str, Any]

Example:

Getting the access policy on the container.
policy = await container_client.get_container_access_policy()
async get_container_properties(**kwargs: Any) → azure.storage.blob._models.ContainerProperties[source]

Returns all user-defined metadata and system properties for the specified container. The data returned does not include the container’s list of blobs.

Keyword Arguments
  • lease (BlobLeaseClient or str) – If specified, get_container_properties only succeeds if the container’s lease is active and matches this ID.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Properties for the specified container within a container object.

Return type

ContainerProperties

Example:

Getting properties on the container.
properties = await container_client.get_container_properties()
list_blobs(name_starts_with: Optional[str] = None, include: Union[str, List[str], None] = None, **kwargs: Any)azure.core.async_paging.AsyncItemPaged[azure.storage.blob._models.BlobProperties][source]

Returns a generator to list the blobs under the specified container. The generator will lazily follow the continuation tokens returned by the service.

Parameters
  • name_starts_with (str) – Filters the results to return only blobs whose names begin with the specified prefix.

  • or str include (list[str]) – Specifies one or more additional datasets to include in the response. Options include: ‘snapshots’, ‘metadata’, ‘uncommittedblobs’, ‘copy’, ‘deleted’, ‘tags’.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

An iterable (auto-paging) response of BlobProperties.

Return type

AsyncItemPaged[BlobProperties]

Example:

List the blobs in the container.
blobs_list = []
async for blob in container_client.list_blobs():
    blobs_list.append(blob)
async set_container_access_policy(signed_identifiers: Dict[str, AccessPolicy], public_access: Optional[Union[str, PublicAccess]] = None, **kwargs: Any) → Dict[str, Union[str, datetime]][source]

Sets the permissions for the specified container or stored access policies that may be used with Shared Access Signatures. The permissions indicate whether blobs in a container may be accessed publicly.

Parameters
  • signed_identifiers (dict[str, AccessPolicy]) – A dictionary of access policies to associate with the container. The dictionary may contain up to 5 elements. An empty dictionary will clear the access policies set on the service.

  • public_access (PublicAccess) – Possible values include: ‘container’, ‘blob’.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the container has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A datetime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified date/time.

  • if_unmodified_since (datetime) – A datetime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Container-updated property dict (Etag and last modified).

Return type

dict[str, str or datetime]

Example:

Setting access policy on the container.
# Create access policy
from azure.storage.blob import AccessPolicy, ContainerSasPermissions
access_policy = AccessPolicy(permission=ContainerSasPermissions(read=True),
                            expiry=datetime.utcnow() + timedelta(hours=1),
                            start=datetime.utcnow() - timedelta(minutes=1))

identifiers = {'my-access-policy-id': access_policy}

# Set the access policy on the container
await container_client.set_container_access_policy(signed_identifiers=identifiers)
async set_container_metadata(metadata: Optional[Dict[str, str]] = None, **kwargs) → Dict[str, Union[str, datetime]][source]

Sets one or more user-defined name-value pairs for the specified container. Each call to this operation replaces all existing metadata attached to the container. To remove all metadata from the container, call this operation with no metadata dict.

Parameters

metadata (dict[str, str]) – A dict containing name-value pairs to associate with the container as metadata. Example: {‘category’:’test’}

Keyword Arguments
  • lease (BlobLeaseClient or str) – If specified, set_container_metadata only succeeds if the container’s lease is active and matches this ID.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Container-updated property dict (Etag and last modified).

Example:

Setting metadata on the container.
# Create key, value pairs for metadata
metadata = {'type': 'test'}

# Set metadata on the container
await container_client.set_container_metadata(metadata=metadata)
async set_premium_page_blob_tier_blobs(premium_page_blob_tier: Union[str, PremiumPageBlobTier], *blobs: List[Union[str, azure.storage.blob._models.BlobProperties, dict]], **kwargs) → AsyncIterator[azure.core.pipeline.transport._base_async.AsyncHttpResponse][source]

Sets the page blob tiers on the blobs. This API is only supported for page blobs on premium accounts.

Parameters
  • premium_page_blob_tier (PremiumPageBlobTier) –

    A page blob tier value to set on all blobs to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.

    Note

    If you want to set different tier on different blobs please set this positional parameter to None. Then the blob tier on every BlobProperties will be taken.

  • blobs (list[str], list[dict], or list[BlobProperties]) –

    The blobs with which to interact. This can be a single blob, or multiple values can be supplied, where each value is either the name of the blob (str) or BlobProperties.

    Note

    When the blob type is dict, here’s a list of keys, value rules.

    blob name:

    key: ‘name’, value type: str

    premium blob tier:

    key: ‘blob_tier’, value type: PremiumPageBlobTier

    lease:

    key: ‘lease_id’, value type: Union[str, LeaseClient]

    timeout for subrequest:

    key: ‘timeout’, value type: int

Keyword Arguments
  • timeout (int) – The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.

  • raise_on_any_failure (bool) – This is a boolean param which defaults to True. When this is set, an exception is raised even if there is a single operation failure. For optimal performance, this should be set to False.

Returns

An async iterator of responses, one for each blob in order

Return type

asynciterator[AsyncHttpResponse]

async set_standard_blob_tier_blobs(standard_blob_tier: Union[str, StandardBlobTier], *blobs: List[Union[str, azure.storage.blob._models.BlobProperties, dict]], **kwargs) → AsyncIterator[azure.core.pipeline.transport._base_async.AsyncHttpResponse][source]

This operation sets the tier on block blobs.

A block blob’s tier determines Hot/Cool/Archive storage type. This operation does not update the blob’s ETag.

Parameters
  • standard_blob_tier (str or StandardBlobTier) –

    Indicates the tier to be set on all blobs. Options include ‘Hot’, ‘Cool’, ‘Archive’. The hot tier is optimized for storing data that is accessed frequently. The cool storage tier is optimized for storing data that is infrequently accessed and stored for at least a month. The archive tier is optimized for storing data that is rarely accessed and stored for at least six months with flexible latency requirements.

    Note

    If you want to set different tier on different blobs please set this positional parameter to None. Then the blob tier on every BlobProperties will be taken.

  • blobs (list[str], list[dict], or list[BlobProperties]) –

    The blobs with which to interact. This can be a single blob, or multiple values can be supplied, where each value is either the name of the blob (str) or BlobProperties.

    Note

    When the blob type is dict, here’s a list of keys, value rules. blob name:

    key: ‘name’, value type: str

    standard blob tier:

    key: ‘blob_tier’, value type: StandardBlobTier

    rehydrate priority:

    key: ‘rehydrate_priority’, value type: RehydratePriority

    lease:

    key: ‘lease_id’, value type: Union[str, LeaseClient]

    tags match condition:

    key: ‘if_tags_match_condition’, value type: str

    timeout for subrequest:

    key: ‘timeout’, value type: int

Keyword Arguments

rehydrate_priority (RehydratePriority) – Indicates the priority with which to rehydrate an archived blob

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • timeout (int) – The timeout parameter is expressed in seconds.

  • raise_on_any_failure (bool) – This is a boolean param which defaults to True. When this is set, an exception is raised even if there is a single operation failure. For optimal performance, this should be set to False.

Returns

An async iterator of responses, one for each blob in order

Return type

asynciterator[AsyncHttpResponse]

async upload_blob(name: Union[str, azure.storage.blob._models.BlobProperties], data: Union[Iterable[AnyStr], IO[AnyStr]], blob_type: str = <BlobType.BlockBlob: 'BlockBlob'>, length: Optional[int] = None, metadata: Optional[Dict[str, str]] = None, **kwargs) → azure.storage.blob.aio._blob_client_async.BlobClient[source]

Creates a new blob from a data source with automatic chunking.

Parameters
  • name (str or BlobProperties) – The blob with which to interact. If specified, this value will override a blob value specified in the blob URL.

  • data – The blob data to upload.

  • blob_type (BlobType) – The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob. The default value is BlockBlob.

  • length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

  • metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.

Keyword Arguments
  • overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob will overwrite the existing data. If set to False, the operation will fail with ResourceExistsError. The exception to the above is with Append blob types: if set to False and the data already exists, an error will not be raised and the data will be appended to the existing blob. If set overwrite=True, then the existing append blob will be deleted, and a new one created. Defaults to False.

  • content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.

  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.

  • lease (BlobLeaseClient or str) – Required if the container has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • timeout (int) – The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.

  • premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.

  • standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.

  • maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).

  • max_concurrency (int) – Maximum number of parallel connections to use when the blob size exceeds 64MB.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • encoding (str) – Defaults to UTF-8.

Returns

A BlobClient to interact with the newly uploaded blob.

Return type

BlobClient

Example:

Upload blob to the container.
with open(SOURCE_FILE, "rb") as data:
    blob_client = await container_client.upload_blob(name="myblob", data=data)

properties = await blob_client.get_blob_properties()
walk_blobs(name_starts_with: Optional[str] = None, include: Optional[Any] = None, delimiter: str = '/', **kwargs: Optional[Any])azure.core.async_paging.AsyncItemPaged[azure.storage.blob._models.BlobProperties][source]

Returns a generator to list the blobs under the specified container. The generator will lazily follow the continuation tokens returned by the service. This operation will list blobs in accordance with a hierarchy, as delimited by the specified delimiter character.

Parameters
  • name_starts_with (str) – Filters the results to return only blobs whose names begin with the specified prefix.

  • include (list[str]) – Specifies one or more additional datasets to include in the response. Options include: ‘snapshots’, ‘metadata’, ‘uncommittedblobs’, ‘copy’, ‘deleted’.

  • delimiter (str) – When the request includes this parameter, the operation returns a BlobPrefix element in the response body that acts as a placeholder for all blobs whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may be a single character or a string.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

An iterable (auto-paging) response of BlobProperties.

Return type

AsyncItemPaged[BlobProperties]

property api_version

The version of the Storage API used for requests.

Type

str

property location_mode

The location mode that the client is currently using.

By default this will be “primary”. Options include “primary” and “secondary”.

Type

str

property primary_endpoint

The full primary endpoint URL.

Type

str

property primary_hostname

The hostname of the primary endpoint.

Type

str

property secondary_endpoint

The full secondary endpoint URL if configured.

If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.

Type

str

Raises

ValueError

property secondary_hostname

The hostname of the secondary endpoint.

If not available this will be None. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.

Type

str or None

property url

The full endpoint URL to this entity, including SAS token if used.

This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode().

class azure.storage.blob.aio.BlobClient(account_url: str, container_name: str, blob_name: str, snapshot: Union[str, Dict[str, Any], None] = None, credential: Optional[Any] = None, **kwargs: Any)[source]

A client to interact with a specific blob, although that blob may not yet exist.

Parameters
  • account_url (str) – The URI to the storage account. In order to create a client given the full URI to the blob, use the from_blob_url() classmethod.

  • container_name (str) – The container name for the blob.

  • blob_name (str) – The name of the blob with which to interact. If specified, this value will override a blob value specified in the blob URL.

  • snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot().

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the URL already has a SAS token, specifying an explicit credential will take priority.

Keyword Arguments
  • api_version (str) –

    The Storage API version to use for requests. Default value is ‘2019-07-07’. Setting to an older version may result in reduced feature compatibility.

    New in version 12.2.0.

  • secondary_hostname (str) – The hostname of the secondary endpoint.

  • max_block_size (int) – The maximum chunk size for uploading a block blob in chunks. Defaults to 4*1024*1024, or 4MB.

  • max_single_put_size (int) – If the blob size is less than or equal max_single_put_size, then the blob will be uploaded with only one http PUT request. If the blob size is larger than max_single_put_size, the blob will be uploaded in chunks. Defaults to 64*1024*1024, or 64MB.

  • min_large_block_upload_threshold (int) – The minimum chunk size required to use the memory efficient algorithm when uploading a block blob. Defaults to 4*1024*1024+1.

  • use_byte_buffer (bool) – Use a byte buffer for block blob uploads. Defaults to False.

  • max_page_size (int) – The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024, or 4MB.

  • max_single_get_size (int) – The maximum size for a blob to be downloaded in a single call, the exceeded part will be downloaded in chunks (could be parallel). Defaults to 32*1024*1024, or 32MB.

  • max_chunk_get_size (int) – The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024, or 4MB.

Example:

Creating the BlobClient from a URL to a public blob (no auth needed).
from azure.storage.blob.aio import BlobClient
blob_client = BlobClient.from_blob_url(blob_url="https://account.blob.core.windows.net/container/blob-name")
Creating the BlobClient from a SAS URL to a blob.
from azure.storage.blob.aio import BlobClient

sas_url = "https://account.blob.core.windows.net/container/blob-name?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D"
blob_client = BlobClient.from_blob_url(sas_url)
async abort_copy(copy_id: Union[str, Dict[str, Any], azure.storage.blob._models.BlobProperties], **kwargs: Any)None[source]

Abort an ongoing copy operation.

This will leave a destination blob with zero length and full metadata. This will raise an error if the copy operation has already ended.

Parameters

copy_id (str or BlobProperties) – The copy operation to abort. This can be either an ID, or an instance of BlobProperties.

Return type

None

Example:

Abort copying a blob from URL.
# Passing in copy id to abort copy operation
await copied_blob.abort_copy(copy_id)

# check copy status
props = await copied_blob.get_blob_properties()
print(props.copy.status)
async acquire_lease(lease_duration: int = - 1, lease_id: Optional[str] = None, **kwargs: Any) → azure.storage.blob.aio._lease_async.BlobLeaseClient[source]

Requests a new lease.

If the blob does not have an active lease, the Blob Service creates a lease on the blob and returns a new lease.

Parameters
  • lease_duration (int) – Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. Default is -1 (infinite lease).

  • lease_id (str) – Proposed lease ID, in a GUID string format. The Blob Service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

A BlobLeaseClient object.

Return type

BlobLeaseClient

Example:

Acquiring a lease on a blob.
# Get the blob client
blob_client = blob_service_client.get_blob_client("leasemyblobscontainerasync", "my_blob")

# Acquire a lease on the blob
lease = await blob_client.acquire_lease()

# Delete blob by passing in the lease
await blob_client.delete_blob(lease=lease)
async append_block(data: Union[AnyStr, Iterable[AnyStr], IO[AnyStr]], length: Optional[int] = None, **kwargs) → Dict[str, Union[str, datetime, int]][source]

Commits a new block of data to the end of the existing append blob.

Parameters
  • data – Content of the block.

  • length (int) – Size of the block in bytes.

Keyword Arguments
  • validate_content (bool) – If true, calculates an MD5 hash of the block content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.

  • maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).

  • appendpos_condition (int) – Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • encoding (str) – Defaults to UTF-8.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag, last modified, append offset, committed block count).

Return type

dict(str, Any)

async append_block_from_url(copy_source_url: str, source_offset: Optional[int] = None, source_length: Optional[int] = None, **kwargs) → Dict[str, Union[str, datetime, int]][source]

Creates a new block to be committed as part of a blob, where the contents are read from a source url.

Parameters
  • copy_source_url (str) – The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.

  • source_offset (int) – This indicates the start of the range of bytes(inclusive) that has to be taken from the copy source.

  • source_length (int) – This indicates the end of the range of bytes that has to be taken from the copy source.

Keyword Arguments
  • source_content_md5 (bytearray) – If given, the service will calculate the MD5 hash of the block content and compare against this value.

  • maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).

  • appendpos_condition (int) – Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The destination match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has been modified since the specified time.

  • source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time.

  • source_etag (str) – The source ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • source_match_condition (MatchConditions) – The source match condition to use upon the etag.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

async clear_page(offset: int, length: int, **kwargs: Any) → Dict[str, Union[str, datetime]][source]

Clears a range of pages.

Parameters
  • offset (int) – Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

  • length (int) – Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_sequence_number_lte (int) – If the blob’s sequence number is less than or equal to the specified value, the request proceeds; otherwise it fails.

  • if_sequence_number_lt (int) – If the blob’s sequence number is less than the specified value, the request proceeds; otherwise it fails.

  • if_sequence_number_eq (int) – If the blob’s sequence number is equal to the specified value, the request proceeds; otherwise it fails.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified).

Return type

dict(str, Any)

async close()

This method is to close the sockets opened by the client. It need not be used when using with a context manager.

async commit_block_list(block_list: List[BlobBlock], content_settings: Optional[ContentSettings] = None, metadata: Optional[Dict[str, str]] = None, **kwargs) → Dict[str, Union[str, datetime]][source]

The Commit Block List operation writes a blob by specifying the list of block IDs that make up the blob.

Parameters
  • block_list (list) – List of Blockblobs.

  • content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.

  • metadata (dict[str, str]) – Name-value pairs associated with the blob as metadata.

Keyword Arguments
  • tags (dict(str, str)) –

    Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (` `), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)

    New in version 12.4.0.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • validate_content (bool) – If true, calculates an MD5 hash of the page content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified).

Return type

dict(str, Any)

async create_append_blob(content_settings: Optional[ContentSettings] = None, metadata: Optional[Dict[str, str]] = None, **kwargs: Any) → Dict[str, Union[str, datetime]][source]

Creates a new Append Blob.

Parameters
  • content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.

  • metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.

Keyword Arguments
  • tags (dict(str, str)) –

    Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (` `), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)

    New in version 12.4.0.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified).

Return type

dict[str, Any]

async create_page_blob(size: int, content_settings: Optional[ContentSettings] = None, metadata: Optional[Dict[str, str]] = None, premium_page_blob_tier: Optional[Union[str, PremiumPageBlobTier]] = None, **kwargs) → Dict[str, Union[str, datetime]][source]

Creates a new Page Blob of the specified size.

Parameters
  • size (int) – This specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned to a 512-byte boundary.

  • content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.

  • metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.

  • premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.

Keyword Arguments
  • tags (dict(str, str)) –

    Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (` `), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)

    New in version 12.4.0.

  • sequence_number (int) – Only for Page blobs. The sequence number is a user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified).

Return type

dict[str, Any]

async create_snapshot(metadata: Optional[Dict[str, str]] = None, **kwargs: Any) → Dict[str, Union[str, datetime]][source]

Creates a snapshot of the blob.

A snapshot is a read-only version of a blob that’s taken at a point in time. It can be read, copied, or deleted, but not modified. Snapshots provide a way to back up a blob as it appears at a moment in time.

A snapshot of a blob has the same name as the base blob from which the snapshot is taken, with a DateTime value appended to indicate the time at which the snapshot was taken.

Parameters

metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Snapshot ID, Etag, and last modified).

Return type

dict[str, Any]

Example:

Create a snapshot of the blob.
# Create a read-only snapshot of the blob at this point in time
snapshot_blob = await blob_client.create_snapshot()

# Get the snapshot ID
print(snapshot_blob.get('snapshot'))

# Delete only the snapshot (blob itself is retained)
await blob_client.delete_blob(delete_snapshots="only")
async delete_blob(delete_snapshots: bool = False, **kwargs: Any)None[source]

Marks the specified blob for deletion.

The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the delete_blob() operation.

If a delete retention policy is enabled for the service, then this operation soft deletes the blob and retains the blob for a specified number of days. After the specified number of days, the blob’s data is removed from the service during garbage collection. Soft deleted blob is accessible through list_blobs() specifying include=[‘deleted’] option. Soft-deleted blob can be restored using undelete() operation.

Parameters

delete_snapshots (str) –

Required if the blob has associated snapshots. Values include:
  • ”only”: Deletes only the blobs snapshots.

  • ”include”: Deletes the blob along with all snapshots.

Keyword Arguments
  • version_id (str) –

    The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to delete.

    New in version 12.4.0.

    This keyword argument was introduced in API version ‘2019-12-12’.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. If specified, delete_blob only succeeds if the blob’s lease is active and matches this ID. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example:

Delete a blob.
await blob_client.delete_blob()
async download_blob(offset: Optional[int] = None, length: Optional[int] = None, **kwargs: Any) → azure.storage.blob.aio._download_async.StorageStreamDownloader[source]

Downloads a blob to the StorageStreamDownloader. The readall() method must be used to read all the content or readinto() must be used to download the blob into a stream.

Parameters
  • offset (int) – Start of byte range to use for downloading a section of the blob. Must be set if length is provided.

  • length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

Keyword Arguments
  • version_id (str) –

    The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to download.

    New in version 12.4.0.

    This keyword argument was introduced in API version ‘2019-12-12’.

  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. If specified, download_blob only succeeds if the blob’s lease is active and matches this ID. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • max_concurrency (int) – The number of parallel connections with which to download.

  • encoding (str) – Encoding to decode the downloaded bytes. Default is None, i.e. no decoding.

  • timeout (int) – The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.

Returns

A streaming object (StorageStreamDownloader)

Return type

StorageStreamDownloader

Example:

Download a blob.
with open(DEST_FILE, "wb") as my_blob:
    stream = await blob_client.download_blob()
    data = await stream.readall()
    my_blob.write(data)
classmethod from_blob_url(blob_url: str, credential: Optional[Any] = None, snapshot: Union[str, Dict[str, Any], None] = None, **kwargs: Any) → azure.storage.blob._blob_client.BlobClient[source]

Create BlobClient from a blob url. This doesn’t support customized blob url with ‘/’ in blob name.

Parameters
  • blob_url (str) – The full endpoint URL to the Blob, including SAS token and snapshot if used. This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode.

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.

  • snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot(). If specified, this will override the snapshot in the url.

Returns

A Blob client.

Return type

BlobClient

classmethod from_connection_string(conn_str: str, container_name: str, blob_name: str, snapshot: Optional[str] = None, credential: Optional[Any] = None, **kwargs: Any) → azure.storage.blob._blob_client.BlobClient[source]

Create BlobClient from a Connection String.

Parameters
  • conn_str (str) – A connection string to an Azure Storage account.

  • container_name (str) – The container name for the blob.

  • blob_name (str) – The name of the blob with which to interact.

  • snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot().

  • credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.

Returns

A Blob client.

Return type

BlobClient

Example:

Creating the BlobClient from a connection string.
from azure.storage.blob import BlobClient
blob_client = BlobClient.from_connection_string(
    self.connection_string, container_name="mycontainer", blob_name="blobname.txt")
async get_account_information(**kwargs: Optional[int]) → Dict[str, str][source]

Gets information related to the storage account in which the blob resides.

The information can also be retrieved if the user has a SAS to a container or blob. The keys in the returned dictionary include ‘sku_name’ and ‘account_kind’.

Returns

A dict of account information (SKU and account type).

Return type

dict(str, str)

async get_blob_properties(**kwargs: Any) → azure.storage.blob._models.BlobProperties[source]

Returns all user-defined metadata, standard HTTP properties, and system properties for the blob. It does not return the content of the blob.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • version_id (str) –

    The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to get properties.

    New in version 12.4.0.

    This keyword argument was introduced in API version ‘2019-12-12’.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

BlobProperties

Return type

BlobProperties

Example:

Getting the properties for a blob.
properties = await blob_client.get_blob_properties()
async get_blob_tags(**kwargs: Any) → Dict[str, str][source]

The Get Tags operation enables users to get tags on a blob or specific blob version, but not snapshot.

New in version 12.4.0: This operation was introduced in API version ‘2019-12-12’.

Keyword Arguments

version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to add tags to.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

Key value pairs of blob tags.

Return type

Dict[str, str]

async get_block_list(block_list_type: Optional[str] = 'committed', **kwargs: Any) → Tuple[List[azure.storage.blob._models.BlobBlock], List[azure.storage.blob._models.BlobBlock]][source]

The Get Block List operation retrieves the list of blocks that have been uploaded as part of a block blob.

Parameters

block_list_type (str) – Specifies whether to return the list of committed blocks, the list of uncommitted blocks, or both lists together. Possible values include: ‘committed’, ‘uncommitted’, ‘all’

Keyword Arguments

lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

A tuple of two lists - committed and uncommitted blocks

Return type

tuple(list(BlobBlock), list(BlobBlock))

async get_page_range_diff_for_managed_disk(previous_snapshot_url: str, offset: Optional[int] = None, length: Optional[int] = None, **kwargs) → Tuple[List[Dict[str, int]], List[Dict[str, int]]][source]

Returns the list of valid page ranges for a managed disk or snapshot.

Note

This operation is only available for managed disk accounts.

New in version 12.2.0: This operation was introduced in API version ‘2019-07-07’.

Parameters
  • previous_snapshot_url – Specifies the URL of a previous snapshot of the managed disk. The response will only contain pages that were changed between the target blob and its previous snapshot.

  • offset (int) – Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

  • length (int) – Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

A tuple of two lists of page ranges as dictionaries with ‘start’ and ‘end’ keys. The first element are filled page ranges, the 2nd element is cleared page ranges.

Return type

tuple(list(dict(str, str), list(dict(str, str))

async get_page_ranges(offset: Optional[int] = None, length: Optional[int] = None, previous_snapshot_diff: Union[str, Dict[str, Any], None] = None, **kwargs) → Tuple[List[Dict[str, int]], List[Dict[str, int]]][source]

Returns the list of valid page ranges for a Page Blob or snapshot of a page blob.

Parameters
  • offset (int) – Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

  • length (int) – Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

  • previous_snapshot_diff (str) – The snapshot diff parameter that contains an opaque DateTime value that specifies a previous blob snapshot to be compared against a more recent snapshot or the current blob.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

A tuple of two lists of page ranges as dictionaries with ‘start’ and ‘end’ keys. The first element are filled page ranges, the 2nd element is cleared page ranges.

Return type

tuple(list(dict(str, str), list(dict(str, str))

query_blob(query_expression: str, **kwargs: Any) → azure.storage.blob._quick_query_helper.BlobQueryReader[source]

Enables users to select/project on blob/or blob snapshot data by providing simple query expressions. This operations returns a BlobQueryReader, users need to use readall() or readinto() to get query data.

Parameters

query_expression (str) – Required. a query statement.

Keyword Arguments
  • on_error (Callable[Exception]) – A function to be called on any processing errors returned by the service.

  • blob_format (DelimitedTextDialect or DelimitedJsonDialect) – Optional. Defines the serialization of the data currently stored in the blob. The default is to treat the blob data as CSV data formatted in the default dialect. This can be overridden with a custom DelimitedTextDialect, or alternatively a DelimitedJsonDialect.

  • output_format (DelimitedTextDialect or DelimitedJsonDialect) – Optional. Defines the output serialization for the data stream. By default the data will be returned as it is represented in the blob. By providing an output format, the blob data will be reformatted according to that profile. This value can be a DelimitedTextDialect or a DelimitedJsonDialect.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

A streaming object (BlobQueryReader)

Return type

BlobQueryReader

Example:

select/project on blob/or blob snapshot data by providing simple query expressions.
errors = []
def on_error(error):
    errors.append(error)

# upload the csv file
blob_client = blob_service_client.get_blob_client(container_name, "csvfile")
with open("./sample-blobs/quick_query.csv", "rb") as stream:
    blob_client.upload_blob(stream, overwrite=True)

# select the second column of the csv file
query_expression = "SELECT _2 from BlobStorage"
input_format = DelimitedTextDialect(delimiter=',', quotechar='"', lineterminator='\n', escapechar="", has_header=False)
output_format = DelimitedJsonDialect(delimiter='\n')
reader = blob_client.query_blob(query_expression, on_error=on_error, blob_format=input_format, output_format=output_format)
content = reader.readall()
async resize_blob(size: int, **kwargs: Any) → Dict[str, Union[str, datetime]][source]

Resizes a page blob to the specified size.

If the specified value is less than the current size of the blob, then all pages above the specified value are cleared.

Parameters

size (int) – Size used to resize blob. Maximum size for a page blob is up to 1 TB. The page blob size must be aligned to a 512-byte boundary.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified).

Return type

dict(str, Any)

async seal_append_blob(**kwargs) → Dict[str, Union[str, datetime, int]][source]

The Seal operation seals the Append Blob to make it read-only.

New in version 12.4.0.

Keyword Arguments
  • appendpos_condition (int) – Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag, last modified, append offset, committed block count).

Return type

dict(str, Any)

async set_blob_metadata(metadata: Optional[Dict[str, str]] = None, **kwargs: Any) → Dict[str, Union[str, datetime]][source]

Sets user-defined metadata for the blob as one or more name-value pairs.

Parameters

metadata (dict(str, str)) – Dict containing name and value pairs. Each call to this operation replaces all existing metadata attached to the blob. To remove all metadata from the blob, call this operation with no metadata headers.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified)

async set_blob_tags(tags: Optional[Dict[str, str]] = None, **kwargs: Any) → Dict[str, Any][source]
The Set Tags operation enables users to set tags on a blob or specific blob version, but not snapshot.

Each call to this operation replaces all existing tags attached to the blob. To remove all tags from the blob, call this operation with no tags set.

New in version 12.4.0: This operation was introduced in API version ‘2019-12-12’.

Parameters

tags (dict(str, str)) – Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (` `), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)

Keyword Arguments
  • version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to delete.

  • validate_content (bool) – If true, calculates an MD5 hash of the tags content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified)

Return type

Dict[str, Any]

async set_http_headers(content_settings: Optional[ContentSettings] = None, **kwargs: Any)None[source]

Sets system properties on the blob.

If one property is set for the content_settings, all properties will be overridden.

Parameters

content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified)

Return type

Dict[str, Any]

async set_premium_page_blob_tier(premium_page_blob_tier: Union[str, PremiumPageBlobTier], **kwargs: Any)None[source]

Sets the page blob tiers on the blob. This API is only supported for page blobs on premium accounts.

Parameters

premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • timeout (int) – The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

Return type

None

async set_sequence_number(sequence_number_action: Union[str, SequenceNumberAction], sequence_number: Optional[str] = None, **kwargs) → Dict[str, Union[str, datetime]][source]

Sets the blob sequence number.

Parameters
  • sequence_number_action (str) – This property indicates how the service should modify the blob’s sequence number. See SequenceNumberAction for more information.

  • sequence_number (str) – This property sets the blob’s sequence number. The sequence number is a user-controlled property that you can use to track requests and manage concurrency issues.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified).

Return type

dict(str, Any)

async set_standard_blob_tier(standard_blob_tier: Union[str, StandardBlobTier], **kwargs: Any)None[source]

This operation sets the tier on a block blob.

A block blob’s tier determines Hot/Cool/Archive storage type. This operation does not update the blob’s ETag.

Parameters

standard_blob_tier (str or StandardBlobTier) – Indicates the tier to be set on the blob. Options include ‘Hot’, ‘Cool’, ‘Archive’. The hot tier is optimized for storing data that is accessed frequently. The cool storage tier is optimized for storing data that is infrequently accessed and stored for at least a month. The archive tier is optimized for storing data that is rarely accessed and stored for at least six months with flexible latency requirements.

Keyword Arguments

rehydrate_priority (RehydratePriority) – Indicates the priority with which to rehydrate an archived blob

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • timeout (int) – The timeout parameter is expressed in seconds.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

Return type

None

async stage_block(block_id: str, data: Union[Iterable[AnyStr], IO[AnyStr]], length: Optional[int] = None, **kwargs)None[source]

Creates a new block to be committed as part of a blob.

Parameters
  • block_id (str) – A valid Base64 string value that identifies the block. Prior to encoding, the string must be less than or equal to 64 bytes in size. For a given blob, the length of the value specified for the block_id parameter must be the same size for each block.

  • data – The blob data.

  • length (int) – Size of the block.

Keyword Arguments
  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • encoding (str) – Defaults to UTF-8.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

async stage_block_from_url(block_id: str, source_url: str, source_offset: Optional[int] = None, source_length: Optional[int] = None, source_content_md5: Union[bytes, bytearray, None] = None, **kwargs)None[source]

Creates a new block to be committed as part of a blob where the contents are read from a URL.

Parameters
  • block_id (str) – A valid Base64 string value that identifies the block. Prior to encoding, the string must be less than or equal to 64 bytes in size. For a given blob, the length of the value specified for the block_id parameter must be the same size for each block.

  • source_url (str) – The URL.

  • source_offset (int) – Start of byte range to use for the block. Must be set if source length is provided.

  • source_length (int) – The size of the block in bytes.

  • source_content_md5 (bytearray) – Specify the md5 calculated for the range of bytes that must be read from the copy source.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

async start_copy_from_url(source_url: str, metadata: Optional[Dict[str, str]] = None, incremental_copy: bool = False, **kwargs: Any) → Any[source]

Copies a blob asynchronously.

This operation returns a copy operation object that can be used to wait on the completion of the operation, as well as check status or abort the copy operation. The Blob service copies blobs on a best-effort basis.

The source blob for a copy operation may be a block blob, an append blob, or a page blob. If the destination blob already exists, it must be of the same blob type as the source blob. Any existing destination blob will be overwritten. The destination blob cannot be modified while a copy operation is in progress.

When copying from a page blob, the Blob service creates a destination page blob of the source blob’s length, initially containing all zeroes. Then the source page ranges are enumerated, and non-empty ranges are copied.

For a block blob or an append blob, the Blob service creates a committed blob of zero length before returning from this operation. When copying from a block blob, all committed blocks and their block IDs are copied. Uncommitted blocks are not copied. At the end of the copy operation, the destination blob will have the same committed block count as the source.

When copying from an append blob, all committed blocks are copied. At the end of the copy operation, the destination blob will have the same committed block count as the source.

For all blob types, you can call status() on the returned polling object to check the status of the copy operation, or wait() to block until the operation is complete. The final blob will be committed when the copy completes.

Parameters
  • source_url (str) –

    A URL of up to 2 KB in length that specifies a file or blob. The value should be URL-encoded as it would appear in a request URI. If the source is in another account, the source must either be public or must be authenticated via a shared access signature. If the source is public, no authentication is required. Examples: https://myaccount.blob.core.windows.net/mycontainer/myblob

    https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<DateTime>

    https://otheraccount.blob.core.windows.net/mycontainer/myblob?sastoken

  • metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob or file.

  • incremental_copy (bool) – Copies the snapshot of the source page blob to a destination page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. Defaults to False.

Keyword Arguments
  • tags (dict(str, str)) –

    Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (` `), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)

    New in version 12.4.0.

  • source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has been modified since the specified date/time.

  • source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has not been modified since the specified date/time.

  • source_etag (str) – The source ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • source_match_condition (MatchConditions) – The source match condition to use upon the etag.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the destination blob has been modified since the specified date/time. If the destination blob has not been modified, the Blob service returns status code 412 (Precondition Failed).

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the destination blob has not been modified since the specified date/time. If the destination blob has been modified, the Blob service returns status code 412 (Precondition Failed).

  • etag (str) – The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The destination match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • destination_lease (BlobLeaseClient or str) – The lease ID specified for this header must match the lease ID of the destination blob. If the request does not include the lease ID or it is not valid, the operation fails with status code 412 (Precondition Failed).

  • source_lease (BlobLeaseClient or str) – Specify this to perform the Copy Blob operation only if the lease ID given matches the active lease ID of the source blob.

  • timeout (int) – The timeout parameter is expressed in seconds.

  • premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.

  • standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.

  • rehydrate_priority (RehydratePriority) – Indicates the priority with which to rehydrate an archived blob

  • seal_destination_blob (bool) –

    Seal the destination append blob. This operation is only for append blob.

    New in version 12.4.0.

  • requires_sync (bool) – Enforces that the service will not return a response until the copy is complete.

Returns

A dictionary of copy properties (etag, last_modified, copy_id, copy_status).

Return type

dict[str, str or datetime]

Example:

Copy a blob from a URL.
# Get the blob client with the source blob
source_blob = "http://www.gutenberg.org/files/59466/59466-0.txt"
copied_blob = blob_service_client.get_blob_client("copyblobcontainerasync", '59466-0.txt')

# start copy and check copy status
copy = await copied_blob.start_copy_from_url(source_blob)
props = await copied_blob.get_blob_properties()
print(props.copy.status)
async undelete_blob(**kwargs: Any)None[source]

Restores soft-deleted blobs or snapshots.

Operation will only be successful if used within the specified number of days set in the delete retention policy.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

Example:

Undeleting a blob.
# Undelete the blob before the retention policy expires
await blob_client.undelete_blob()
async upload_blob(data: Union[Iterable[AnyStr], IO[AnyStr]], blob_type: str = <BlobType.BlockBlob: 'BlockBlob'>, length: Optional[int] = None, metadata: Optional[Dict[str, str]] = None, **kwargs) → Any[source]

Creates a new blob from a data source with automatic chunking.

Parameters
  • data – The blob data to upload.

  • blob_type (BlobType) – The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob. The default value is BlockBlob.

  • length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

  • metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.

Keyword Arguments
  • tags (dict(str, str)) –

    Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (` `), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)

    New in version 12.4.0.

  • overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob will overwrite the existing data. If set to False, the operation will fail with ResourceExistsError. The exception to the above is with Append blob types: if set to False and the data already exists, an error will not be raised and the data will be appended to the existing blob. If set overwrite=True, then the existing append blob will be deleted, and a new one created. Defaults to False.

  • content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.

  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.

  • lease – If specified, upload_blob only succeeds if the blob’s lease is active and matches this ID. Required if the blob has an active lease.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

Paramtype

BlobLeaseClient

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.

  • standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.

  • maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).

  • max_concurrency (int) – Maximum number of parallel connections to use when the blob size exceeds 64MB.

  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • encoding (str) – Defaults to UTF-8.

  • timeout (int) – The timeout parameter is expressed in seconds. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.

Returns

Blob-updated property dict (Etag and last modified)

Return type

dict[str, Any]

Example:

Upload a blob to the container.
# Upload content to block blob
with open(SOURCE_FILE, "rb") as data:
    await blob_client.upload_blob(data, blob_type="BlockBlob")
async upload_page(page: bytes, offset: int, length: int, **kwargs) → Dict[str, Union[str, datetime]][source]

The Upload Pages operation writes a range of pages to a page blob.

Parameters
  • page (bytes) – Content of the page.

  • offset (int) – Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

  • length (int) – Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

Keyword Arguments
  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • validate_content (bool) – If true, calculates an MD5 hash of the page content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.

  • if_sequence_number_lte (int) – If the blob’s sequence number is less than or equal to the specified value, the request proceeds; otherwise it fails.

  • if_sequence_number_lt (int) – If the blob’s sequence number is less than the specified value, the request proceeds; otherwise it fails.

  • if_sequence_number_eq (int) – If the blob’s sequence number is equal to the specified value, the request proceeds; otherwise it fails.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • encoding (str) – Defaults to UTF-8.

  • timeout (int) – The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified).

Return type

dict(str, Any)

async upload_pages_from_url(source_url: str, offset: int, length: int, source_offset: int, **kwargs) → Dict[str, Any][source]

The Upload Pages operation writes a range of pages to a page blob where the contents are read from a URL.

Parameters
  • source_url (str) – The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.

  • offset (int) – Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

  • length (int) – Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.

  • source_offset (int) – This indicates the start of the range of bytes(inclusive) that has to be taken from the copy source. The service will read the same number of bytes as the destination range (length-offset).

Keyword Arguments
  • source_content_md5 (bytes) – If given, the service will calculate the MD5 hash of the block content and compare against this value.

  • source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has been modified since the specified time.

  • source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time.

  • source_etag (str) – The source ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • source_match_condition (MatchConditions) – The source match condition to use upon the etag.

  • lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.

  • if_sequence_number_lte (int) – If the blob’s sequence number is less than or equal to the specified value, the request proceeds; otherwise it fails.

  • if_sequence_number_lt (int) – If the blob’s sequence number is less than the specified value, the request proceeds; otherwise it fails.

  • if_sequence_number_eq (int) – If the blob’s sequence number is equal to the specified value, the request proceeds; otherwise it fails.

  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The destination match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments
  • cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.

  • encryption_scope (str) –

    A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.

    New in version 12.2.0.

  • timeout (int) – The timeout parameter is expressed in seconds.

property api_version

The version of the Storage API used for requests.

Type

str

property location_mode

The location mode that the client is currently using.

By default this will be “primary”. Options include “primary” and “secondary”.

Type

str

property primary_endpoint

The full primary endpoint URL.

Type

str

property primary_hostname

The hostname of the primary endpoint.

Type

str

property secondary_endpoint

The full secondary endpoint URL if configured.

If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.

Type

str

Raises

ValueError

property secondary_hostname

The hostname of the secondary endpoint.

If not available this will be None. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.

Type

str or None

property url

The full endpoint URL to this entity, including SAS token if used.

This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode().

class azure.storage.blob.aio.BlobLeaseClient(client: Union[BlobClient, ContainerClient], lease_id: Optional[str] = None)[source]

Creates a new BlobLeaseClient.

This client provides lease operations on a BlobClient or ContainerClient.

Variables
  • id (str) – The ID of the lease currently being maintained. This will be None if no lease has yet been acquired.

  • etag (str) – The ETag of the lease currently being maintained. This will be None if no lease has yet been acquired or modified.

  • last_modified (datetime) – The last modified timestamp of the lease currently being maintained. This will be None if no lease has yet been acquired or modified.

Parameters
  • client (BlobClient or ContainerClient) – The client of the blob or container to lease.

  • lease_id (str) – A string representing the lease ID of an existing lease. This value does not need to be specified in order to acquire a new lease, or break one.

async acquire(lease_duration: int = - 1, **kwargs: Any)None[source]

Requests a new lease.

If the container does not have an active lease, the Blob service creates a lease on the container and returns a new lease ID.

Parameters

lease_duration (int) – Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. Default is -1 (infinite lease).

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Return type

None

async break_lease(lease_break_period: Optional[int] = None, **kwargs: Any)int[source]

Break the lease, if the container or blob has an active lease.

Once a lease is broken, it cannot be renewed. Any authorized request can break the lease; the request is not required to specify a matching lease ID. When a lease is broken, the lease break period is allowed to elapse, during which time no lease operation except break and release can be performed on the container or blob. When a lease is successfully broken, the response indicates the interval in seconds until a new lease can be acquired.

Parameters

lease_break_period (int) – This is the proposed duration of seconds that the lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be available before the break period has expired, but the lease may be held for longer than the break period. If this header does not appear with a break operation, a fixed-duration lease breaks after the remaining lease period elapses, and an infinite lease breaks immediately.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

Approximate time remaining in the lease period, in seconds.

Return type

int

async change(proposed_lease_id: str, **kwargs: Any)None[source]

Change the lease ID of an active lease.

Parameters

proposed_lease_id (str) – Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

None

async release(**kwargs: Any)None[source]

Release the lease.

The lease may be released if the client lease id specified matches that associated with the container or blob. Releasing the lease allows another client to immediately acquire the lease for the container or blob as soon as the release is complete.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

None

async renew(**kwargs: Any)None[source]

Renews the lease.

The lease can be renewed if the lease ID specified in the lease client matches that associated with the container or blob. Note that the lease may be renewed even if it has expired as long as the container or blob has not been leased again since the expiration of that lease. When you renew a lease, the lease duration clock resets.

Keyword Arguments
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.

  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.

  • etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.

  • match_condition (MatchConditions) – The match condition to use upon the etag.

:keyword str if_tags_match_condition

Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg. “”tagname”=’my tag’”

New in version 12.4.0.

Keyword Arguments

timeout (int) – The timeout parameter is expressed in seconds.

Returns

None

class azure.storage.blob.aio.ExponentialRetry(initial_backoff=15, increment_base=3, retry_total=3, retry_to_secondary=False, random_jitter_range=3, **kwargs)[source]

Exponential retry.

Constructs an Exponential retry object. The initial_backoff is used for the first retry. Subsequent retries are retried after initial_backoff + increment_power^retry_count seconds. For example, by default the first retry occurs after 15 seconds, the second after (15+3^1) = 18 seconds, and the third after (15+3^2) = 24 seconds.

Parameters
  • initial_backoff (int) – The initial backoff interval, in seconds, for the first retry.

  • increment_base (int) – The base, in seconds, to increment the initial_backoff by after the first retry.

  • max_attempts (int) – The maximum number of retry attempts.

  • retry_to_secondary (bool) – Whether the request should be retried to secondary, if able. This should only be enabled of RA-GRS accounts are used and potentially stale data can be handled.

  • random_jitter_range (int) – A number in seconds which indicates a range to jitter/randomize for the back-off interval. For example, a random_jitter_range of 3 results in the back-off interval x to vary between x+3 and x-3.

configure_retries(request)
get_backoff_time(settings)[source]

Calculates how long to sleep before retrying.

Returns

An integer indicating how long to wait before retrying the request, or None to indicate no retry should be performed.

Return type

int or None

increment(settings, request, response=None, error=None)

Increment the retry counters.

Parameters
  • response – A pipeline response object.

  • error – An error encountered during the request, or None if the response was received successfully.

Returns

Whether the retry attempts are exhausted.

async send(request)

Abstract send method for a synchronous pipeline. Mutates the request.

Context content is dependent on the HttpTransport.

Parameters

request (PipelineRequest) – The pipeline request object

Returns

The pipeline response object.

Return type

PipelineResponse

async sleep(settings, transport)
class azure.storage.blob.aio.LinearRetry(backoff=15, retry_total=3, retry_to_secondary=False, random_jitter_range=3, **kwargs)[source]

Linear retry.

Constructs a Linear retry object.

Parameters
  • backoff (int) – The backoff interval, in seconds, between retries.

  • max_attempts (int) – The maximum number of retry attempts.

  • retry_to_secondary (bool) – Whether the request should be retried to secondary, if able. This should only be enabled of RA-GRS accounts are used and potentially stale data can be handled.

  • random_jitter_range (int) – A number in seconds which indicates a range to jitter/randomize for the back-off interval. For example, a random_jitter_range of 3 results in the back-off interval x to vary between x+3 and x-3.

configure_retries(request)
get_backoff_time(settings)[source]

Calculates how long to sleep before retrying.

Returns

An integer indicating how long to wait before retrying the request, or None to indicate no retry should be performed.

Return type

int or None

increment(settings, request, response=None, error=None)

Increment the retry counters.

Parameters
  • response – A pipeline response object.

  • error – An error encountered during the request, or None if the response was received successfully.

Returns

Whether the retry attempts are exhausted.

async send(request)

Abstract send method for a synchronous pipeline. Mutates the request.

Context content is dependent on the HttpTransport.

Parameters

request (PipelineRequest) – The pipeline request object

Returns

The pipeline response object.

Return type

PipelineResponse

async sleep(settings, transport)
class azure.storage.blob.aio.StorageStreamDownloader(clients=None, config=None, start_range=None, end_range=None, validate_content=None, encryption_options=None, max_concurrency=1, name=None, container=None, encoding=None, **kwargs)[source]

A streaming object to download from Azure Storage.

Variables
  • name (str) – The name of the blob being downloaded.

  • container (str) – The name of the container where the blob is.

  • properties (BlobProperties) – The properties of the blob being downloaded. If only a range of the data is being downloaded, this will be reflected in the properties.

  • size (int) – The size of the total data in the stream. This will be the byte range if speficied, otherwise the total size of the blob.

chunks()[source]

Iterate over chunks in the download stream.

Return type

Iterable[bytes]

async content_as_bytes(max_concurrency=1)[source]

Download the contents of this file.

This operation is blocking until all data is downloaded.

Keyword Arguments

max_concurrency (int) – The number of parallel connections with which to download.

Return type

bytes

async content_as_text(max_concurrency=1, encoding='UTF-8')[source]

Download the contents of this blob, and decode as text.

This operation is blocking until all data is downloaded.

Keyword Arguments

max_concurrency (int) – The number of parallel connections with which to download.

Parameters

encoding (str) – Test encoding to decode the downloaded bytes. Default is UTF-8.

Return type

str

async download_to_stream(stream, max_concurrency=1)[source]

Download the contents of this blob to a stream.

Parameters

stream – The stream to download to. This can be an open file-handle, or any writable stream. The stream must be seekable if the download uses more than one parallel connection.

Returns

The properties of the downloaded blob.

Return type

Any

async readall()[source]

Download the contents of this blob.

This operation is blocking until all data is downloaded. :rtype: bytes or str

async readinto(stream)[source]

Download the contents of this blob to a stream.

Parameters

stream – The stream to download to. This can be an open file-handle, or any writable stream. The stream must be seekable if the download uses more than one parallel connection.

Returns

The number of bytes read.

Return type

int

async azure.storage.blob.aio.upload_blob_to_url(blob_url: str, data: Union[Iterable[AnyStr], IO[AnyStr]], credential: Any = None, **kwargs)dict[str, Any][source]

Upload data to a given URL

The data will be uploaded as a block blob.

Parameters
  • blob_url (str) – The full URI to the blob. This can also include a SAS token.

  • data (bytes or str or Iterable) – The data to upload. This can be bytes, text, an iterable or a file-like object.

  • credential – The credentials with which to authenticate. This is optional if the blob URL already has a SAS token. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the URL already has a SAS token, specifying an explicit credential will take priority.

Keyword Arguments
  • overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob_to_url will overwrite any existing data. If set to False, the operation will fail with a ResourceExistsError.

  • max_concurrency (int) – The number of parallel connections with which to download.

  • length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

  • metadata (dict(str,str)) – Name-value pairs associated with the blob as metadata.

  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.

  • encoding (str) – Encoding to use if text is supplied as input. Defaults to UTF-8.

Returns

Blob-updated property dict (Etag and last modified)

Return type

dict(str, Any)

async azure.storage.blob.aio.download_blob_from_url(blob_url: str, output: str, credential: Any = None, **kwargs)None[source]

Download the contents of a blob to a local file or stream.

Parameters
  • blob_url (str) – The full URI to the blob. This can also include a SAS token.

  • output (str or writable stream) – Where the data should be downloaded to. This could be either a file path to write to, or an open IO handle to write to.

  • credential – The credentials with which to authenticate. This is optional if the blob URL already has a SAS token or the blob is public. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the URL already has a SAS token, specifying an explicit credential will take priority.

Keyword Arguments
  • overwrite (bool) – Whether the local file should be overwritten if it already exists. The default value is False - in which case a ValueError will be raised if the file already exists. If set to True, an attempt will be made to write to the existing file. If a stream handle is passed in, this value is ignored.

  • max_concurrency (int) – The number of parallel connections with which to download.

  • offset (int) – Start of byte range to use for downloading a section of the blob. Must be set if length is provided.

  • length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.

Return type

None