BlobClient Class

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

For more optional configuration, please click here.

Inheritance
azure.storage.blob._shared.base_client.StorageAccountHostsMixin
BlobClient

Constructor

BlobClient(account_url, container_name, blob_name, snapshot=None, credential=None, **kwargs)

Parameters

account_url
str
Required

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
Required

The container name for the blob.

blob_name
str
Required

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
Required

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

credential
Required

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 instance of a AzureSasCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential

  • except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError.
api_version
str
Required

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
Required

The hostname of the secondary endpoint.

max_block_size
int
Required

The maximum chunk size for uploading a block blob in chunks. Defaults to 4*1024*1024, or 4MB.

max_single_put_size
int
Required

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
Required

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
Required

Use a byte buffer for block blob uploads. Defaults to False.

max_page_size
int
Required

The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024, or 4MB.

max_single_get_size
int
Required

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
Required

The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024, or 4MB.

Examples

Creating the BlobClient from a URL to a public blob (no auth needed).


   from azure.storage.blob 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 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)

Methods

abort_copy

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

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

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

append_block_from_url

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

clear_page

Clears a range of pages.

commit_block_list

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

create_append_blob

Creates a new Append Blob.

create_page_blob

Creates a new Page Blob of the specified size.

create_snapshot

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

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 <xref:azure.storage.blob.undelete> operation.

delete_immutability_policy

The Delete Immutability Policy operation deletes the immutability policy on the blob.

New in version 12.10.0: This operation was introduced in API version '2020-10-02'.

download_blob

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. Using chunks() returns an iterator which allows the user to iterate over the content in chunks.

exists

Returns True if a blob exists with the defined parameters, and returns False otherwise.

from_blob_url

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

from_connection_string

Create BlobClient from a Connection String.

get_account_information

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

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_tags

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

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

get_block_list

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

get_page_range_diff_for_managed_disk

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

get_page_ranges

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

query_blob

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.

resize_blob

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.

seal_append_blob

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

New in version 12.4.0.

set_blob_metadata

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

set_blob_tags

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

set_http_headers

Sets system properties on the blob.

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

set_immutability_policy

The Set Immutability Policy operation sets the immutability policy on the blob.

New in version 12.10.0: This operation was introduced in API version '2020-10-02'.

set_legal_hold

The Set Legal Hold operation sets a legal hold on the blob.

New in version 12.10.0: This operation was introduced in API version '2020-10-02'.

set_premium_page_blob_tier

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

set_sequence_number

Sets the blob sequence number.

set_standard_blob_tier

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

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

stage_block_from_url

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

start_copy_from_url

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

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

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

upload_blob_from_url

Creates a new Block Blob where the content of the blob is read from a given URL. The content of an existing blob is overwritten with the new blob.

upload_page

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

upload_pages_from_url

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

abort_copy

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
Required

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

Return type

Examples

Abort copying a blob from URL.


   # Passing in copy id to abort copy operation
   copied_blob.abort_copy(copy_id)

   # check copy status
   props = copied_blob.get_blob_properties()
   print(props.copy.status)

acquire_lease

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
Required

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
Required

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.

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.

if_tags_match_condition
str

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.

timeout
int

The timeout parameter is expressed in seconds.

Returns

A BlobLeaseClient object.

Return type

Examples

Acquiring a lease on a blob.


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

   # Delete blob by passing in the lease
   blob_client.delete_blob(lease=lease)

append_block

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

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

Parameters

data
bytes or str or <xref:Iterable>
Required

Content of the block. This can be bytes, text, an iterable or a file-like object.

length
int
Required

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

if_tags_match_condition
str

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.

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, <xref:Any>)

append_block_from_url

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
Required

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
Required

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

source_length
int
Required

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

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.

if_tags_match_condition
str

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.

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.

source_authorization
str

Authenticate as a service principal using a client secret to access a source blob. Ensure "bearer " is the prefix of the source_authorization string.

clear_page

Clears a range of pages.

clear_page(offset, length, **kwargs)

Parameters

offset
int
Required

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
Required

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

if_tags_match_condition
str

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.

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, <xref:Any>)

commit_block_list

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
Required

List of Blockblobs.

content_settings
ContentSettings
Required

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

metadata
dict[str, str]
Required

Name-value pairs associated with the blob as metadata.

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.

immutability_policy
ImmutabilityPolicy

Specifies the immutability policy of a blob, blob snapshot or blob version.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

legal_hold
bool

Specified if a legal hold should be set on the blob.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

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.

if_tags_match_condition
str

Specify a SQL where clause on blob tags to operate only on destination blob with a matching value.

New in version 12.4.0.

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, <xref:Any>)

create_append_blob

Creates a new Append Blob.

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

Parameters

content_settings
ContentSettings
Required

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

metadata
dict(str, str)
Required

Name-value pairs associated with the blob as metadata.

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.

immutability_policy
ImmutabilityPolicy

Specifies the immutability policy of a blob, blob snapshot or blob version.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

legal_hold
bool

Specified if a legal hold should be set on the blob.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

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, <xref:Any>]

create_page_blob

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
Required

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
Required

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

metadata
dict(str, str)
Required

Name-value pairs associated with the blob as metadata.

premium_page_blob_tier
PremiumPageBlobTier
Required

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.

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.

immutability_policy
ImmutabilityPolicy

Specifies the immutability policy of a blob, blob snapshot or blob version.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

legal_hold
bool

Specified if a legal hold should be set on the blob.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

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, <xref:Any>]

create_snapshot

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

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.

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.

if_tags_match_condition
str

Specify a SQL where clause on blob tags to operate only on destination blob with a matching value.

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.

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, <xref:Any>]

Examples

Create a snapshot of the blob.


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

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

delete_blob

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 <xref:azure.storage.blob.undelete> operation.

delete_blob(delete_snapshots=None, **kwargs)

Parameters

delete_snapshots
str
Required

Required if the blob has associated snapshots. Values include:

  • "only": Deletes only the blobs snapshots.

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

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.

if_tags_match_condition
str

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.

timeout
int

The timeout parameter is expressed in seconds.

Return type

Examples

Delete a blob.


   blob_client.delete_blob()

delete_immutability_policy

The Delete Immutability Policy operation deletes the immutability policy on the blob.

New in version 12.10.0: This operation was introduced in API version '2020-10-02'.

delete_immutability_policy(**kwargs)

Parameters

timeout
int

The timeout parameter is expressed in seconds.

Returns

Key value pairs of blob tags.

Return type

<xref:Dict>[str, str]

download_blob

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. Using chunks() returns an iterator which allows the user to iterate over the content in chunks.

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

Parameters

offset
int
Required

Start of byte range to use for downloading a section of the blob. Must be set if length is provided.

length
int
Required

Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

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.

if_tags_match_condition
str

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.

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

Examples

Download a blob.


   with open(DEST_FILE, "wb") as my_blob:
       download_stream = blob_client.download_blob()
       my_blob.write(download_stream.readall())

exists

Returns True if a blob exists with the defined parameters, and returns False otherwise.

exists(**kwargs)

Parameters

version_id
str

The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to check if it exists.

timeout
int

The timeout parameter is expressed in seconds.

Returns

boolean

from_blob_url

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

from_blob_url(blob_url, credential=None, snapshot=None, **kwargs)

Parameters

blob_url
str
Required

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
Required

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 instance of a AzureSasCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential

  • except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError.
snapshot
str
default value: None

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.

snapshot
default value: None

Returns

A Blob client.

Return type

from_connection_string

Create BlobClient from a Connection String.

from_connection_string(conn_str, container_name, blob_name, snapshot=None, credential=None, **kwargs)

Parameters

conn_str
str
Required

A connection string to an Azure Storage account.

container_name
str
Required

The container name for the blob.

blob_name
str
Required

The name of the blob with which to interact.

snapshot
str
Required

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

credential
default value: None

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 instance of a AzureSasCredential from azure.core.credentials, 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.

credential
default value: None

Returns

A Blob client.

Return type

Examples

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

get_account_information

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

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

if_tags_match_condition
str

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.

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 = blob_client.get_blob_properties()

get_blob_tags

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

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

get_blob_tags(**kwargs)

Parameters

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.

if_tags_match_condition
str

Specify a SQL where clause on blob tags to operate only on destination blob with a matching value. eg. "\"tagname\"='my tag'"

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.

timeout
int

The timeout parameter is expressed in seconds.

Returns

Key value pairs of blob tags.

Return type

<xref:Dict>[str, str]

get_block_list

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
Required

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

Specify a SQL where clause on blob tags to operate only on destination blob with a matching value.

New in version 12.4.0.

timeout
int

The timeout parameter is expressed in seconds.

Returns

A tuple of two lists - committed and uncommitted blocks

Return type

get_page_range_diff_for_managed_disk

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

get_page_range_diff_for_managed_disk(previous_snapshot_url, offset=None, length=None, **kwargs)

Parameters

previous_snapshot_url
Required

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
Required

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
Required

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.

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

get_page_ranges

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
Required

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
Required

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
Required

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.

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.

if_tags_match_condition
str

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.

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

query_blob

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.

query_blob(query_expression, **kwargs)

Parameters

query_expression
str
Required

Required. a query statement.

on_error
<xref:Callable>[BlobQueryError]

A function to be called on any processing errors returned by the service.

blob_format
DelimitedTextDialect or DelimitedJsonDialect or QuickQueryDialect or str

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 DelimitedJsonDialect or "ParquetDialect" (passed as a string or enum). These dialects can be passed through their respective classes, the QuickQueryDialect enum or as a string

output_format
DelimitedTextDialect or DelimitedJsonDialect or list[ArrowDialect] or QuickQueryDialect or str

Optional. Defines the output serialization for the data stream. By default the data will be returned as it is represented in the blob (Parquet formats default to DelimitedTextDialect). By providing an output format, the blob data will be reformatted according to that profile. This value can be a DelimitedTextDialect or a DelimitedJsonDialect or ArrowDialect. These dialects can be passed through their respective classes, the QuickQueryDialect enum or as a string

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.

if_tags_match_condition
str

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.

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

Examples

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

resize_blob

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
Required

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.

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.

if_tags_match_condition
str

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.

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, <xref:Any>)

seal_append_blob

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

New in version 12.4.0.

seal_append_blob(**kwargs)

Parameters

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, <xref:Any>)

set_blob_metadata

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

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

if_tags_match_condition
str

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.

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)

set_blob_tags

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

set_blob_tags(tags=None, **kwargs)

Parameters

tags
dict(str, str)
Required

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 (_)

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.

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.

if_tags_match_condition
str

Specify a SQL where clause on blob tags to operate only on destination blob with a matching value. eg. "\"tagname\"='my tag'"

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.

timeout
int

The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified)

Return type

<xref:Dict>[str, <xref:Any>]

set_http_headers

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
Required

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

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.

if_tags_match_condition
str

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.

timeout
int

The timeout parameter is expressed in seconds.

Returns

Blob-updated property dict (Etag and last modified)

Return type

<xref:Dict>[str, <xref:Any>]

set_immutability_policy

The Set Immutability Policy operation sets the immutability policy on the blob.

New in version 12.10.0: This operation was introduced in API version '2020-10-02'.

set_immutability_policy(immutability_policy, **kwargs)

Parameters

immutability_policy
ImmutabilityPolicy
Required

Specifies the immutability policy of a blob, blob snapshot or blob version.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

timeout
int

The timeout parameter is expressed in seconds.

Returns

Key value pairs of blob tags.

Return type

<xref:Dict>[str, str]

The Set Legal Hold operation sets a legal hold on the blob.

New in version 12.10.0: This operation was introduced in API version '2020-10-02'.

set_legal_hold(legal_hold, **kwargs)

Parameters

legal_hold
bool
Required

Specified if a legal hold should be set on the blob.

timeout
int

The timeout parameter is expressed in seconds.

Returns

Key value pairs of blob tags.

Return type

<xref:Dict>[str, <xref:Union>[str, datetime, bool]]

set_premium_page_blob_tier

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
Required

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.

if_tags_match_condition
str

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.

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

set_sequence_number

Sets the blob sequence number.

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

Parameters

sequence_number_action
str
Required

This property indicates how the service should modify the blob's sequence number. See SequenceNumberAction for more information.

sequence_number
str
Required

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

if_tags_match_condition
str

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.

timeout
int

The timeout parameter is expressed in seconds.

Returns

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

Return type

dict(str, <xref:Any>)

set_standard_blob_tier

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
Required

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

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

if_tags_match_condition
str

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.

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

stage_block

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

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

Parameters

block_id
str
Required

A string value that identifies the block. The string should be less than or equal to 64 bytes in size. For a given blob, the block_id must be the same size for each block.

data
Required

The blob data.

length
int
Required

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

Returns

Blob property dict.

Return type

dict[str, <xref:Any>]

stage_block_from_url

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
Required

A string value that identifies the block. The string should be less than or equal to 64 bytes in size. For a given blob, the block_id must be the same size for each block.

source_url
str
Required

The URL.

source_offset
int
Required

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

source_length
int
Required

The size of the block in bytes.

source_content_md5
bytearray
Required

Specify the md5 calculated for the range of bytes that must be read from the copy source.

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.

source_authorization
str

Authenticate as a service principal using a client secret to access a source blob. Ensure "bearer " is the prefix of the source_authorization string.

Returns

Blob property dict.

Return type

dict[str, <xref:Any>]

start_copy_from_url

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
Required

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=

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

metadata
dict(str, str)
Required

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
Required

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.

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.

immutability_policy
ImmutabilityPolicy

Specifies the immutability policy of a blob, blob snapshot or blob version.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

legal_hold
bool

Specified if a legal hold should be set on the blob.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

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.

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.

source_authorization
str

Authenticate as a service principal using a client secret to access a source blob. Ensure "bearer " is the prefix of the source_authorization string. This option is only available when incremental_copy is set to False and requires_sync is set to True.

Returns

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

Return type

dict[str, <xref:Union>[str, datetime]]

Examples

Copy a blob from a URL.


   # Get the blob client with the source blob
   source_blob = "https://www.gutenberg.org/files/59466/59466-0.txt"
   copied_blob = blob_service_client.get_blob_client("copyblobcontainer", '59466-0.txt')

   # start copy and check copy status
   copy = copied_blob.start_copy_from_url(source_blob)
   props = copied_blob.get_blob_properties()
   print(props.copy.status)

undelete_blob

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
   blob_client.undelete_blob()

upload_blob

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
Required

The blob data to upload.

blob_type
BlobType
Required

The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob. The default value is BlockBlob.

length
int
Required

Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.

metadata
dict(str, str)
Required

Name-value pairs associated with the blob as metadata.

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
BlobLeaseClient or str

Required if the blob has an active lease. If specified, upload_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.

if_tags_match_condition
str

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.

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.

immutability_policy
ImmutabilityPolicy

Specifies the immutability policy of a blob, blob snapshot or blob version. Currently this parameter of upload_blob() API is for BlockBlob only.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

legal_hold
bool

Specified if a legal hold should be set on the blob. Currently this parameter of upload_blob() API is for BlockBlob only.

New in version 12.10.0: This was introduced in API version '2020-10-02'.

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, <xref:Any>]

Examples

Upload a blob to the container.


   # Upload content to block blob
   with open(SOURCE_FILE, "rb") as data:
       blob_client.upload_blob(data, blob_type="BlockBlob")

upload_blob_from_url

Creates a new Block Blob where the content of the blob is read from a given URL. The content of an existing blob is overwritten with the new blob.

upload_blob_from_url(source_url, **kwargs)

Parameters

source_url
str
Required

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=

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

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.

include_source_blob_properties
bool

Indicates if properties from the source blob should be copied. Defaults to True.

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 (_)

source_content_md5
bytearray

Specify the md5 that is used to verify the integrity of the source bytes.

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.

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.

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

timeout
int

The timeout parameter is expressed in seconds.

content_settings
ContentSettings

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

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.

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.

source_authorization
str

Authenticate as a service principal using a client secret to access a source blob. Ensure "bearer " is the prefix of the source_authorization string.

upload_page

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

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

Parameters

page
bytes
Required

Content of the page.

offset
int
Required

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
Required

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

if_tags_match_condition
str

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.

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, <xref:Any>)

upload_pages_from_url

The Upload Pages operation writes 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
Required

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
Required

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
Required

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
Required

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

if_tags_match_condition
str

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.

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.

source_authorization
str

Authenticate as a service principal using a client secret to access a source blob. Ensure "bearer " is the prefix of the source_authorization string.