azure.storage.blob.baseblobservice module

class azure.storage.blob.baseblobservice.BaseBlobService(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.common.storageclient.StorageClient

This is the main class managing Blob resources.

The Blob service stores text and binary data as blobs in the cloud. The Blob service offers the following three resources: the storage account, containers, and blobs. Within your storage account, containers provide a way to organize sets of blobs. For more information please see: https://msdn.microsoft.com/en-us/library/azure/ee691964.aspx

Variables:
  • MAX_SINGLE_GET_SIZE (int) – The size of the first range get performed by get_blob_to_* methods if max_connections is greater than 1. Less data will be returned if the blob is smaller than this.
  • MAX_CHUNK_GET_SIZE (int) – The size of subsequent range gets performed by get_blob_to_* methods if max_connections is greater than 1 and the blob is larger than MAX_SINGLE_GET_SIZE. Less data will be returned if the remainder of the blob is smaller than this. If this is set to larger than 4MB, content_validation will throw an error if enabled. However, if content_validation is not desired a size greater than 4MB may be optimal. Setting this below 4MB is not recommended.
  • key_encryption_key (object) – The key-encryption-key optionally provided by the user. If provided, will be used to encrypt/decrypt in supported methods. For methods requiring decryption, either the key_encryption_key OR the resolver must be provided. If both are provided, the resolver will take precedence. Must implement the following methods for APIs requiring encryption: wrap_key(key)–wraps the specified key (bytes) using an algorithm of the user’s choice. Returns the encrypted key as bytes. get_key_wrap_algorithm()–returns the algorithm used to wrap the specified symmetric key. get_kid()–returns a string key id for this key-encryption-key. Must implement the following methods for APIs requiring decryption: unwrap_key(key, algorithm)–returns the unwrapped form of the specified symmetric key using the string-specified algorithm. get_kid()–returns a string key id for this key-encryption-key.
  • key_resolver_function(kid) (function) – A function to resolve keys optionally provided by the user. If provided, will be used to decrypt in supported methods. For methods requiring decryption, either the key_encryption_key OR the resolver must be provided. If both are provided, the resolver will take precedence. It uses the kid string to return a key-encryption-key implementing the interface defined above.
  • require_encryption (bool) – A flag that may be set to ensure that all messages successfully uploaded to the queue and all those downloaded and successfully read from the queue are/were encrypted while on the server. If this flag is set, all required parameters for encryption/decryption must be provided. See the above comments on the key_encryption_key and resolver.
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_CHUNK_GET_SIZE = 4194304
MAX_SINGLE_GET_SIZE = 33554432
abort_copy_blob(container_name, blob_name, copy_id, lease_id=None, timeout=None)[source]

Aborts a pending copy_blob operation, and leaves a destination blob with zero length and full metadata.

Parameters:
  • container_name (str) – Name of destination container.
  • blob_name (str) – Name of destination blob.
  • copy_id (str) – Copy identifier provided in the copy.id of the original copy_blob operation.
  • lease_id (str) – Required if the destination blob has an active infinite lease.
  • timeout (int) – The timeout parameter is expressed in seconds.
acquire_blob_lease(container_name, blob_name, lease_duration=-1, proposed_lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

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

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • 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).
  • proposed_lease_id (str) – Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
  • if_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag matches the value specified.
  • if_none_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag does not match the value specified. Specify the wildcard character (*) to perform the operation only if the resource does not exist, and fail the operation if it does exist.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

the lease ID of the newly created lease.

Returns:

str

acquire_container_lease(container_name, lease_duration=-1, proposed_lease_id=None, if_modified_since=None, if_unmodified_since=None, timeout=None)[source]

Requests a new lease. If the container does not have an active lease, the Blob service creates a lease on the container and returns a new lease ID.

Parameters:
  • container_name (str) – Name of existing container.
  • 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).
  • proposed_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.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

the lease ID of the newly created lease.

Returns:

str

break_blob_lease(container_name, blob_name, lease_break_period=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Breaks the lease, if the blob has an active lease. Once a lease is broken, it cannot be renewed. Any authorized request can break the lease; the request is not required to specify a matching lease ID. When a lease is broken, the lease break period is allowed to elapse, during which time no lease operation except break and release can be performed on the blob. When a lease is successfully broken, the response indicates the interval in seconds until a new lease can be acquired.

A lease that has been broken can also be released, in which case another client may immediately acquire the lease on the blob.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • lease_break_period (int) – For a break operation, this is the proposed duration of seconds that the lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be available before the break period has expired, but the lease may be held for longer than the break period. If this header does not appear with a break operation, a fixed-duration lease breaks after the remaining lease period elapses, and an infinite lease breaks immediately.
  • 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:

Approximate time remaining in the lease period, in seconds.

Returns:

int

break_container_lease(container_name, lease_break_period=None, if_modified_since=None, if_unmodified_since=None, timeout=None)[source]

Break the lease, if the container has an active lease. Once a lease is broken, it cannot be renewed. Any authorized request can break the lease; the request is not required to specify a matching lease ID. When a lease is broken, the lease break period is allowed to elapse, during which time no lease operation except break and release can be performed on the container. When a lease is successfully broken, the response indicates the interval in seconds until a new lease can be acquired.

Parameters:
  • container_name (str) – Name of existing container.
  • lease_break_period (int) – This is the proposed duration of seconds that the lease should continue before it is broken, between 0 and 60 seconds. This break period is only used if it is shorter than the time remaining on the lease. If longer, the time remaining on the lease is used. A new lease will not be available before the break period has expired, but the lease may be held for longer than the break period. If this header does not appear with a break operation, a fixed-duration lease breaks after the remaining lease period elapses, and an infinite lease breaks immediately.
  • 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.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

Approximate time remaining in the lease period, in seconds.

Returns:

int

change_blob_lease(container_name, blob_name, lease_id, proposed_lease_id, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Changes the lease ID of an active lease. A change must include the current lease ID and a new lease ID.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • lease_id (str) – Required if the blob has an active lease.
  • proposed_lease_id (str) – Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
  • if_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag matches the value specified.
  • if_none_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag does not match the value specified. Specify the wildcard character (*) to perform the operation only if the resource does not exist, and fail the operation if it does exist.
  • timeout (int) – The timeout parameter is expressed in seconds.
change_container_lease(container_name, lease_id, proposed_lease_id, if_modified_since=None, if_unmodified_since=None, timeout=None)[source]

Change the lease ID of an active lease. A change must include the current lease ID and a new lease ID.

Parameters:
  • container_name (str) – Name of existing container.
  • lease_id (str) – Lease ID for active lease.
  • proposed_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.
  • timeout (int) – The timeout parameter is expressed in seconds.
copy_blob(container_name, blob_name, copy_source, metadata=None, source_if_modified_since=None, source_if_unmodified_since=None, source_if_match=None, source_if_none_match=None, destination_if_modified_since=None, destination_if_unmodified_since=None, destination_if_match=None, destination_if_none_match=None, destination_lease_id=None, source_lease_id=None, timeout=None)[source]

Copies a blob asynchronously. This operation returns a copy operation properties object, including a copy ID you can use to check 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 get_blob_properties on the destination blob to check the status of the copy operation. The final blob will be committed when the copy completes.

Parameters:
  • container_name (str) – Name of the destination container. The container must exist.
  • blob_name (str) – Name of the destination blob. If the destination blob exists, it will be overwritten. Otherwise, it will be created.
  • copy_source (str) – A URL of up to 2 KB in length that specifies an Azure file or blob. The value should be URL-encoded as it would appear in a request URI. If the source is in another account, the source must either be public or must be authenticated via a shared access signature. If the source is public, no authentication is required. Examples: https://myaccount.blob.core.windows.net/mycontainer/myblob https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<DateTime> https://otheraccount.blob.core.windows.net/mycontainer/myblob?sastoken
  • metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata. If no name-value pairs are specified, the operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source blob or file.
  • source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has been modified since the specified date/time.
  • source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has not been modified since the specified date/time.
  • source_if_match (ETag) – An ETag value, or the wildcard character (*). Specify this conditional header to copy the source blob only if its ETag matches the value specified. If the ETag values do not match, the Blob service returns status code 412 (Precondition Failed). This header cannot be specified if the source is an Azure File.
  • source_if_none_match (ETag) – An ETag value, or the wildcard character (*). Specify this conditional header to copy the blob only if its ETag does not match the value specified. If the values are identical, the Blob service returns status code 412 (Precondition Failed). This header cannot be specified if the source is an Azure File.
  • destination_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the destination blob has been modified since the specified date/time. If the destination blob has not been modified, the Blob service returns status code 412 (Precondition Failed).
  • destination_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the destination blob has not been modified since the specified date/time. If the destination blob has been modified, the Blob service returns status code 412 (Precondition Failed).
  • destination_if_match (ETag) – An ETag value, or the wildcard character (*). Specify an ETag value for this conditional header to copy the blob only if the specified ETag value matches the ETag value for an existing destination blob. If the ETag for the destination blob does not match the ETag specified for If-Match, the Blob service returns status code 412 (Precondition Failed).
  • destination_if_none_match (ETag) – An ETag value, or the wildcard character (*). Specify an ETag value for this conditional header to copy the blob only if the specified ETag value does not match the ETag value for the destination blob. Specify the wildcard character (*) to perform the operation only if the destination blob does not exist. If the specified condition isn’t met, the Blob service returns status code 412 (Precondition Failed).
  • destination_lease_id (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_id (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.
Returns:

Copy operation properties such as status, source, and ID.

Return type:

CopyProperties

create_container(container_name, metadata=None, public_access=None, fail_on_exist=False, timeout=None)[source]

Creates a new container under the specified account. If the container with the same name already exists, the operation fails if fail_on_exist is True.

Parameters:
  • container_name (str) – Name of container to create.
  • metadata (dict(str, str)) – A dict with name_value pairs to associate with the container as metadata. Example:{‘Category’:’test’}
  • public_access (PublicAccess) – Possible values include: container, blob.
  • fail_on_exist (bool) – Specify whether to throw an exception when the container exists.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

True if container is created, False if container already exists.

Return type:

bool

delete_blob(container_name, blob_name, snapshot=None, lease_id=None, delete_snapshots=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Marks the specified blob or snapshot 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.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • snapshot (str) – The snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to delete.
  • lease_id (str) – Required if the blob has an active lease.
  • delete_snapshots (DeleteSnapshot) – Required if the blob has associated snapshots.
  • 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.
delete_container(container_name, fail_not_exist=False, lease_id=None, if_modified_since=None, if_unmodified_since=None, timeout=None)[source]

Marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection.

Parameters:
  • container_name (str) – Name of container to delete.
  • fail_not_exist (bool) – Specify whether to throw an exception when the container doesn’t exist.
  • lease_id (str) – If specified, delete_container only succeeds if the container’s lease is active and matches this ID. Required if the container 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.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

True if container is deleted, False container doesn’t exist.

Return type:

bool

exists(container_name, blob_name=None, snapshot=None, timeout=None)[source]

Returns a boolean indicating whether the container exists (if blob_name is None), or otherwise a boolean indicating whether the blob exists.

Parameters:
  • container_name (str) – Name of a container.
  • blob_name (str) – Name of a blob. If None, the container will be checked for existence.
  • snapshot (str) – The snapshot parameter is an opaque DateTime value that, when present, specifies the snapshot.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

A boolean indicating whether the resource exists.

Return type:

bool

generate_account_shared_access_signature(resource_types, permission, expiry, start=None, ip=None, protocol=None)[source]

Generates a shared access signature for the blob service. Use the returned signature with the sas_token parameter of any BlobService.

Parameters:
  • resource_types (ResourceTypes) – Specifies the resource types that are accessible with the account SAS.
  • permission (AccountPermissions) – The permissions associated with the shared access signature. The user is restricted to operations allowed by the permissions. Required unless an id is given referencing a stored access policy which contains this field. This field must be omitted if it has been specified in an associated stored access policy.
  • expiry (datetime or str) – The time at which the shared access signature becomes invalid. Required unless an id is given referencing a stored access policy which contains this field. This field must be omitted if it has been specified in an associated stored access policy. Azure will always convert values to UTC. If a date is passed in without timezone info, it is assumed to be UTC.
  • start (datetime or str) – The time at which the shared access signature becomes valid. If omitted, start time for this call is assumed to be the time when the storage service receives the request. Azure will always convert values to UTC. If a date is passed in without timezone info, it is assumed to be UTC.
  • ip (str) – Specifies an IP address or a range of IP addresses from which to accept requests. If the IP address from which the request originates does not match the IP address or address range specified on the SAS token, the request is not authenticated. For example, specifying sip=168.1.5.65 or sip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses.
  • protocol (str) – Specifies the protocol permitted for a request made. The default value is https,http. See Protocol for possible values.
Returns:

A Shared Access Signature (sas) token.

Return type:

str

generate_blob_shared_access_signature(container_name, blob_name, permission=None, expiry=None, start=None, id=None, ip=None, protocol=None, cache_control=None, content_disposition=None, content_encoding=None, content_language=None, content_type=None)[source]

Generates a shared access signature for the blob. Use the returned signature with the sas_token parameter of any BlobService.

Parameters:
  • container_name (str) – Name of container.
  • blob_name (str) – Name of blob.
  • permission (BlobPermissions) – The permissions associated with the shared access signature. The user is restricted to operations allowed by the permissions. Permissions must be ordered read, write, delete, list. Required unless an id is given referencing a stored access policy which contains this field. This field must be omitted if it has been specified in an associated stored access policy.
  • expiry (datetime or str) – The time at which the shared access signature becomes invalid. Required unless an id is given referencing a stored access policy which contains this field. This field must be omitted if it has been specified in an associated stored access policy. Azure will always convert values to UTC. If a date is passed in without timezone info, it is assumed to be UTC.
  • start (datetime or str) – The time at which the shared access signature becomes valid. If omitted, start time for this call is assumed to be the time when the storage service receives the request. Azure will always convert values to UTC. If a date is passed in without timezone info, it is assumed to be UTC.
  • id (str) – A unique value up to 64 characters in length that correlates to a stored access policy. To create a stored access policy, use set_container_acl().
  • ip (str) – Specifies an IP address or a range of IP addresses from which to accept requests. If the IP address from which the request originates does not match the IP address or address range specified on the SAS token, the request is not authenticated. For example, specifying sip=168.1.5.65 or sip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses.
  • protocol (str) – Specifies the protocol permitted for a request made. The default value is https,http. See Protocol for possible values.
  • cache_control (str) – Response header value for Cache-Control when resource is accessed using this shared access signature.
  • content_disposition (str) – Response header value for Content-Disposition when resource is accessed using this shared access signature.
  • content_encoding (str) – Response header value for Content-Encoding when resource is accessed using this shared access signature.
  • content_language (str) – Response header value for Content-Language when resource is accessed using this shared access signature.
  • content_type (str) – Response header value for Content-Type when resource is accessed using this shared access signature.
Returns:

A Shared Access Signature (sas) token.

Return type:

str

generate_container_shared_access_signature(container_name, permission=None, expiry=None, start=None, id=None, ip=None, protocol=None, cache_control=None, content_disposition=None, content_encoding=None, content_language=None, content_type=None)[source]

Generates a shared access signature for the container. Use the returned signature with the sas_token parameter of any BlobService.

Parameters:
  • container_name (str) – Name of container.
  • permission (ContainerPermissions) – The permissions associated with the shared access signature. The user is restricted to operations allowed by the permissions. Permissions must be ordered read, write, delete, list. Required unless an id is given referencing a stored access policy which contains this field. This field must be omitted if it has been specified in an associated stored access policy.
  • expiry (datetime or str) – The time at which the shared access signature becomes invalid. Required unless an id is given referencing a stored access policy which contains this field. This field must be omitted if it has been specified in an associated stored access policy. Azure will always convert values to UTC. If a date is passed in without timezone info, it is assumed to be UTC.
  • start (datetime or str) – The time at which the shared access signature becomes valid. If omitted, start time for this call is assumed to be the time when the storage service receives the request. Azure will always convert values to UTC. If a date is passed in without timezone info, it is assumed to be UTC.
  • id (str) – A unique value up to 64 characters in length that correlates to a stored access policy. To create a stored access policy, use set_blob_service_properties.
  • ip (str) – Specifies an IP address or a range of IP addresses from which to accept requests. If the IP address from which the request originates does not match the IP address or address range specified on the SAS token, the request is not authenticated. For example, specifying sip=168.1.5.65 or sip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses.
  • protocol (str) – Specifies the protocol permitted for a request made. The default value is https,http. See Protocol for possible values.
  • cache_control (str) – Response header value for Cache-Control when resource is accessed using this shared access signature.
  • content_disposition (str) – Response header value for Content-Disposition when resource is accessed using this shared access signature.
  • content_encoding (str) – Response header value for Content-Encoding when resource is accessed using this shared access signature.
  • content_language (str) – Response header value for Content-Language when resource is accessed using this shared access signature.
  • content_type (str) – Response header value for Content-Type when resource is accessed using this shared access signature.
Returns:

A Shared Access Signature (sas) token.

Return type:

str

get_blob_metadata(container_name, blob_name, snapshot=None, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Returns all user-defined metadata for the specified blob or snapshot.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • snapshot (str) – The snapshot parameter is an opaque value that, when present, specifies the blob snapshot to retrieve.
  • 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:

A dictionary representing the blob metadata name, value pairs.

Return type:

dict(str, str)

get_blob_properties(container_name, blob_name, snapshot=None, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

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

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • snapshot (str) – The snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to retrieve.
  • 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:

a blob object including properties and metadata.

Return type:

Blob

get_blob_service_properties(timeout=None)[source]

Gets the properties of a storage account’s Blob service, including Azure Storage Analytics.

Parameters:timeout (int) – The timeout parameter is expressed in seconds.
Returns:The blob service properties.
Return type:ServiceProperties with an attached target_version property
get_blob_service_stats(timeout=None)[source]

Retrieves statistics related to replication for the Blob service. It is only available when read-access geo-redundant replication is enabled for the storage account.

With geo-redundant replication, Azure Storage maintains your data durable in two locations. In both locations, Azure Storage constantly maintains multiple healthy replicas of your data. The location where you read, create, update, or delete data is the primary storage account location. The primary location exists in the region you choose at the time you create an account via the Azure Management Azure classic portal, for example, North Central US. The location to which your data is replicated is the secondary location. The secondary location is automatically determined based on the location of the primary; it is in a second data center that resides in the same region as the primary location. Read-only access is available from the secondary location, if read-access geo-redundant replication is enabled for your storage account.

Parameters:timeout (int) – The timeout parameter is expressed in seconds.
Returns:The blob service stats.
Return type:ServiceStats
get_blob_to_bytes(container_name, blob_name, snapshot=None, start_range=None, end_range=None, validate_content=False, progress_callback=None, max_connections=2, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Downloads a blob as an array of bytes, with automatic chunking and progress notifications. Returns an instance of Blob with properties, metadata, and content.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • snapshot (str) – The snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to retrieve.
  • start_range (int) – Start of byte range to use for downloading a section of the blob. If no end_range is given, all bytes after the start_range will be downloaded. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • end_range (int) – End of byte range to use for downloading a section of the blob. If end_range is given, start_range must be provided. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • validate_content (bool) – If set to true, validates an MD5 hash for each retrieved portion of the blob. 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 the service will only return transactional MD5s for chunks 4MB or less so the first get request will be of size self.MAX_CHUNK_GET_SIZE instead of self.MAX_SINGLE_GET_SIZE. If self.MAX_CHUNK_GET_SIZE was set to greater than 4MB an error will be thrown. As computing the MD5 takes processing time and more requests will need to be done due to the reduced chunk size there may be some increase in latency.
  • progress_callback (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 if known.
  • max_connections (int) – If set to 2 or greater, an initial get will be done for the first self.MAX_SINGLE_GET_SIZE bytes of the blob. If this is the entire blob, the method returns at this point. If it is not, it will download the remaining data parallel using the number of threads equal to max_connections. Each chunk will be of size self.MAX_CHUNK_GET_SIZE. If set to 1, a single large get request will be done. This is not generally recommended but available if very few threads should be used, network requests are very expensive, or a non-seekable stream prevents parallel download. This may also be useful if many blobs are expected to be empty as an extra request is required for empty blobs if max_connections is greater than 1.
  • 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. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.
Returns:

A Blob with properties and metadata. If max_connections is greater than 1, the content_md5 (if set on the blob) will not be returned. If you require this value, either use get_blob_properties or set max_connections to 1.

Return type:

Blob

get_blob_to_path(container_name, blob_name, file_path, open_mode='wb', snapshot=None, start_range=None, end_range=None, validate_content=False, progress_callback=None, max_connections=2, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Downloads a blob to a file path, with automatic chunking and progress notifications. Returns an instance of Blob with properties and metadata.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • file_path (str) – Path of file to write out to.
  • open_mode (str) – Mode to use when opening the file. Note that specifying append only open_mode prevents parallel download. So, max_connections must be set to 1 if this open_mode is used.
  • snapshot (str) – The snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to retrieve.
  • start_range (int) – Start of byte range to use for downloading a section of the blob. If no end_range is given, all bytes after the start_range will be downloaded. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • end_range (int) – End of byte range to use for downloading a section of the blob. If end_range is given, start_range must be provided. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • validate_content (bool) – If set to true, validates an MD5 hash for each retrieved portion of the blob. 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 the service will only return transactional MD5s for chunks 4MB or less so the first get request will be of size self.MAX_CHUNK_GET_SIZE instead of self.MAX_SINGLE_GET_SIZE. If self.MAX_CHUNK_GET_SIZE was set to greater than 4MB an error will be thrown. As computing the MD5 takes processing time and more requests will need to be done due to the reduced chunk size there may be some increase in latency.
  • progress_callback (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 if known.
  • max_connections (int) – If set to 2 or greater, an initial get will be done for the first self.MAX_SINGLE_GET_SIZE bytes of the blob. If this is the entire blob, the method returns at this point. If it is not, it will download the remaining data parallel using the number of threads equal to max_connections. Each chunk will be of size self.MAX_CHUNK_GET_SIZE. If set to 1, a single large get request will be done. This is not generally recommended but available if very few threads should be used, network requests are very expensive, or a non-seekable stream prevents parallel download. This may also be useful if many blobs are expected to be empty as an extra request is required for empty blobs if max_connections is greater than 1.
  • 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. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.
Returns:

A Blob with properties and metadata. If max_connections is greater than 1, the content_md5 (if set on the blob) will not be returned. If you require this value, either use get_blob_properties or set max_connections to 1.

Return type:

Blob

get_blob_to_stream(container_name, blob_name, stream, snapshot=None, start_range=None, end_range=None, validate_content=False, progress_callback=None, max_connections=2, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Downloads a blob to a stream, with automatic chunking and progress notifications. Returns an instance of Blob with properties and metadata.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • stream (io.IOBase) – Opened stream to write to.
  • snapshot (str) – The snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to retrieve.
  • start_range (int) – Start of byte range to use for downloading a section of the blob. If no end_range is given, all bytes after the start_range will be downloaded. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • end_range (int) – End of byte range to use for downloading a section of the blob. If end_range is given, start_range must be provided. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • validate_content (bool) – If set to true, validates an MD5 hash for each retrieved portion of the blob. 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 the service will only return transactional MD5s for chunks 4MB or less so the first get request will be of size self.MAX_CHUNK_GET_SIZE instead of self.MAX_SINGLE_GET_SIZE. If self.MAX_CHUNK_GET_SIZE was set to greater than 4MB an error will be thrown. As computing the MD5 takes processing time and more requests will need to be done due to the reduced chunk size there may be some increase in latency.
  • progress_callback (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 if known.
  • max_connections (int) – If set to 2 or greater, an initial get will be done for the first self.MAX_SINGLE_GET_SIZE bytes of the blob. If this is the entire blob, the method returns at this point. If it is not, it will download the remaining data parallel using the number of threads equal to max_connections. Each chunk will be of size self.MAX_CHUNK_GET_SIZE. If set to 1, a single large get request will be done. This is not generally recommended but available if very few threads should be used, network requests are very expensive, or a non-seekable stream prevents parallel download. This may also be useful if many blobs are expected to be empty as an extra request is required for empty blobs if max_connections is greater than 1.
  • 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. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.
Returns:

A Blob with properties and metadata. If max_connections is greater than 1, the content_md5 (if set on the blob) will not be returned. If you require this value, either use get_blob_properties or set max_connections to 1.

Return type:

Blob

get_blob_to_text(container_name, blob_name, encoding='utf-8', snapshot=None, start_range=None, end_range=None, validate_content=False, progress_callback=None, max_connections=2, lease_id=None, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Downloads a blob as unicode text, with automatic chunking and progress notifications. Returns an instance of Blob with properties, metadata, and content.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • encoding (str) – Python encoding to use when decoding the blob data.
  • snapshot (str) – The snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to retrieve.
  • start_range (int) – Start of byte range to use for downloading a section of the blob. If no end_range is given, all bytes after the start_range will be downloaded. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • end_range (int) – End of byte range to use for downloading a section of the blob. If end_range is given, start_range must be provided. The start_range and end_range params are inclusive. Ex: start_range=0, end_range=511 will download first 512 bytes of blob.
  • validate_content (bool) – If set to true, validates an MD5 hash for each retrieved portion of the blob. 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 the service will only return transactional MD5s for chunks 4MB or less so the first get request will be of size self.MAX_CHUNK_GET_SIZE instead of self.MAX_SINGLE_GET_SIZE. If self.MAX_CHUNK_GET_SIZE was set to greater than 4MB an error will be thrown. As computing the MD5 takes processing time and more requests will need to be done due to the reduced chunk size there may be some increase in latency.
  • progress_callback (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 if known.
  • max_connections (int) – If set to 2 or greater, an initial get will be done for the first self.MAX_SINGLE_GET_SIZE bytes of the blob. If this is the entire blob, the method returns at this point. If it is not, it will download the remaining data parallel using the number of threads equal to max_connections. Each chunk will be of size self.MAX_CHUNK_GET_SIZE. If set to 1, a single large get request will be done. This is not generally recommended but available if very few threads should be used, network requests are very expensive, or a non-seekable stream prevents parallel download. This may also be useful if many blobs are expected to be empty as an extra request is required for empty blobs if max_connections is greater than 1.
  • 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. This method may make multiple calls to the Azure service and the timeout will apply to each call individually.
Returns:

A Blob with properties and metadata. If max_connections is greater than 1, the content_md5 (if set on the blob) will not be returned. If you require this value, either use get_blob_properties or set max_connections to 1.

Return type:

Blob

get_container_acl(container_name, lease_id=None, timeout=None)[source]

Gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly.

Parameters:
  • container_name (str) – Name of existing container.
  • lease_id – If specified, get_container_acl only succeeds if the container’s lease is active and matches this ID.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

A dictionary of access policies associated with the container. dict of str to azure.storage.common.models.AccessPolicy and a public_access property if public access is turned on

get_container_metadata(container_name, lease_id=None, timeout=None)[source]

Returns all user-defined metadata for the specified container.

Parameters:
  • container_name (str) – Name of existing container.
  • lease_id (str) – If specified, get_container_metadata only succeeds if the container’s lease is active and matches this ID.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

A dictionary representing the container metadata name, value pairs.

Return type:

dict(str, str)

get_container_properties(container_name, lease_id=None, timeout=None)[source]

Returns all user-defined metadata and system properties for the specified container. The data returned does not include the container’s list of blobs.

Parameters:
  • container_name (str) – Name of existing container.
  • lease_id (str) – If specified, get_container_properties only succeeds if the container’s lease is active and matches this ID.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

properties for the specified container within a container object.

Return type:

Container

list_blobs(container_name, prefix=None, num_results=None, include=None, delimiter=None, marker=None, timeout=None)[source]

Returns a generator to list the blobs under the specified container. The generator will lazily follow the continuation tokens returned by the service and stop when all blobs have been returned or num_results is reached.

If num_results is specified and the account has more than that number of blobs, the generator will have a populated next_marker field once it finishes. This marker can be used to create a new generator if more results are desired.

Parameters:
  • container_name (str) – Name of existing container.
  • prefix (str) – Filters the results to return only blobs whose names begin with the specified prefix.
  • num_results (int) – Specifies the maximum number of blobs to return, including all BlobPrefix elements. If the request does not specify num_results or specifies a value greater than 5,000, the server will return up to 5,000 items. Setting num_results to a value less than or equal to zero results in error response code 400 (Bad Request).
  • include (Include) – Specifies one or more additional datasets to include in the response.
  • delimiter (str) – When the request includes this parameter, the operation returns a BlobPrefix element in the result list that acts as a placeholder for all blobs whose names begin with the same substring up to the appearance of the delimiter character. The delimiter may be a single character or a string.
  • marker (str) – An opaque continuation token. This value can be retrieved from the next_marker field of a previous generator object if num_results was specified and that generator has finished enumerating results. If specified, this generator will begin returning results from the point where the previous generator stopped.
  • timeout (int) – The timeout parameter is expressed in seconds.
list_containers(prefix=None, num_results=None, include_metadata=False, marker=None, timeout=None)[source]

Returns a generator to list the containers under the specified account. The generator will lazily follow the continuation tokens returned by the service and stop when all containers have been returned or num_results is reached.

If num_results is specified and the account has more than that number of containers, the generator will have a populated next_marker field once it finishes. This marker can be used to create a new generator if more results are desired.

Parameters:
  • prefix (str) – Filters the results to return only containers whose names begin with the specified prefix.
  • num_results (int) – Specifies the maximum number of containers to return. A single list request may return up to 1000 contianers and potentially a continuation token which should be followed to get additional resutls.
  • include_metadata (bool) – Specifies that container metadata be returned in the response.
  • marker (str) – An opaque continuation token. This value can be retrieved from the next_marker field of a previous generator object if num_results was specified and that generator has finished enumerating results. If specified, this generator will begin returning results from the point where the previous generator stopped.
  • timeout (int) – The timeout parameter is expressed in seconds.
make_blob_url(container_name, blob_name, protocol=None, sas_token=None, snapshot=None)[source]

Creates the url to access a blob.

Parameters:
  • container_name (str) – Name of container.
  • blob_name (str) – Name of blob.
  • protocol (str) – Protocol to use: ‘http’ or ‘https’. If not specified, uses the protocol specified when BaseBlobService was initialized.
  • sas_token (str) – Shared access signature token created with generate_shared_access_signature.
  • snapshot (str) – An string value that uniquely identifies the snapshot. The value of this query parameter indicates the snapshot version.
Returns:

blob access URL.

Return type:

str

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

Releases the lease. The lease may be released if the lease ID specified on the request matches that associated with the blob. Releasing the lease allows another client to immediately acquire the lease for the blob as soon as the release is complete.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • lease_id (str) – Lease ID for 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.
release_container_lease(container_name, lease_id, if_modified_since=None, if_unmodified_since=None, timeout=None)[source]

Release the lease. The lease may be released if the lease_id specified matches that associated with the container. Releasing the lease allows another client to immediately acquire the lease for the container as soon as the release is complete.

Parameters:
  • container_name (str) – Name of existing container.
  • lease_id (str) – Lease ID for 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.
  • timeout (int) – The timeout parameter is expressed in seconds.
renew_blob_lease(container_name, blob_name, lease_id, if_modified_since=None, if_unmodified_since=None, if_match=None, if_none_match=None, timeout=None)[source]

Renews the lease. The lease can be renewed if the lease ID specified on the request matches that associated with the blob. Note that the lease may be renewed even if it has expired as long as the blob has not been modified or leased again since the expiration of that lease. When you renew a lease, the lease duration clock resets.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • lease_id (str) – Lease ID for 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:

the lease ID of the renewed lease.

Returns:

str

renew_container_lease(container_name, lease_id, if_modified_since=None, if_unmodified_since=None, timeout=None)[source]

Renews the lease. The lease can be renewed if the lease ID specified matches that associated with the container. Note that the lease may be renewed even if it has expired as long as the container has not been leased again since the expiration of that lease. When you renew a lease, the lease duration clock resets.

Parameters:
  • container_name (str) – Name of existing container.
  • lease_id (str) – Lease ID for 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.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

the lease ID of the renewed lease.

Returns:

str

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

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

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • metadata (dict(str, str)) – Dict containing name and value pairs. Each call to this operation replaces all existing metadata attached to the blob. To remove all metadata from the blob, call this operation with no metadata headers.
  • lease_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 Blob

Return type:

ResourceProperties

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

Sets system properties on the blob. If one property is set for the content_settings, all properties will be overriden.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • content_settings (ContentSettings) – ContentSettings object used to set blob properties.
  • 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 Blob

Return type:

ResourceProperties

set_blob_service_properties(logging=None, hour_metrics=None, minute_metrics=None, cors=None, target_version=None, timeout=None)[source]

Sets the properties of a storage account’s Blob service, including Azure Storage Analytics. If an element (ex Logging) is left as None, the existing settings on the service for that functionality are preserved.

Parameters:
  • logging (Logging) – Groups the Azure Analytics Logging settings.
  • hour_metrics (Metrics) – The hour metrics settings provide a summary of request statistics grouped by API in hourly aggregates for blobs.
  • minute_metrics (Metrics) – The minute metrics settings provide request statistics for each minute for blobs.
  • cors (list(CorsRule)) – You can include up to five CorsRule elements in the list. If an empty list is specified, all CORS rules will be deleted, and CORS will be disabled for the service.
  • target_version (string) – Indicates the default version to use for requests if an incoming request’s version is not specified.
  • timeout (int) – The timeout parameter is expressed in seconds.
set_container_acl(container_name, signed_identifiers=None, public_access=None, lease_id=None, if_modified_since=None, if_unmodified_since=None, timeout=None)[source]

Sets the permissions for the specified container or stored access policies that may be used with Shared Access Signatures. The permissions indicate whether blobs in a container may be accessed publicly.

Parameters:
  • container_name (str) – Name of existing container.
  • signed_identifiers (dict(str, AccessPolicy)) – A dictionary of access policies to associate with the container. The dictionary may contain up to 5 elements. An empty dictionary will clear the access policies set on the service.
  • public_access (PublicAccess) – Possible values include: container, blob.
  • lease_id (str) – If specified, set_container_acl only succeeds if the container’s lease is active and matches this ID.
  • 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 date/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.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

ETag and last modified properties for the updated Container

Return type:

ResourceProperties

set_container_metadata(container_name, metadata=None, lease_id=None, if_modified_since=None, timeout=None)[source]

Sets one or more user-defined name-value pairs for the specified container. Each call to this operation replaces all existing metadata attached to the container. To remove all metadata from the container, call this operation with no metadata dict.

Parameters:
  • container_name (str) – Name of existing container.
  • metadata (dict(str, str)) – A dict containing name-value pairs to associate with the container as metadata. Example: {‘category’:’test’}
  • lease_id (str) – If specified, set_container_metadata only succeeds if the container’s lease is active and matches this ID.
  • 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.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

ETag and last modified properties for the updated Container

Return type:

ResourceProperties

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

Creates a read-only snapshot of a blob.

Parameters:
  • container_name (str) – Name of existing container.
  • blob_name (str) – Name of existing blob.
  • metadata (dict(str, str)) – Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the operation will copy the base blob metadata to the snapshot. If one or more name-value pairs are specified, the snapshot is created with the specified metadata, and metadata is not copied from the base blob.
  • if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
  • if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
  • if_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag matches the value specified.
  • if_none_match (str) – An ETag value, or the wildcard character (*). Specify this header to perform the operation only if the resource’s ETag does not match the value specified. Specify the wildcard character (*) to perform the operation only if the resource does not exist, and fail the operation if it does exist.
  • lease_id (str) – Required if the blob has an active lease.
  • timeout (int) – The timeout parameter is expressed in seconds.
Returns:

snapshot properties

Return type:

Blob