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.StorageAccountHostsMixinBlobClientazure.storage.blob._encryption.StorageEncryptionMixinBlobClient
Constructor
BlobClient(account_url: str, container_name: str, blob_name: str, snapshot: Optional[Union[str, Dict[str, Any]]] = None, credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long = None, **kwargs: Any)
Parameters
- account_url
- str
The URI to the storage account. In order to create a client given the full URI to the blob, use the from_blob_url classmethod.
- blob_name
- str
The name of the blob with which to interact. If specified, this value will override a blob value specified in the blob URL.
- snapshot
- str
The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot.
- credential
The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential 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. If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key.
- api_version
- str
The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility.
New in version 12.2.0.
- secondary_hostname
- str
The hostname of the secondary endpoint.
- max_block_size
- int
The maximum chunk size for uploading a block blob in chunks.
Defaults to 4*1024*1024
, or 4MB.
- max_single_put_size
- int
If the blob size is less than or equal max_single_put_size, then the blob will be
uploaded with only one http PUT request. If the blob size is larger than max_single_put_size,
the blob will be uploaded in chunks. Defaults to 64*1024*1024
, or 64MB.
- min_large_block_upload_threshold
- int
The minimum chunk size required to use the memory efficient
algorithm when uploading a block blob. Defaults to 4*1024*1024
+1.
- use_byte_buffer
- bool
Use a byte buffer for block blob uploads. Defaults to False.
- max_page_size
- int
The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024
, or 4MB.
- max_single_get_size
- int
The maximum size for a blob to be downloaded in a single call,
the exceeded part will be downloaded in chunks (could be parallel). Defaults to 32*1024*1024
, or 32MB.
- max_chunk_get_size
- int
The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024
,
or 4MB.
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 |
DEPRECATED: Returns the list of valid page ranges for a Page Blob or snapshot of a page blob. |
list_page_ranges |
Returns the list of valid page ranges for a Page Blob or snapshot of a page blob. If previous_snapshot is specified, the result will be a diff of changes between the target blob and the previous snapshot. |
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 from the given URL. This operation returns a dictionary containing copy_status and copy_id, which can be used to check the status of or abort the copy operation. copy_status will be 'success' if the copy completed synchronously or 'pending' if the copy has been started asynchronously. For asynchronous copies, the status can be checked by polling the get_blob_properties method and checking the copy status. Set requires_sync to True to force the copy to be synchronous. 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. |
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: Union[str, Dict[str, Any], azure.storage.blob._models.BlobProperties], **kwargs: Any) -> None
Parameters
- copy_id
- str or BlobProperties
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
if props.copy.status != "success":
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: int = - 1, lease_id: Optional[str] = None, **kwargs: Any) -> azure.storage.blob._lease.BlobLeaseClient
Parameters
- lease_duration
- int
Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. Default is -1 (infinite lease).
- lease_id
- str
Proposed lease ID, in a GUID string format. The Blob Service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.
- if_modified_since
- datetime
A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
- if_unmodified_since
- datetime
A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
- 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: Union[bytes, str, Iterable[AnyStr], IO[AnyStr]], length: Optional[int] = None, **kwargs) -> Dict[str, Union[str, datetime, int]]
Parameters
Content of the block. This can be bytes, text, an iterable or a file-like object.
- 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.
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
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: str, source_offset: Optional[int] = None, source_length: Optional[int] = None, **kwargs) -> Dict[str, Union[str, datetime, int]]
Parameters
- copy_source_url
- str
The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.
- source_offset
- int
This indicates the start of the range of bytes (inclusive) that has to be taken from the copy source.
- source_length
- int
This indicates the end of the range of bytes that has to be taken from the copy source.
- source_content_md5
- bytearray
If given, the service will calculate the MD5 hash of the block content and compare against this value.
- maxsize_condition
- int
Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).
- appendpos_condition
- int
Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).
- 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.
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: int, length: int, **kwargs: Any) -> Dict[str, Union[str, datetime]]
Parameters
- offset
- int
Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- length
- int
Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- 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.
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
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: List[BlobBlock], content_settings: Optional[ContentSettings] = None, metadata: Optional[Dict[str, str]] = None, **kwargs) -> Dict[str, Union[str, datetime]]
Parameters
- content_settings
- ContentSettings
ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
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.
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
create_append_blob
Creates a new Append Blob.
create_append_blob(content_settings: Optional[ContentSettings] = None, metadata: Optional[Dict[str, str]] = None, **kwargs: Any) -> Dict[str, Union[str, datetime]]
Parameters
- content_settings
- ContentSettings
ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
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.
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
create_page_blob
Creates a new Page Blob of the specified size.
create_page_blob(size: int, content_settings: Optional[ContentSettings] = None, metadata: Optional[Dict[str, str]] = None, premium_page_blob_tier: Optional[Union[str, PremiumPageBlobTier]] = None, **kwargs) -> Dict[str, Union[str, datetime]]
Parameters
- size
- int
This specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned to a 512-byte boundary.
- content_settings
- ContentSettings
ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
- 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.
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.
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
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: Optional[Dict[str, str]] = None, **kwargs: Any) -> Dict[str, Union[str, datetime]]
Parameters
- 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.
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
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: str = None, **kwargs: Any) -> None
Parameters
- delete_snapshots
- str
Required if the blob has associated snapshots. Values include:
"only": Deletes only the blobs snapshots.
"include": Deletes the blob along with all snapshots.
- 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: Any) -> None
Parameters
- timeout
- int
The timeout parameter is expressed in seconds.
Returns
Key value pairs of blob tags.
Return type
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: int = None, length: int = None, *, encoding: str, **kwargs) -> StorageStreamDownloader[str]
Parameters
- offset
- int
Start of byte range to use for downloading a section of the blob. Must be set if length is provided.
- length
- int
Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
- 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.
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.
A callback to track the progress of a long running download. The signature is function(current: int, total: int) where current is the number of bytes transfered so far, and total is the total size of the download.
- 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: Any) -> bool
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: str, credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long = None, snapshot: Optional[Union[str, Dict[str, Any]]] = None, **kwargs: Any) -> ClassType
Parameters
- blob_url
- str
The full endpoint URL to the Blob, including SAS token and snapshot if used. This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode.
- credential
The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential 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. If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key.
- snapshot
- str
The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot. If specified, this will override the snapshot in the url.
Returns
A Blob client.
Return type
from_connection_string
Create BlobClient from a Connection String.
from_connection_string(conn_str: str, container_name: str, blob_name: str, snapshot: Optional[str] = None, credential: Optional[Union[str, Dict[str, str], AzureNamedKeyCredential, AzureSasCredential, "TokenCredential"]] # pylint: disable=line-too-long = None, **kwargs: Any) -> ClassType
Parameters
- snapshot
- str
The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot.
- credential
The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential 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. If using an instance of AzureNamedKeyCredential, "name" should be the storage account name, and "key" should be the storage account key.
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: Any) -> Dict[str, str]
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: Any) -> azure.storage.blob._models.BlobProperties
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.
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: Any) -> Dict[str, str]
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
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: Optional[str] = 'committed', **kwargs: Any) -> Tuple[List[azure.storage.blob._models.BlobBlock], List[azure.storage.blob._models.BlobBlock]]
Parameters
- block_list_type
- str
Specifies whether to return the list of committed blocks, the list of uncommitted blocks, or both lists together. Possible values include: 'committed', 'uncommitted', 'all'
- lease
- 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: str, offset: Optional[int] = None, length: Optional[int] = None, **kwargs) -> Tuple[List[Dict[str, int]], List[Dict[str, int]]]
Parameters
- previous_snapshot_url
Specifies the URL of a previous snapshot of the managed disk. The response will only contain pages that were changed between the target blob and its previous snapshot.
- offset
- int
Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- length
- int
Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- 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
DEPRECATED: Returns the list of valid page ranges for a Page Blob or snapshot of a page blob.
get_page_ranges(offset: Optional[int] = None, length: Optional[int] = None, previous_snapshot_diff: Optional[Union[str, Dict[str, Any]]] = None, **kwargs) -> Tuple[List[Dict[str, int]], List[Dict[str, int]]]
Parameters
- offset
- int
Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- length
- int
Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- previous_snapshot_diff
- str
The snapshot diff parameter that contains an opaque DateTime value that specifies a previous blob snapshot to be compared against a more recent snapshot or the current blob.
- 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
list_page_ranges
Returns the list of valid page ranges for a Page Blob or snapshot of a page blob. If previous_snapshot is specified, the result will be a diff of changes between the target blob and the previous snapshot.
list_page_ranges(*, offset: Optional[int] = None, length: Optional[int] = None, previous_snapshot: Optional[Union[str, Dict[str, Any]]] = None, **kwargs: Any) -> azure.core.paging.ItemPaged[azure.storage.blob._models.PageRange]
Parameters
- offset
- int
Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- length
- int
Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
A snapshot value that specifies that the response will contain only pages that were changed between target blob and previous snapshot. Changed pages include both updated and cleared pages. The target blob may be a snapshot, as long as the snapshot specified by previous_snapshot is the older of the two.
- 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.
- results_per_page
- int
The maximum number of page ranges to retrieve per API call.
- timeout
- int
The timeout parameter is expressed in seconds.
Returns
An iterable (auto-paging) of PageRange.
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: str, **kwargs: Any) -> azure.storage.blob._quick_query_helper.BlobQueryReader
Parameters
- 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.
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: int, **kwargs: Any) -> Dict[str, Union[str, datetime]]
Parameters
- size
- int
Size used to resize blob. Maximum size for a page blob is up to 1 TB. The page blob size must be aligned to a 512-byte boundary.
- 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
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) -> Dict[str, Union[str, datetime, int]]
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
set_blob_metadata
Sets user-defined metadata for the blob as one or more name-value pairs.
set_blob_metadata(metadata: Optional[Dict[str, str]] = None, **kwargs: Any) -> Dict[str, Union[str, datetime]]
Parameters
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.
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: Optional[Dict[str, str]] = None, **kwargs: Any) -> Dict[str, Any]
Parameters
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
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: Optional[ContentSettings] = None, **kwargs: Any) -> None
Parameters
- content_settings
- ContentSettings
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
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: ImmutabilityPolicy, **kwargs: Any) -> Dict[str, str]
Parameters
- 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'.
- timeout
- int
The timeout parameter is expressed in seconds.
Returns
Key value pairs of blob tags.
Return type
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_legal_hold(legal_hold: bool, **kwargs: Any) -> Dict[str, Union[str, datetime, bool]]
Parameters
- timeout
- int
The timeout parameter is expressed in seconds.
Returns
Key value pairs of blob tags.
Return type
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: Union[str, PremiumPageBlobTier], **kwargs: Any) -> None
Parameters
- premium_page_blob_tier
- PremiumPageBlobTier
A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
- 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: Union[str, SequenceNumberAction], sequence_number: Optional[str] = None, **kwargs: Any) -> Dict[str, Union[str, datetime]]
Parameters
- sequence_number_action
- str
This property indicates how the service should modify the blob's sequence number. See SequenceNumberAction for more information.
- sequence_number
- str
This property sets the blob's sequence number. The sequence number is a user-controlled property that you can use to track requests and manage concurrency issues.
- lease
- 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
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: Union[str, StandardBlobTier], **kwargs: Any) -> None
Parameters
- standard_blob_tier
- str or StandardBlobTier
Indicates the tier to be set on the blob. Options include 'Hot', 'Cool', 'Archive'. The hot tier is optimized for storing data that is accessed frequently. The cool storage tier is optimized for storing data that is infrequently accessed and stored for at least a month. The archive tier is optimized for storing data that is rarely accessed and stored for at least six months with flexible latency requirements.
- rehydrate_priority
- RehydratePriority
Indicates the priority with which to rehydrate an archived blob
- 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: str, data: Union[Iterable, IO], length: Optional[int] = None, **kwargs) -> Dict[str, Any]
Parameters
- block_id
- str
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
The blob data.
- 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.
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
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: Union[str, int], source_url: str, source_offset: Optional[int] = None, source_length: Optional[int] = None, source_content_md5: Optional[Union[bytes, bytearray]] = None, **kwargs) -> Dict[str, Any]
Parameters
- block_id
- str
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_offset
- int
Start of byte range to use for the block. Must be set if source length is provided.
- source_content_md5
- bytearray
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.
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
start_copy_from_url
Copies a blob from the given URL.
This operation returns a dictionary containing copy_status and copy_id, which can be used to check the status of or abort the copy operation. copy_status will be 'success' if the copy completed synchronously or 'pending' if the copy has been started asynchronously. For asynchronous copies, the status can be checked by polling the get_blob_properties method and checking the copy status. Set requires_sync to True to force the copy to be synchronous. 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.
start_copy_from_url(source_url: str, metadata: Optional[Dict[str, str]] = None, incremental_copy: bool = False, **kwargs: Any) -> Dict[str, Union[str, datetime]]
Parameters
- source_url
- str
A URL of up to 2 KB in length that specifies a file or blob. The value should be URL-encoded as it would appear in a request URI. If the source is in another account, the source must either be public or must be authenticated via a shared access signature. If the source is public, no authentication is required. Examples: https://myaccount.blob.core.windows.net/mycontainer/myblob
https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=
https://otheraccount.blob.core.windows.net/mycontainer/myblob?sastoken
Name-value pairs associated with the blob as metadata. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob or file.
- incremental_copy
- bool
Copies the snapshot of the source page blob to a destination page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. Defaults to False.
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 (_).
The (case-sensitive) literal "COPY" can instead be passed to copy tags from the source blob. This option is only available when incremental_copy=False and requires_sync=True.
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.
New in version 12.9.0.
- encryption_scope
- str
A predefined encryption scope used to encrypt the data on the sync copied blob. 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.10.0.
Returns
A dictionary of copy properties (etag, last_modified, copy_id, copy_status).
Return type
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: Any) -> None
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: Union[bytes, str, Iterable, IO], blob_type: Union[str, azure.storage.blob._models.BlobType] = <BlobType.BLOCKBLOB: 'BlockBlob'>, length: Optional[int] = None, metadata: Optional[Dict[str, str]] = None, **kwargs) -> Any
Parameters
- data
The blob data to upload.
- blob_type
- BlobType
The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob. The default value is BlockBlob.
- length
- int
Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
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.
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.
A callback to track the progress of a long running upload. The signature is function(current: int, total: Optional[int]) where current is the number of bytes transfered so far, and total is the size of the blob or None if the size is unknown.
- 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
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: str, **kwargs: Any) -> Dict[str, Any]
Parameters
- source_url
- str
A URL of up to 2 KB in length that specifies a file or blob. The value should be URL-encoded as it would appear in a request URI. If the source is in another account, the source must either be public or must be authenticated via a shared access signature. If the source is public, no authentication is required. Examples: https://myaccount.blob.core.windows.net/mycontainer/myblob
https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=
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.
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.
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: bytes, offset: int, length: int, **kwargs) -> Dict[str, Union[str, datetime]]
Parameters
- offset
- int
Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- length
- int
Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- 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.
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
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: str, offset: int, length: int, source_offset: int, **kwargs) -> Dict[str, Any]
Parameters
- source_url
- str
The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.
- offset
- int
Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- length
- int
Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- source_offset
- int
This indicates the start of the range of bytes(inclusive) that has to be taken from the copy source. The service will read the same number of bytes as the destination range (length-offset).
- 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.
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.
Feedback
Submit and view feedback for