azure.storage.blob.appendblobservice module

class azure.storage.blob.appendblobservice.AppendBlobService(account_name=None, account_key=None, sas_token=None, is_emulated=False, protocol='https', endpoint_suffix='core.windows.net', custom_domain=None, request_session=None, connection_string=None, socket_timeout=None)[source]

Bases: azure.storage.blob.baseblobservice.BaseBlobService

An append blob is comprised of blocks and is optimized for append operations. When you modify an append blob, blocks are added to the end of the blob only, via the append_block operation. Updating or deleting of existing blocks is not supported. Unlike a block blob, an append blob does not expose its block IDs.

Each block in an append blob can be a different size, up to a maximum of 4 MB, and an append blob can include up to 50,000 blocks. The maximum size of an append blob is therefore slightly more than 195 GB (4 MB X 50,000 blocks).

Variables:

MAX_BLOCK_SIZE (int) – The size of the blocks put by append_blob_from_* methods. Smaller blocks may be put if there is less data provided. The maximum block size the service supports is 4MB.

Parameters:
  • account_name (str) – The storage account name. This is used to authenticate requests signed with an account key and to construct the storage endpoint. It is required unless a connection string is given, or if a custom domain is used with anonymous authentication.
  • account_key (str) – The storage account key. This is used for shared key authentication. If neither account key or sas token is specified, anonymous access will be used.
  • sas_token (str) – A shared access signature token to use to authenticate requests instead of the account key. If account key and sas token are both specified, account key will be used to sign. If neither are specified, anonymous access will be used.
  • is_emulated (bool) – Whether to use the emulator. Defaults to False. If specified, will override all other parameters besides connection string and request session.
  • protocol (str) – The protocol to use for requests. Defaults to https.
  • endpoint_suffix (str) – The host base component of the url, minus the account name. Defaults to Azure (core.windows.net). Override this to use the China cloud (core.chinacloudapi.cn).
  • custom_domain (str) – The custom domain to use. This can be set in the Azure Portal. For example, ‘www.mydomain.com’.
  • request_session (requests.Session) – The session object to use for http requests.
  • connection_string (str) – If specified, this will override all other parameters besides request session. See http://azure.microsoft.com/en-us/documentation/articles/storage-configure-connection-string/ for the connection string format.
  • socket_timeout (int) – If specified, this will override the default socket timeout. The timeout specified is in seconds. See DEFAULT_SOCKET_TIMEOUT in _constants.py for the default value.
MAX_BLOCK_SIZE = 4194304
append_blob_from_bytes(container_name, blob_name, blob, index=0, count=None, validate_content=False, maxsize_condition=None, progress_callback=None, lease_id=None, timeout=None)[source]

Appends to the content of an existing blob from an array of bytes, with automatic chunking and progress notifications.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of blob to create or update.
  • blob (bytes) – Content of blob as an array of bytes.
  • index (int) – Start index in the array of bytes.
  • count (int) – Number of bytes to upload. Set to None or negative value to upload all bytes starting from index.
  • 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.
  • 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).
  • progress_callback (callback function in format of func(current, total)) – Callback for progress with signature function(current, total) where current is the number of bytes transfered so far, and total is the size of the blob, or None if the total size is unknown.
  • lease_id (str) – Required if the blob has an active lease.
  • 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.
append_blob_from_path(container_name, blob_name, file_path, validate_content=False, maxsize_condition=None, progress_callback=None, lease_id=None, timeout=None)[source]

Appends to the content of an existing blob from a file path, with automatic chunking and progress notifications.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of blob to create or update.
  • file_path (str) – Path of the file to upload as the blob content.
  • 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.
  • 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).
  • progress_callback (callback function in format of func(current, total)) – Callback for progress with signature function(current, total) where current is the number of bytes transfered so far, and total is the size of the blob, or None if the total size is unknown.
  • lease_id (str) – Required if the blob has an active lease.
  • 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.
append_blob_from_stream(container_name, blob_name, stream, count=None, validate_content=False, maxsize_condition=None, progress_callback=None, lease_id=None, timeout=None)[source]

Appends to the content of an existing blob from a file/stream, with automatic chunking and progress notifications.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of blob to create or update.
  • stream (io.IOBase) – Opened stream to upload as the blob content.
  • count (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
  • validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the blob.
  • maxsize_condition (int) – 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).
  • progress_callback (callback function in format of func(current, total)) – Callback for progress with signature function(current, total) where current is the number of bytes transfered so far, and total is the size of the blob, or None if the total size is unknown.
  • lease_id (str) – Required if the blob has an active lease.
  • 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.
append_blob_from_text(container_name, blob_name, text, encoding='utf-8', validate_content=False, maxsize_condition=None, progress_callback=None, lease_id=None, timeout=None)[source]

Appends to the content of an existing blob from str/unicode, with automatic chunking and progress notifications.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of blob to create or update.
  • text (str) – Text to upload to the blob.
  • encoding (str) – Python encoding to use to convert the text to bytes.
  • 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.
  • 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).
  • progress_callback (callback function in format of func(current, total)) – Callback for progress with signature function(current, total) where current is the number of bytes transfered so far, and total is the size of the blob, or None if the total size is unknown.
  • lease_id (str) – Required if the blob has an active lease.
  • 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.
append_block(container_name, blob_name, block, validate_content=False, maxsize_condition=None, appendpos_condition=None, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

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

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • block (bytes) – Content of the block in bytes.
  • validate_content (bool) – If true, calculates an MD5 hash of the block content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the blob.
  • maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).
  • appendpos_condition (int) – Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).
  • lease_id (str) – Required if the blob has an active lease.
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
  • if_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag matches the value specified.
  • if_none_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag does not match the value specified. Specify the wildcard character (*) to perform the operation only if the resource does not exist, and fail the operation if it does exist.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

ETag, last modified, append offset, and committed block count properties for the updated Append Blob

Return type:

AppendBlockProperties

create_blob(container_name, blob_name, content_settings=None, metadata=None, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Creates a blob or overrides an existing blob. Use if_match=* to prevent overriding an existing blob.

See create_blob_from_* for high level functions that handle the creation and upload of large blobs with automatic chunking and progress notifications.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of blob to create or update.
  • content_settings (ContentSettings) – ContentSettings object used to set blob properties.
  • metadata (a dict mapping str to str) – Name-value pairs associated with the blob as metadata.
  • lease_id (str) – Required if the blob has an active lease.
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
  • if_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag matches the value specified.
  • if_none_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag does not match the value specified. Specify the wildcard character (*) to perform the operation only if the resource does not exist, and fail the operation if it does exist.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

ETag and last modified properties for the updated Append Blob

Return type:

ResourceProperties