BlobClient class

Definition

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

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

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(blob_url, credential=None, snapshot=None, **kwargs) classmethod.

container_name
str

The container name for the blob.

blob_name
str

The name of the blob with which to interact. If specified, this value will override a blob value specified in the blob URL.

snapshot
str

The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot(metadata=None, **kwargs).

credential

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

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(name_starts_with=None, include=None, **kwargs) specifying include=['deleted'] option. Soft-deleted blob can be restored using <xref:azure.storage.blob.undelete> operation.

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.

from_blob_url

Create BlobClient from a blob url.

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_block_list

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

get_page_range_diff_for_managed_disk

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

Note

This operation is only available for managed disk accounts.

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

get_page_ranges

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

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.

set_blob_metadata

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

set_http_headers

Sets system properties on the blob.

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

set_premium_page_blob_tier

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

set_sequence_number

Sets the blob sequence number.

set_standard_blob_tier

This operation sets the tier on a block blob.

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

stage_block

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

stage_block_from_url

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

start_copy_from_url

Copies a blob asynchronously.

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

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

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

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

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

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

undelete_blob

Restores soft-deleted blobs or snapshots.

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

upload_blob

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

upload_page

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

upload_pages_from_url

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

abort_copy

Abort an ongoing copy operation.

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

abort_copy(copy_id, **kwargs)

Parameters

copy_id
str or BlobProperties
Required

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

Return type

None

Examples

Abort copying a blob from URL.


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

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

acquire_lease

Requests a new lease.

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

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

Parameters

lease_duration
int
Required

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

lease_id
str
Required

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

Returns

A BlobLeaseClient object.

Return type

Examples

Acquiring a lease on a blob.


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

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

append_block

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

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

Parameters

data
bytes or str or Iterable
Required

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

length
int
Required

Size of the block in bytes.

Returns

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

Return type

dict(str, Any)

append_block_from_url

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

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

Parameters

copy_source_url
str
Required

The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.

source_offset
int
Required

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

source_length
int
Required

This indicates the end of the range of bytes that has to be taken from the copy source.

clear_page

Clears a range of pages.

clear_page(offset, length, **kwargs)

Parameters

offset
int
Required

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

length
int
Required

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

Returns

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

Return type

dict(str, Any)

commit_block_list

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

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

Parameters

block_list
list
Required

List of Blockblobs.

content_settings
ContentSettings
Required

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

metadata
dict[str, str]
Required

Name-value pairs associated with the blob as metadata.

Returns

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

Return type

dict(str, Any)

create_append_blob

Creates a new Append Blob.

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

Parameters

content_settings
ContentSettings
Required

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

metadata
dict(str, str)
Required

Name-value pairs associated with the blob as metadata.

Returns

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

Return type

dict[str, Any]

create_page_blob

Creates a new Page Blob of the specified size.

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

Parameters

size
int
Required

This specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned to a 512-byte boundary.

content_settings
ContentSettings
Required

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

metadata
dict(str, str)
Required

Name-value pairs associated with the blob as metadata.

premium_page_blob_tier
PremiumPageBlobTier
Required

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

Returns

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

Return type

dict[str, Any]

create_snapshot

Creates a snapshot of the blob.

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

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

create_snapshot(metadata=None, **kwargs)

Parameters

metadata
dict(str, str)
Required

Name-value pairs associated with the blob as metadata.

Returns

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

Return type

dict[str, Any]

Examples

Create a snapshot of the blob.


   # Create a read-only snapshot of the blob at this point in time
   snapshot_blob = 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(name_starts_with=None, include=None, **kwargs) specifying include=['deleted'] option. Soft-deleted blob can be restored using <xref:azure.storage.blob.undelete> operation.

delete_blob(delete_snapshots=False, **kwargs)

Parameters

delete_snapshots
str
Required

Required if the blob has associated snapshots. Values include:

  • "only": Deletes only the blobs snapshots.

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

Return type

None

Examples

Delete a blob.


   blob_client.delete_blob()

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.

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

Parameters

offset
int
Required

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

length
int
Required

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

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

from_blob_url

Create BlobClient from a blob url.

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

Parameters

blob_url
str
Required

The full endpoint URL to the Blob, including SAS token and snapshot if used. This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode.

credential
Required

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

snapshot
str
default value: None

The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot(metadata=None, **kwargs). If specified, this will override the snapshot in the url.

snapshot
default value: None

Returns

A Blob client.

Return type

from_connection_string

Create BlobClient from a Connection String.

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

Parameters

conn_str
str
Required

A connection string to an Azure Storage account.

container_name
str
Required

The container name for the blob.

blob_name
str
Required

The name of the blob with which to interact.

snapshot
str
Required

The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from create_snapshot(metadata=None, **kwargs).

credential
default value: None

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

credential
default value: None

Returns

A Blob client.

Return type

Examples

Creating the BlobClient from a connection string.


   from azure.storage.blob import BlobClient
   blob_client = BlobClient.from_connection_string(
       self.connection_string, container_name="mycontainer", blob_name="blobname.txt")

get_account_information

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

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

get_account_information(**kwargs)

Returns

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

Return type

dict(str, str)

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)

Returns

BlobProperties

Return type

Examples

Getting the properties for a blob.


   properties = blob_client.get_blob_properties()

get_block_list

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

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

Parameters

block_list_type
str
Required

Specifies whether to return the list of committed blocks, the list of uncommitted blocks, or both lists together. Possible values include: 'committed', 'uncommitted', 'all'

Returns

A tuple of two lists - committed and uncommitted blocks

Return type

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

get_page_range_diff_for_managed_disk

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

Note

This operation is only available for managed disk accounts.

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

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

Parameters

previous_snapshot_url
Required

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

offset
int
Required

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

length
int
Required

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

Returns

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

Return type

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

get_page_ranges

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

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

Parameters

offset
int
Required

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

length
int
Required

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

previous_snapshot_diff
str
Required

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

Returns

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

Return type

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

resize_blob

Resizes a page blob to the specified size.

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

resize_blob(size, **kwargs)

Parameters

size
int
Required

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

Returns

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

Return type

dict(str, Any)

set_blob_metadata

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

set_blob_metadata(metadata=None, **kwargs)

Parameters

metadata
dict(str, str)
Required

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

Returns

Blob-updated property dict (Etag and last modified)

set_http_headers

Sets system properties on the blob.

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

set_http_headers(content_settings=None, **kwargs)

Parameters

content_settings
ContentSettings
Required

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

Returns

Blob-updated property dict (Etag and last modified)

Return type

Dict[str, Any]

set_premium_page_blob_tier

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

set_premium_page_blob_tier(premium_page_blob_tier, **kwargs)

Parameters

premium_page_blob_tier
PremiumPageBlobTier
Required

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

Return type

None

set_sequence_number

Sets the blob sequence number.

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

Parameters

sequence_number_action
str
Required

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

sequence_number
str
Required

This property sets the blob's sequence number. The sequence number is a user-controlled property that you can use to track requests and manage concurrency issues.

Returns

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

Return type

dict(str, Any)

set_standard_blob_tier

This operation sets the tier on a block blob.

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

set_standard_blob_tier(standard_blob_tier, **kwargs)

Parameters

standard_blob_tier
str or StandardBlobTier
Required

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

Return type

None

stage_block

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

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

Parameters

block_id
str
Required

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

data
Required

The blob data.

length
int
Required

Size of the block.

Returns

Blob property dict.

Return type

dict[str, Any]

stage_block_from_url

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

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

Parameters

block_id
str
Required

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

source_url
str
Required

The URL.

source_offset
int
Required

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

source_length
int
Required

The size of the block in bytes.

source_content_md5
bytearray
Required

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

Returns

Blob property dict.

Return type

dict[str, Any]

start_copy_from_url

Copies a blob asynchronously.

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

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

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

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

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

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

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

Parameters

source_url
str
Required

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

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

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

metadata
dict(str, str)
Required

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

incremental_copy
bool
Required

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

Returns

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

Return type

dict[str, str
datetime.datetime]

Examples

Copy a blob from a URL.


   # Get the blob client with the source blob
   source_blob = "http://www.gutenberg.org/files/59466/59466-0.txt"
   copied_blob = blob_service_client.get_blob_client("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)

Return type

None

Examples

Undeleting a blob.


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

upload_blob

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

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

Parameters

data
Required

The blob data to upload.

blob_type
BlobType
Required

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

length
int
Required

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

metadata
dict(str, str)
Required

Name-value pairs associated with the blob as metadata.

Returns

Blob-updated property dict (Etag and last modified)

Return type

dict[str, Any]

Examples

Upload a blob to the container.


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

upload_page

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

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

Parameters

page
bytes
Required

Content of the page.

offset
int
Required

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

length
int
Required

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

Returns

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

Return type

dict(str, Any)

upload_pages_from_url

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

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

Parameters

source_url
str
Required

The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.

offset
int
Required

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

length
int
Required

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

source_offset
int
Required

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