BlobClient class

Definition

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

BlobClient(account_url, container_name, blob_name, snapshot=None, credential=None, **kwargs)
Inheritance
builtins.object
azure.storage.blob._shared.base_client_async.AsyncStorageAccountHostsMixin
BlobClient
azure.storage.blob._shared.base_client.StorageAccountHostsMixin
azure.storage.blob.blob_client.BlobClient
BlobClient

Parameters

account_url
str

The full URI to the account.

container_name
str

The container for the blob.

blob_name
str

The mame of the blob with which to interact.

snapshot
str

The optional blob snapshot on which to operate.

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, and 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.

Examples

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)

Variables

url
str
The full endpoint URL to the Blob, including snapshot and SAS token if used. This could be either the primary endpoint, or the secondary endpoint depending on the current *location_mode*.
primary_endpoint
str
The full primary endpoint URL.
primary_hostname
str
The hostname of the primary endpoint.
secondary_endpoint
str
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.
secondary_hostname
str
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.
location_mode
str
The location mode that the client is currently using. By default this will be "primary". Options include "primary" and "secondary".

Methods

abort_copy(copy_id, **kwargs)

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.

acquire_lease(lease_duration=-1, lease_id=None, **kwargs)

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.

append_block(data, length=None, **kwargs)

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

append_block_from_url(copy_source_url, source_offset=None, source_length=None, **kwargs)

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

clear_page(offset, length, **kwargs)

Clears a range of pages.

commit_block_list(block_list, content_settings=None, metadata=None, **kwargs)

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

create_append_blob(content_settings=None, metadata=None, **kwargs)

Creates a new Append Blob.

create_page_blob(size, content_settings=None, metadata=None, premium_page_blob_tier=None, **kwargs)

Creates a new Page Blob of the specified size.

create_snapshot(metadata=None, **kwargs)

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.

delete_blob(delete_snapshots=False, **kwargs)

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 API specifying include='deleted' option. Soft-deleted blob can be restored using Undelete API.

download_blob(offset=None, length=None, **kwargs)

Downloads a blob to a stream with automatic chunking.

get_account_information(**kwargs)

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'.

get_blob_properties(**kwargs)

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

get_block_list(block_list_type='committed', **kwargs)

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

get_page_ranges(offset=None, length=None, previous_snapshot_diff=None, **kwargs)

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

resize_blob(size, **kwargs)

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.

set_blob_metadata(metadata=None, **kwargs)

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

set_http_headers(content_settings=None, **kwargs)

Sets system properties on the blob.

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

set_premium_page_blob_tier(premium_page_blob_tier, **kwargs)

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

set_sequence_number(sequence_number_action, sequence_number=None, **kwargs)

Sets the blob sequence number.

set_standard_blob_tier(standard_blob_tier, **kwargs)

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.

stage_block(block_id, data, length=None, **kwargs)

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

stage_block_from_url(block_id, source_url, source_offset=None, source_length=None, source_content_md5=None, **kwargs)

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

start_copy_from_url(source_url, metadata=None, incremental_copy=False, **kwargs)

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.

undelete_blob(**kwargs)

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.

upload_blob(data, blob_type=<BlobType.BlockBlob: 'BlockBlob'>, length=None, metadata=None, **kwargs)

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

upload_page(page, offset, length, **kwargs)

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

upload_pages_from_url(source_url, offset, length, source_offset, **kwargs)

Updates a range of pages to a page blob where the contents are read from a URL.

abort_copy(copy_id, **kwargs)

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.

abort_copy(copy_id, **kwargs)

Parameters

copy_id
str or BlobProperties

The copy operation to abort. This can be either an ID, or an instance of BlobProperties.

Return type

Examples

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)

acquire_lease(lease_duration=-1, lease_id=None, **kwargs)

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.

acquire_lease(lease_duration=-1, lease_id=None, **kwargs)

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.

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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Returns

A LeaseClient object.

Return type

azure.storage.blob.aio.lease_async.LeaseClient

Examples

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)

append_block(data, length=None, **kwargs)

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

append_block(data, length=None, **kwargs)

Parameters

data

Content of the block.

length
int

Size of the block in bytes.

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
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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.

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)

append_block_from_url(copy_source_url, source_offset=None, source_length=None, **kwargs)

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

append_block_from_url(copy_source_url, source_offset=None, source_length=None, **kwargs)

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.

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).

or str lease
azure.storage.blob.lease.LeaseClient

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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_if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the source resource's ETag matches the value specified.

source_if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the source resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the source resource does not exist, and fail the operation if it does exist.

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.

clear_page(offset, length, **kwargs)

Clears a range of pages.

clear_page(offset, length, **kwargs)

Parameters

offset
int

Start of byte range to use for downloading a section of the blob. Must be set if length is provided. Pages must be aligned with 512-byte boundaries, the start offset 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.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify an ETag value for this conditional header to write the page only if the blob's ETag value matches the value specified. If the values do not match, the Blob service fails.

if_none_match
str

An ETag value, or the wildcard character (*). Specify an ETag value for this conditional header to write the page only if the blob's ETag value does not match the value specified. If the values are identical, the Blob service fails.

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)

commit_block_list(block_list, content_settings=None, metadata=None, **kwargs)

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

commit_block_list(block_list, content_settings=None, metadata=None, **kwargs)

Parameters

block_list
list

List of Blockblobs.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient object or the lease ID as a string.

content_settings
ContentSettings

ContentSettings object used to set blob properties.

metadata
dict[str, str]

Name-value pairs associated with the blob as metadata.

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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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.

timeout
int

The timeout parameter is expressed in seconds.

Returns

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

Return type

dict(str, Any)

create_append_blob(content_settings=None, metadata=None, **kwargs)

Creates a new Append Blob.

create_append_blob(content_settings=None, metadata=None, **kwargs)

Parameters

content_settings
ContentSettings

ContentSettings object used to set properties on the blob.

metadata
dict(str, str)

Name-value pairs associated with the blob as metadata.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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]

create_page_blob(size, content_settings=None, metadata=None, premium_page_blob_tier=None, **kwargs)

Creates a new Page Blob of the specified size.

create_page_blob(size, content_settings=None, metadata=None, premium_page_blob_tier=None, **kwargs)

Parameters

size
int

This header 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 properties on the blob.

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.

metadata
dict(str, str)

Name-value pairs associated with the blob as metadata.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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.

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.

Returns

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

Return type

dict[str, Any]

create_snapshot(metadata=None, **kwargs)

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.

create_snapshot(metadata=None, **kwargs)

Parameters

metadata
dict(str, str)

Name-value pairs associated with the blob as metadata.

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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

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]

Examples

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")

delete_blob(delete_snapshots=False, **kwargs)

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 API specifying include='deleted' option. Soft-deleted blob can be restored using Undelete API.

delete_blob(delete_snapshots=False, **kwargs)

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.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Return type

Examples

Delete a blob.


   await blob_client.delete_blob()

download_blob(offset=None, length=None, **kwargs)

Downloads a blob to a stream with automatic chunking.

download_blob(offset=None, length=None, **kwargs)

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.

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
azure.storage.blob.aio.lease_async.LeaseClient or str

If specified, download_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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.

Returns

A iterable data generator (stream)

Return type

azure.storage.blob._blob_utils.StorageStreamDownloader

Examples

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)

get_account_information(**kwargs)

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'.

get_account_information(**kwargs)

Returns

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

Return type

get_blob_properties(**kwargs)

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

get_blob_properties(**kwargs)

Parameters

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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

Examples

Getting the properties for a blob.


   properties = await blob_client.get_blob_properties()

get_block_list(block_list_type='committed', **kwargs)

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

get_block_list(block_list_type='committed', **kwargs)

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'

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient object or the lease ID as a string.

timeout
int

The timeout parameter is expressed in seconds.

Returns

A tuple of two lists - committed and uncommitted blocks

Return type

get_page_ranges(offset=None, length=None, previous_snapshot_diff=None, **kwargs)

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

get_page_ranges(offset=None, length=None, previous_snapshot_diff=None, **kwargs)

Parameters

offset
int

Start of byte range to use for downloading a section of the blob. Must be set if length is provided. 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. 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.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient object or the lease ID as a string.

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.

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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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

resize_blob(size, **kwargs)

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.

resize_blob(size, **kwargs)

Parameters

size
int

Size to resize blob to.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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)

set_blob_metadata(metadata=None, **kwargs)

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

set_blob_metadata(metadata=None, **kwargs)

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.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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)

set_http_headers(content_settings=None, **kwargs)

Sets system properties on the blob.

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

set_http_headers(content_settings=None, **kwargs)

Parameters

content_settings
ContentSettings

ContentSettings object used to set blob properties.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified)

Return type

Dict[str, Any]

set_premium_page_blob_tier(premium_page_blob_tier, **kwargs)

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

set_premium_page_blob_tier(premium_page_blob_tier, **kwargs)

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.

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
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient object or the lease ID as a string.

Return type

set_sequence_number(sequence_number_action, sequence_number=None, **kwargs)

Sets the blob sequence number.

set_sequence_number(sequence_number_action, sequence_number=None, **kwargs)

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.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

timeout
int

The timeout parameter is expressed in seconds.

Returns

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

Return type

dict(str, Any)

set_standard_blob_tier(standard_blob_tier, **kwargs)

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.

set_standard_blob_tier(standard_blob_tier, **kwargs)

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.

rehydrate_priority
RehydratePriority

Indicates the priority with which to rehydrate an archived blob

timeout
int

The timeout parameter is expressed in seconds.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient object or the lease ID as a string.

Return type

stage_block(block_id, data, length=None, **kwargs)

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

stage_block(block_id, data, length=None, **kwargs)

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.

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
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

timeout
int

The timeout parameter is expressed in seconds.

Return type

stage_block_from_url(block_id, source_url, source_offset=None, source_length=None, source_content_md5=None, **kwargs)

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

stage_block_from_url(block_id, source_url, source_offset=None, source_length=None, source_content_md5=None, **kwargs)

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

The URL.

source_offset

Start of byte range to use for the block. Must be set if source length is provided.

source_length

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.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

timeout
int

The timeout parameter is expressed in seconds.

Return type

start_copy_from_url(source_url, metadata=None, incremental_copy=False, **kwargs)

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.

start_copy_from_url(source_url, metadata=None, incremental_copy=False, **kwargs)

Parameters

source_url
str

A URL of up to 2 KB in length that specifies an Azure 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=

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.

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_if_match
str

An ETag value, or the wildcard character (*). Specify this conditional header to copy the source blob only if its ETag matches the value specified. If the ETag values do not match, the Blob service returns status code 412 (Precondition Failed). This header cannot be specified if the source is an Azure File.

source_if_none_match
str

An ETag value, or the wildcard character (*). Specify this conditional header to copy the blob only if its ETag does not match the value specified. If the values are identical, the Blob service returns status code 412 (Precondition Failed). This header cannot be specified if the source is an Azure File.

destination_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).

destination_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).

destination_if_match
str

An ETag value, or the wildcard character (*). Specify an ETag value for this conditional header to copy the blob only if the specified ETag value matches the ETag value for an existing destination blob. If the ETag for the destination blob does not match the ETag specified for If-Match, the Blob service returns status code 412 (Precondition Failed).

destination_if_none_match
str

An ETag value, or the wildcard character (). Specify an ETag value for this conditional header to copy the blob only if the specified ETag value does not match the ETag value for the destination blob. Specify the wildcard character () to perform the operation only if the destination blob does not exist. If the specified condition isn't met, the Blob service returns status code 412 (Precondition Failed).

destination_lease
azure.storage.blob.aio.lease_async..LeaseClient 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
azure.storage.blob.aio.lease_async.LeaseClient 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.

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.

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

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, Union[str, datetime]]

Examples

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)

undelete_blob(**kwargs)

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.

undelete_blob(**kwargs)

Parameters

timeout
int

The timeout parameter is expressed in seconds.

Return type

Examples

Undeleting a blob.


   # Undelete the blob before the retention policy expires
   await blob_client.undelete_blob()

upload_blob(data, blob_type=<BlobType.BlockBlob: 'BlockBlob'>, length=None, metadata=None, **kwargs)

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

upload_blob(data, blob_type=<BlobType.BlockBlob: 'BlockBlob'>, length=None, metadata=None, **kwargs)

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.

overwrite
bool

Whether the blob to be uploaded should overwrite the current data. If True, upload_blob will silently overwrite the existing data. If set to False, the operation will fail with ResourceExistsError. The exception to the above is with Append blob types. In this case, if data already exists, an error will not be raised and the data will be appended to the existing blob. If you set overwrite=True, then the existing blob will be deleted, and a new one created.

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.

content_settings
ContentSettings

ContentSettings object used to set blob properties.

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
azure.storage.blob.aio.lease_async.LeaseClient

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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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.

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]

Examples

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")

upload_page(page, offset, length, **kwargs)

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

upload_page(page, offset, length, **kwargs)

Parameters

page
bytes

Content of the page.

offset
int

Start of byte range to use for downloading a section of the blob. Must be set if length is provided. 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.

lease
azure.storage.blob.aio.lease_async.LeaseClient or str

Required if the blob has an active lease. Value can be a LeaseClient 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.

if_match
str

An ETag value, or the wildcard character (*). Specify an ETag value for this conditional header to write the page only if the blob's ETag value matches the value specified. If the values do not match, the Blob service fails.

if_none_match
str

An ETag value, or the wildcard character (*). Specify an ETag value for this conditional header to write the page only if the blob's ETag value does not match the value specified. If the values are identical, the Blob service fails.

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.

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)

upload_pages_from_url(source_url, offset, length, source_offset, **kwargs)

Updates a range of pages to a page blob where the contents are read from a URL.

upload_pages_from_url(source_url, offset, length, source_offset, **kwargs)

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 downloading a section of the blob. Must be set if length is provided.

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).

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_if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the source resource's ETag matches the value specified.

source_if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the source resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the source resource does not exist, and fail the operation if it does exist.

lease
str

Required if the blob has an active lease.

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.

if_match
str

An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource's ETag matches the value specified.

if_none_match
str

An ETag value, or the wildcard character (). Specify this header to perform the operation only if the resource's ETag does not match the value specified. Specify the wildcard character () to perform the operation only if the resource does not exist, and fail the operation if it does exist.

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.