azure.storage.blob package
- exception azure.storage.blob.PartialBatchErrorException(message, response, parts)[source]
There is a partial failure in batch operations.
- Parameters:
- add_note(object, /)
Exception.add_note(note) – add a note to the exception
- raise_with_traceback() None
Raise the exception with the existing traceback.
Deprecated since version 1.22.0: This method is deprecated as we don’t support Python 2 anymore. Use raise/from instead.
- with_traceback(object, /)
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- args
- class azure.storage.blob.AccessPolicy(permission: ContainerSasPermissions | str | None = None, expiry: datetime | str | None = None, start: datetime | str | None = None)[source]
Access Policy class used by the set and get access policy methods in each service.
A stored access policy can specify the start time, expiry time, and permissions for the Shared Access Signatures with which it’s associated. Depending on how you want to control access to your resource, you can specify all of these parameters within the stored access policy, and omit them from the URL for the Shared Access Signature. Doing so permits you to modify the associated signature’s behavior at any time, as well as to revoke it. Or you can specify one or more of the access policy parameters within the stored access policy, and the others on the URL. Finally, you can specify all of the parameters on the URL. In this case, you can use the stored access policy to revoke the signature, but not to modify its behavior.
Together the Shared Access Signature and the stored access policy must include all fields required to authenticate the signature. If any required fields are missing, the request will fail. Likewise, if a field is specified both in the Shared Access Signature URL and in the stored access policy, the request will fail with status code 400 (Bad Request).
- Parameters:
permission (Optional[Union[ContainerSasPermissions, str]]) – 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 – 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 – 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.
- Keyword Arguments:
- classmethod deserialize(data: Any, content_type: str | None = None) Self
Parse a str using the RestAPI syntax and return a model.
- classmethod from_dict(data: Any, key_extractors: Callable[[str, Dict[str, Any], Any], Any] | None = None, content_type: str | None = None) Self
Parse a dict using given key extractor return a model.
By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)
- as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, ~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) MutableMapping[str, Any]
Return a dict that can be serialized using json.dump.
Advanced usage might optionally use a callback as parameter:
Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.
The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.
See the three examples in this file:
attribute_transformer
full_restapi_key_transformer
last_restapi_key_transformer
If you want XML serialization, you can pass the kwargs is_xml=True.
- serialize(keep_readonly: bool = False, **kwargs: Any) MutableMapping[str, Any]
Return the JSON that would be sent to server from this model.
This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).
If you want XML serialization, you can pass the kwargs is_xml=True.
- permission: ContainerSasPermissions | str | None
The permissions associated with the shared access signature. The user is restricted to operations allowed by the permissions.
- class azure.storage.blob.AccountSasPermissions(read: bool = False, write: bool = False, delete: bool = False, list: bool = False, add: bool = False, create: bool = False, update: bool = False, process: bool = False, delete_previous_version: bool = False, **kwargs)[source]
ResourceTypesclass to be used with generate_account_sas function and for the AccessPolicies used with set_*_acl. There are two types of SAS which may be used to grant resource access. One is to grant access to a specific resource (resource-specific). Another is to grant access to the entire service for a specific account and allow certain operations based on perms found here.- Parameters:
read (bool) – Valid for all signed resources types (Service, Container, and Object). Permits read permissions to the specified resource type.
write (bool) – Valid for all signed resources types (Service, Container, and Object). Permits write permissions to the specified resource type.
delete (bool) – Valid for Container and Object resource types, except for queue messages.
delete_previous_version (bool) – Delete the previous blob version for the versioning enabled storage account.
list (bool) – Valid for Service and Container resource types only.
add (bool) – Valid for the following Object resource types only: queue messages, and append blobs.
create (bool) – Valid for the following Object resource types only: blobs and files. Users can create new blobs or files, but may not overwrite existing blobs or files.
update (bool) – Valid for the following Object resource types only: queue messages.
process (bool) – Valid for the following Object resource type only: queue messages.
- Keyword Arguments:
tag (bool) – To enable set or get tags on the blobs in the container.
filter_by_tags (bool) – To enable get blobs by tags, this should be used together with list permission.
set_immutability_policy (bool) – To enable operations related to set/delete immutability policy. To get immutability policy, you just need read permission.
permanent_delete (bool) – To enable permanent delete on the blob is permitted. Valid for Object resource type of Blob only.
- classmethod from_string(permission)[source]
Create AccountSasPermissions from a string.
To specify read, write, delete, etc. permissions you need only to include the first letter of the word in the string. E.g. for read and write permissions you would provide a string “rw”.
- Parameters:
permission (str) – Specify permissions in the string with the first letter of the word.
- Returns:
An AccountSasPermissions object
- Return type:
- class azure.storage.blob.ArrowDialect(type, **kwargs: Any)[source]
field of an arrow schema.
All required parameters must be populated in order to send to Azure.
- Parameters:
type (ArrowType) – Arrow field type.
- Keyword Arguments:
- classmethod deserialize(data: Any, content_type: str | None = None) Self
Parse a str using the RestAPI syntax and return a model.
- classmethod from_dict(data: Any, key_extractors: Callable[[str, Dict[str, Any], Any], Any] | None = None, content_type: str | None = None) Self
Parse a dict using given key extractor return a model.
By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)
- as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, ~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) MutableMapping[str, Any]
Return a dict that can be serialized using json.dump.
Advanced usage might optionally use a callback as parameter:
Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.
The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.
See the three examples in this file:
attribute_transformer
full_restapi_key_transformer
last_restapi_key_transformer
If you want XML serialization, you can pass the kwargs is_xml=True.
- class azure.storage.blob.ArrowType(*values)[source]
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- BOOL = 'bool'
- DECIMAL = 'decimal'
- DOUBLE = 'double'
- INT64 = 'int64'
- STRING = 'string'
- TIMESTAMP_MS = 'timestamp[ms]'
- class azure.storage.blob.BlobAnalyticsLogging(**kwargs: Any)[source]
Azure Analytics Logging settings.
- Keyword Arguments:
version (str) – The version of Storage Analytics to configure. The default value is 1.0.
delete (bool) – Indicates whether all delete requests should be logged. The default value is False.
read (bool) – Indicates whether all read requests should be logged. The default value is False.
write (bool) – Indicates whether all write requests should be logged. The default value is False.
retention_policy (RetentionPolicy) – Determines how long the associated data should persist. If not specified the retention policy will be disabled by default.
version – The version of Storage Analytics to configure. Required.
delete – Indicates whether all delete requests should be logged. Required.
read – Indicates whether all read requests should be logged. Required.
write – Indicates whether all write requests should be logged. Required.
retention_policy – the retention policy which determines how long the associated data should persist. Required.
- classmethod deserialize(data: Any, content_type: str | None = None) Self
Parse a str using the RestAPI syntax and return a model.
- classmethod from_dict(data: Any, key_extractors: Callable[[str, Dict[str, Any], Any], Any] | None = None, content_type: str | None = None) Self
Parse a dict using given key extractor return a model.
By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)
- as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, ~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) MutableMapping[str, Any]
Return a dict that can be serialized using json.dump.
Advanced usage might optionally use a callback as parameter:
Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.
The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.
See the three examples in this file:
attribute_transformer
full_restapi_key_transformer
last_restapi_key_transformer
If you want XML serialization, you can pass the kwargs is_xml=True.
- serialize(keep_readonly: bool = False, **kwargs: Any) MutableMapping[str, Any]
Return the JSON that would be sent to server from this model.
This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).
If you want XML serialization, you can pass the kwargs is_xml=True.
- retention_policy: RetentionPolicy = <azure.storage.blob._models.RetentionPolicy object>
Determines how long the associated data should persist.
- class azure.storage.blob.BlobBlock(block_id: str, state: BlockState = BlockState.LATEST)[source]
BlockBlob Block class.
- Parameters:
block_id (str) – Block id.
state (BlockState) – Block state. Possible values: BlockState.COMMITTED | BlockState.UNCOMMITTED
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- state: BlockState
Block state.
- class azure.storage.blob.BlobClient(account_url: str, container_name: str, blob_name: str, snapshot: str | Dict[str, Any] | None = None, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any)[source]
A client to interact with a specific blob, although that blob may not yet exist.
For more optional configuration, please click here.
- Parameters:
account_url (str) – The URI to the storage account. In order to create a client given the full URI to the blob, use the
from_blob_url()classmethod.container_name (str) – The container name for the blob.
blob_name (str) – The name of the blob with which to interact. If specified, this value will override a blob value specified in the blob URL.
snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from
create_snapshot().credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
api_version (str) –
The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility.
Added in version 12.2.0.
secondary_hostname (str) – The hostname of the secondary endpoint.
max_block_size (int) – The maximum chunk size for uploading a block blob in chunks. Defaults to 4*1024*1024, or 4MB.
max_single_put_size (int) – If the blob size is less than or equal max_single_put_size, then the blob will be uploaded with only one http PUT request. If the blob size is larger than max_single_put_size, the blob will be uploaded in chunks. Defaults to 64*1024*1024, or 64MB.
min_large_block_upload_threshold (int) – The minimum chunk size required to use the memory efficient algorithm when uploading a block blob. Defaults to 4*1024*1024+1.
use_byte_buffer (bool) – Use a byte buffer for block blob uploads. Defaults to False.
max_page_size (int) – The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024, or 4MB.
max_single_get_size (int) – The maximum size for a blob to be downloaded in a single call, the exceeded part will be downloaded in chunks (could be parallel). Defaults to 32*1024*1024, or 32MB.
max_chunk_get_size (int) – The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024, or 4MB.
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to operate on.
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
Example:
Creating the BlobClient from a URL to a public blob (no auth needed).from azure.storage.blob import BlobClient blob_client = BlobClient.from_blob_url(blob_url="https://account.blob.core.windows.net/container/blob-name")
Creating the BlobClient from a SAS URL to a blob.from azure.storage.blob import BlobClient sas_url = "https://account.blob.core.windows.net/container/blob-name?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D" blob_client = BlobClient.from_blob_url(sas_url)
- classmethod from_blob_url(blob_url: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, snapshot: str | Dict[str, Any] | None = None, **kwargs: Any) Self[source]
Create BlobClient from a blob url. This doesn’t support customized blob url with ‘/’ in blob name.
- Parameters:
blob_url (str) – The full endpoint URL to the Blob, including SAS token and snapshot if used. This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode.
credential (AzureNamedKeyCredential or AzureSasCredential or TokenCredential or str or dict[str, str] or None) – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from
create_snapshot(). If specified, this will override the snapshot in the url.
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to operate on.
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
- Returns:
A Blob client.
- Return type:
- classmethod from_connection_string(conn_str: str, container_name: str, blob_name: str, snapshot: str | Dict[str, Any] | None = None, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any) Self[source]
Create BlobClient from a Connection String.
- Parameters:
conn_str (str) – A connection string to an Azure Storage account.
container_name (str) – The container name for the blob.
blob_name (str) – The name of the blob with which to interact.
snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from
create_snapshot().credential (AzureNamedKeyCredential or AzureSasCredential or TokenCredential or str or dict[str, str] or None) – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to operate on.
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
- Returns:
A Blob client.
- Return type:
Example:
Creating the BlobClient from a connection string.from azure.storage.blob import BlobClient blob_client = BlobClient.from_connection_string( self.connection_string, container_name="mycontainer", blob_name="blobname.txt")
- abort_copy(copy_id: str | Dict[str, Any] | BlobProperties, **kwargs: Any) None[source]
Abort an ongoing copy operation.
This will leave a destination blob with zero length and full metadata. This will raise an error if the copy operation has already ended.
- Parameters:
copy_id (str or BlobProperties) – The copy operation to abort. This can be either an ID string, or an instance of BlobProperties.
- Returns:
None
- Return type:
None
Example:
Abort copying a blob from URL.# Passing in copy id to abort copy operation if props.copy.status != "success": if copy_id is not None: copied_blob.abort_copy(copy_id) else: print("copy_id was unexpectedly None, check if the operation completed successfully.") # check copy status props = copied_blob.get_blob_properties() print(props.copy.status)
- acquire_lease(lease_duration: int = -1, lease_id: str | None = None, **kwargs: Any) BlobLeaseClient[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.
- Parameters:
lease_duration (int) – Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. Default is -1 (infinite lease).
lease_id (str) – Proposed lease ID, in a GUID string format. The Blob Service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A BlobLeaseClient object.
- Return type:
Example:
Acquiring a lease on a blob.# Acquire a lease on the blob lease = blob_client.acquire_lease() # Delete blob by passing in the lease blob_client.delete_blob(lease=lease)
- append_block(data: bytes | str | Iterable | IO, length: int | None = None, **kwargs: Any) Dict[str, str | datetime | int][source]
Commits a new block of data to the end of the existing append blob.
- Parameters:
- Keyword Arguments:
validate_content (bool) – If true, calculates an MD5 hash of the block content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.
maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).
appendpos_condition (int) – Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
encoding (str) – Defaults to UTF-8.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag, last modified, append offset, committed block count).
- Return type:
- append_block_from_url(copy_source_url: str, source_offset: int | None = None, source_length: int | None = None, **kwargs: Any) Dict[str, str | datetime | int][source]
Creates a new block to be committed as part of a blob, where the contents are read from a source url.
- Parameters:
copy_source_url (str) – The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.
source_offset (int) – This indicates the start of the range of bytes (inclusive) that has to be taken from the copy source.
source_length (int) – This indicates the end of the range of bytes that has to be taken from the copy source.
- Keyword Arguments:
source_content_md5 (bytearray) – If given, the service will calculate the MD5 hash of the block content and compare against this value.
maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).
appendpos_condition (int) – Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The destination match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has been modified since the specified time.
source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time.
source_etag (str) – The source ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
source_match_condition (MatchConditions) – The source match condition to use upon the etag.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
source_authorization (str) – Authenticate as a service principal using a client secret to access a source blob. Ensure “bearer “ is the prefix of the source_authorization string.
source_token_intent (Literal['backup']) –
Required when source is Azure Storage Files and using TokenCredential for authentication. This is ignored for other forms of authentication. Specifies the intent for all requests when using TokenCredential authentication. Possible values are:
- backup - Specifies requests are intended for backup/admin type operations, meaning that all file/directory
ACLs are bypassed and full permissions are granted. User must also have required RBAC permission.
- Returns:
Result after appending a new block.
- Return type:
- clear_page(offset: int, length: int, **kwargs: Any) Dict[str, str | datetime][source]
Clears a range of pages.
- Parameters:
offset (int) – Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
length (int) – Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_sequence_number_lte (int) – If the blob’s sequence number is less than or equal to the specified value, the request proceeds; otherwise it fails.
if_sequence_number_lt (int) – If the blob’s sequence number is less than the specified value, the request proceeds; otherwise it fails.
if_sequence_number_eq (int) – If the blob’s sequence number is equal to the specified value, the request proceeds; otherwise it fails.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified).
- Return type:
- close() None
This method is to close the sockets opened by the client. It need not be used when using with a context manager.
- commit_block_list(block_list: List[BlobBlock], content_settings: ContentSettings | None = None, metadata: Dict[str, str] | None = None, **kwargs: Any) Dict[str, str | datetime][source]
The Commit Block List operation writes a blob by specifying the list of block IDs that make up the blob.
- Parameters:
block_list (list) – List of Blockblobs.
content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
metadata (dict[str, str]) – Name-value pairs associated with the blob as metadata.
- Keyword Arguments:
Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (’ ‘), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)
Added in version 12.4.0.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
immutability_policy (ImmutabilityPolicy) –
Specifies the immutability policy of a blob, blob snapshot or blob version.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
legal_hold (bool) –
Specified if a legal hold should be set on the blob.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
validate_content (bool) – If true, calculates an MD5 hash of the page content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on destination blob with a matching value.
Added in version 12.4.0.
standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified).
- Return type:
- create_append_blob(content_settings: ContentSettings | None = None, metadata: Dict[str, str] | None = None, **kwargs: Any) Dict[str, str | datetime][source]
Creates a new Append Blob. This operation creates a new 0-length append blob. The content of any existing blob is overwritten with the newly initialized append blob. To add content to the append blob, call the
append_block()orappend_block_from_url()method.- Parameters:
content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.
- Keyword Arguments:
Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (’ ‘), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)
Added in version 12.4.0.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
immutability_policy (ImmutabilityPolicy) –
Specifies the immutability policy of a blob, blob snapshot or blob version.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
legal_hold (bool) –
Specified if a legal hold should be set on the blob.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified).
- Return type:
- create_page_blob(size: int, content_settings: ContentSettings | None = None, metadata: Dict[str, str] | None = None, premium_page_blob_tier: str | PremiumPageBlobTier | None = None, **kwargs: Any) Dict[str, str | datetime][source]
Creates a new Page Blob of the specified size.
- Parameters:
size (int) – This specifies the maximum size for the page blob, up to 1 TB. The page blob size must be aligned to a 512-byte boundary.
content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.
premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
- Keyword Arguments:
Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (’ ‘), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)
Added in version 12.4.0.
sequence_number (int) – Only for Page blobs. The sequence number is a user-controlled value that you can use to track requests. The value of the sequence number must be between 0 and 2^63 - 1.The default value is 0.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
immutability_policy (ImmutabilityPolicy) –
Specifies the immutability policy of a blob, blob snapshot or blob version.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
legal_hold (bool) –
Specified if a legal hold should be set on the blob.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified).
- Return type:
- create_snapshot(metadata: Dict[str, str] | None = None, **kwargs: Any) Dict[str, str | datetime][source]
Creates a snapshot of the blob.
A snapshot is a read-only version of a blob that’s taken at a point in time. It can be read, copied, or deleted, but not modified. Snapshots provide a way to back up a blob as it appears at a moment in time.
A snapshot of a blob has the same name as the base blob from which the snapshot is taken, with a DateTime value appended to indicate the time at which the snapshot was taken.
- Parameters:
metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on destination blob with a matching value.
Added in version 12.4.0.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Snapshot ID, Etag, and last modified).
- Return type:
Example:
Create a snapshot of the blob.# Create a read-only snapshot of the blob at this point in time snapshot_blob = blob_client.create_snapshot() # Get the snapshot ID print(snapshot_blob.get('snapshot'))
- delete_blob(delete_snapshots: str | None = None, **kwargs: Any) None[source]
Marks the specified blob for deletion.
The blob is later deleted during garbage collection. Note that in order to delete a blob, you must delete all of its snapshots. You can delete both at the same time with the delete_blob() operation.
If a delete retention policy is enabled for the service, then this operation soft deletes the blob and retains the blob for a specified number of days. After the specified number of days, the blob’s data is removed from the service during garbage collection. Soft deleted blob is accessible through
list_blobs()specifying include=[‘deleted’] option. Soft-deleted blob can be restored usingundelete_blob()operation.- Parameters:
delete_snapshots (Optional[str]) –
- Required if the blob has associated snapshots. Values include:
”only”: Deletes only the blobs snapshots.
”include”: Deletes the blob along with all snapshots.
- Keyword Arguments:
version_id (Optional[str]) –
The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to delete.
Added in version 12.4.0.
This keyword argument was introduced in API version ‘2019-12-12’.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. If specified, delete_blob only succeeds if the blob’s lease is active and matches this ID. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- Return type:
None
Example:
Delete a blob.blob_client.delete_blob()
- delete_immutability_policy(**kwargs: Any) None[source]
The Delete Immutability Policy operation deletes the immutability policy on the blob.
Added in version 12.10.0: This operation was introduced in API version ‘2020-10-02’.
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to check if it exists.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Key value pairs of blob tags.
- Return type:
- download_blob(offset: int | None = None, length: int | None = None, *, encoding: str | None = None, **kwargs: Any) StorageStreamDownloader[str] | StorageStreamDownloader[bytes][source]
Downloads a blob to the StorageStreamDownloader. The readall() method must be used to read all the content or readinto() must be used to download the blob into a stream. Using chunks() returns an iterator which allows the user to iterate over the content in chunks.
- Parameters:
- Keyword Arguments:
version_id (str) –
The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to download.
Added in version 12.4.0.
This keyword argument was introduced in API version ‘2019-12-12’.
validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. If specified, download_blob only succeeds if the blob’s lease is active and matches this ID. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
max_concurrency (int) – Maximum number of parallel connections to use when transferring the blob in chunks. This option does not affect the underlying connection pool, and may require a separate configuration of the connection pool.
encoding (Optional[str]) – Encoding to decode the downloaded bytes. Default is None, i.e. no decoding.
progress_hook (Callable[[int, int], None]) – A callback to track the progress of a long running download. The signature is function(current: int, total: int) where current is the number of bytes transferred so far, and total is the total size of the download.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here. This method may make multiple calls to the service and the timeout will apply to each call individually. multiple calls to the Azure service and the timeout will apply to each call individually.
- Returns:
A streaming object (StorageStreamDownloader)
- Return type:
Example:
Download a blob.with open(DEST_FILE, "wb") as my_blob: download_stream = blob_client.download_blob() my_blob.write(download_stream.readall())
- exists(**kwargs: Any) bool[source]
Returns True if a blob exists with the defined parameters, and returns False otherwise.
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to check if it exists.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
boolean
- Return type:
- get_account_information(**kwargs: Any) Dict[str, str][source]
Gets information related to the storage account in which the blob resides.
The information can also be retrieved if the user has a SAS to a container or blob. The keys in the returned dictionary include ‘sku_name’ and ‘account_kind’.
- get_blob_properties(**kwargs: Any) BlobProperties[source]
Returns all user-defined metadata, standard HTTP properties, and system properties for the blob. It does not return the content of the blob.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
version_id (str) –
The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to get properties.
Added in version 12.4.0.
This keyword argument was introduced in API version ‘2019-12-12’.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
BlobProperties
- Return type:
Example:
Getting the properties for a blob.properties = blob_client.get_blob_properties()
- get_blob_tags(**kwargs: Any) Dict[str, str][source]
The Get Tags operation enables users to get tags on a blob or specific blob version, or snapshot.
Added in version 12.4.0: This operation was introduced in API version ‘2019-12-12’.
- Keyword Arguments:
version_id (Optional[str]) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to add tags to.
if_tags_match_condition (str) – Specify a SQL where clause on blob tags to operate only on destination blob with a matching value. eg.
"\"tagname\"='my tag'"lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Key value pairs of blob tags.
- Return type:
- get_block_list(block_list_type: str = 'committed', **kwargs: Any) Tuple[List[BlobBlock], List[BlobBlock]][source]
The Get Block List operation retrieves the list of blocks that have been uploaded as part of a block blob.
- Parameters:
block_list_type (str) – Specifies whether to return the list of committed blocks, the list of uncommitted blocks, or both lists together. Possible values include: ‘committed’, ‘uncommitted’, ‘all’
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on destination blob with a matching value.
Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A tuple of two lists - committed and uncommitted blocks
- Return type:
- get_page_range_diff_for_managed_disk(previous_snapshot_url: str, offset: int | None = None, length: int | None = None, **kwargs: Any) Tuple[List[Dict[str, int]], List[Dict[str, int]]][source]
Returns the list of valid page ranges for a managed disk or snapshot.
Note
This operation is only available for managed disk accounts.
Added in version 12.2.0: This operation was introduced in API version ‘2019-07-07’.
- Parameters:
previous_snapshot_url (str) – Specifies the URL of a previous snapshot of the managed disk. The response will only contain pages that were changed between the target blob and its previous snapshot.
offset (int) – Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
length (int) – Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A tuple of two lists of page ranges as dictionaries with ‘start’ and ‘end’ keys. The first element are filled page ranges, the 2nd element is cleared page ranges.
- Return type:
- get_page_ranges(offset: int | None = None, length: int | None = None, previous_snapshot_diff: str | Dict[str, Any] | None = None, **kwargs: Any) Tuple[List[Dict[str, int]], List[Dict[str, int]]][source]
DEPRECATED: Returns the list of valid page ranges for a Page Blob or snapshot of a page blob.
- Parameters:
offset (int) – Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
length (int) – Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
previous_snapshot_diff (str) – The snapshot diff parameter that contains an opaque DateTime value that specifies a previous blob snapshot to be compared against a more recent snapshot or the current blob.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A tuple of two lists of page ranges as dictionaries with ‘start’ and ‘end’ keys. The first element are filled page ranges, the 2nd element is cleared page ranges.
- Return type:
- list_page_ranges(*, offset: int | None = None, length: int | None = None, previous_snapshot: str | Dict[str, Any] | None = None, **kwargs: Any) ItemPaged[PageRange][source]
Returns the list of valid page ranges for a Page Blob or snapshot of a page blob. If previous_snapshot is specified, the result will be a diff of changes between the target blob and the previous snapshot.
- Keyword Arguments:
offset (int) – Start of byte range to use for getting valid page ranges. If no length is given, all bytes after the offset will be searched. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
length (int) – Number of bytes to use for getting valid page ranges. If length is given, offset must be provided. This range will return valid page ranges from the offset start up to the specified length. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
previous_snapshot (str or Dict[str, Any]) – A snapshot value that specifies that the response will contain only pages that were changed between target blob and previous snapshot. Changed pages include both updated and cleared pages. The target blob may be a snapshot, as long as the snapshot specified by previous_snapshot is the older of the two.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
results_per_page (int) – The maximum number of page ranges to retrieve per API call.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterable (auto-paging) of PageRange.
- Return type:
- query_blob(query_expression: str, **kwargs: Any) BlobQueryReader[source]
Enables users to select/project on blob/or blob snapshot data by providing simple query expressions. This operations returns a BlobQueryReader, users need to use readall() or readinto() to get query data.
- Parameters:
query_expression (str) – Required. a query statement. For more details see https://learn.microsoft.com/azure/storage/blobs/query-acceleration-sql-reference.
- Keyword Arguments:
on_error (Callable[BlobQueryError]) – A function to be called on any processing errors returned by the service.
blob_format (DelimitedTextDialect or DelimitedJsonDialect or QuickQueryDialect or str) –
Optional. Defines the serialization of the data currently stored in the blob. The default is to treat the blob data as CSV data formatted in the default dialect. This can be overridden with a custom DelimitedTextDialect, or DelimitedJsonDialect or “ParquetDialect” (passed as a string or enum). These dialects can be passed through their respective classes, the QuickQueryDialect enum or as a string
Note
”ParquetDialect” is in preview, so some features may not work as intended.
output_format (DelimitedTextDialect or DelimitedJsonDialect or List[ArrowDialect] or QuickQueryDialect or str) – Optional. Defines the output serialization for the data stream. By default the data will be returned as it is represented in the blob (Parquet formats default to DelimitedTextDialect). By providing an output format, the blob data will be reformatted according to that profile. This value can be a DelimitedTextDialect or a DelimitedJsonDialect or ArrowDialect. These dialects can be passed through their respective classes, the QuickQueryDialect enum or as a string
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A streaming object (BlobQueryReader)
- Return type:
Example:
select/project on blob/or blob snapshot data by providing simple query expressions.errors = [] def on_error(error): errors.append(error) # upload the csv file blob_client = blob_service_client.get_blob_client(container_name, "csvfile") with open(BASE_FILE, "rb") as stream: blob_client.upload_blob(stream, overwrite=True) # select the second column of the csv file query_expression = "SELECT _2 from BlobStorage" input_format = DelimitedTextDialect(delimiter=',', quotechar='"', lineterminator='\n', escapechar="", has_header=False) output_format = DelimitedJsonDialect(delimiter='\n') reader = blob_client.query_blob(query_expression, on_error=on_error, blob_format=input_format, output_format=output_format) content = reader.readall()
- resize_blob(size: int, **kwargs: Any) Dict[str, str | datetime][source]
Resizes a page blob to the specified size.
If the specified value is less than the current size of the blob, then all pages above the specified value are cleared.
- Parameters:
size (int) – Size used to resize blob. Maximum size for a page blob is up to 1 TB. The page blob size must be aligned to a 512-byte boundary.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified).
- Return type:
- seal_append_blob(**kwargs: Any) Dict[str, str | datetime | int][source]
The Seal operation seals the Append Blob to make it read-only.
Added in version 12.4.0.
- Keyword Arguments:
appendpos_condition (int) – Optional conditional header, used only for the Append Block operation. A number indicating the byte offset to compare. Append Block will succeed only if the append position is equal to this number. If it is not, the request will fail with the AppendPositionConditionNotMet error (HTTP status code 412 - Precondition Failed).
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag, last modified, append offset, committed block count).
- Return type:
- set_blob_metadata(metadata: Dict[str, str] | None = None, **kwargs: Any) Dict[str, str | datetime][source]
Sets user-defined metadata for the blob as one or more name-value pairs.
- Parameters:
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.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified)
- Return type:
- set_blob_tags(tags: Dict[str, str] | None = None, **kwargs: Any) Dict[str, Any][source]
- The Set Tags operation enables users to set tags on a blob or specific blob version, but not snapshot.
Each call to this operation replaces all existing tags attached to the blob. To remove all tags from the blob, call this operation with no tags set.
Added in version 12.4.0: This operation was introduced in API version ‘2019-12-12’.
- Parameters:
tags (dict(str, str)) – Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (’ ‘), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to add tags to.
validate_content (bool) – If true, calculates an MD5 hash of the tags content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.
if_tags_match_condition (str) – Specify a SQL where clause on blob tags to operate only on destination blob with a matching value. eg.
"\"tagname\"='my tag'"lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified)
- Return type:
Dict[str, Any]
- set_http_headers(content_settings: ContentSettings | None = None, **kwargs: Any) Dict[str, Any][source]
Sets system properties on the blob.
If one property is set for the content_settings, all properties will be overridden.
- Parameters:
content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified)
- Return type:
Dict[str, Any]
- set_immutability_policy(immutability_policy: ImmutabilityPolicy, **kwargs: Any) Dict[str, str][source]
The Set Immutability Policy operation sets the immutability policy on the blob.
Added in version 12.10.0: This operation was introduced in API version ‘2020-10-02’.
- Parameters:
immutability_policy (ImmutabilityPolicy) –
Specifies the immutability policy of a blob, blob snapshot or blob version.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to check if it exists.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Key value pairs of blob tags.
- Return type:
- set_legal_hold(legal_hold: bool, **kwargs: Any) Dict[str, str | datetime | bool][source]
The Set Legal Hold operation sets a legal hold on the blob.
Added in version 12.10.0: This operation was introduced in API version ‘2020-10-02’.
- Parameters:
legal_hold (bool) – Specified if a legal hold should be set on the blob.
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to check if it exists.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Key value pairs of blob tags.
- Return type:
Sets the page blob tiers on the blob. This API is only supported for page blobs on premium accounts.
- Parameters:
premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
- Keyword Arguments:
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
- Returns:
None
- Return type:
None
- set_sequence_number(sequence_number_action: str | SequenceNumberAction, sequence_number: str | None = None, **kwargs: Any) Dict[str, str | datetime][source]
Sets the blob sequence number.
- Parameters:
sequence_number_action (str) – This property indicates how the service should modify the blob’s sequence number. See
SequenceNumberActionfor more information.sequence_number (str) – This property sets the blob’s sequence number. The sequence number is a user-controlled property that you can use to track requests and manage concurrency issues.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified).
- Return type:
- set_standard_blob_tier(standard_blob_tier: str | StandardBlobTier, **kwargs: Any) None[source]
This operation sets the tier on a block blob.
A block blob’s tier determines Hot/Cool/Archive storage type. This operation does not update the blob’s ETag.
- Parameters:
standard_blob_tier (str or StandardBlobTier) – Indicates the tier to be set on the blob. Options include ‘Hot’, ‘Cool’, ‘Archive’. The hot tier is optimized for storing data that is accessed frequently. The cool storage tier is optimized for storing data that is infrequently accessed and stored for at least a month. The archive tier is optimized for storing data that is rarely accessed and stored for at least six months with flexible latency requirements.
- Keyword Arguments:
rehydrate_priority (RehydratePriority) – Indicates the priority with which to rehydrate an archived blob
version_id (str) –
The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to download.
Added in version 12.4.0.
This keyword argument was introduced in API version ‘2019-12-12’.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
- Returns:
None
- Return type:
None
- stage_block(block_id: str, data: bytes | str | Iterable | IO, length: int | None = None, **kwargs: Any) Dict[str, Any][source]
Creates a new block to be committed as part of a blob.
- Parameters:
- Keyword Arguments:
validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
encoding (str) – Defaults to UTF-8.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob property dict.
- Return type:
- stage_block_from_url(block_id: str, source_url: str, source_offset: int | None = None, source_length: int | None = None, source_content_md5: bytes | bytearray | None = None, **kwargs: Any) Dict[str, Any][source]
Creates a new block to be committed as part of a blob where the contents are read from a URL.
- Parameters:
block_id (str) – A string value that identifies the block. The string should be less than or equal to 64 bytes in size. For a given blob, the block_id must be the same size for each block.
source_url (str) – The URL.
source_offset (int) – Start of byte range to use for the block. Must be set if source length is provided.
source_length (int) – The size of the block in bytes.
source_content_md5 (bytearray) – Specify the md5 calculated for the range of bytes that must be read from the copy source.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
source_authorization (str) – Authenticate as a service principal using a client secret to access a source blob. Ensure “bearer “ is the prefix of the source_authorization string.
source_token_intent (Literal['backup']) –
Required when source is Azure Storage Files and using TokenCredential for authentication. This is ignored for other forms of authentication. Specifies the intent for all requests when using TokenCredential authentication. Possible values are:
- backup - Specifies requests are intended for backup/admin type operations, meaning that all file/directory
ACLs are bypassed and full permissions are granted. User must also have required RBAC permission.
- Returns:
Blob property dict.
- Return type:
- start_copy_from_url(source_url: str, metadata: Dict[str, str] | None = None, incremental_copy: bool = False, **kwargs: Any) Dict[str, str | datetime][source]
Copies a blob from the given URL.
This operation returns a dictionary containing copy_status and copy_id, which can be used to check the status of or abort the copy operation. copy_status will be ‘success’ if the copy completed synchronously or ‘pending’ if the copy has been started asynchronously. For asynchronous copies, the status can be checked by polling the
get_blob_properties()method and checking the copy status. Set requires_sync to True to force the copy to be synchronous. The Blob service copies blobs on a best-effort basis.The source blob for a copy operation may be a block blob, an append blob, or a page blob. If the destination blob already exists, it must be of the same blob type as the source blob. Any existing destination blob will be overwritten. The destination blob cannot be modified while a copy operation is in progress.
When copying from a page blob, the Blob service creates a destination page blob of the source blob’s length, initially containing all zeroes. Then the source page ranges are enumerated, and non-empty ranges are copied.
For a block blob or an append blob, the Blob service creates a committed blob of zero length before returning from this operation. When copying from a block blob, all committed blocks and their block IDs are copied. Uncommitted blocks are not copied. At the end of the copy operation, the destination blob will have the same committed block count as the source.
When copying from an append blob, all committed blocks are copied. At the end of the copy operation, the destination blob will have the same committed block count as the source.
- Parameters:
source_url (str) –
A URL of up to 2 KB in length that specifies a file or blob. The value should be URL-encoded as it would appear in a request URI. If the source is in another account, the source must either be public or must be authenticated via a shared access signature. If the source is public, no authentication is required. Examples: https://myaccount.blob.core.windows.net/mycontainer/myblob
https://myaccount.blob.core.windows.net/mycontainer/myblob?snapshot=<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.
incremental_copy (bool) – Copies the snapshot of the source page blob to a destination page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination. The copied snapshots are complete copies of the original snapshot and can be read or copied from as usual. Defaults to False.
- Keyword Arguments:
tags (dict(str, str) or Literal["COPY"]) –
Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (’ ‘), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_).
The (case-sensitive) literal “COPY” can instead be passed to copy tags from the source blob. This option is only available when incremental_copy=False and requires_sync=True.
Added in version 12.4.0.
immutability_policy (ImmutabilityPolicy) –
Specifies the immutability policy of a blob, blob snapshot or blob version.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
legal_hold (bool) –
Specified if a legal hold should be set on the blob.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has been modified since the specified date/time.
source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the source blob has not been modified since the specified date/time.
source_etag (str) – The source ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
source_match_condition (MatchConditions) – The source match condition to use upon the etag.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the destination blob has been modified since the specified date/time. If the destination blob has not been modified, the Blob service returns status code 412 (Precondition Failed).
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this conditional header to copy the blob only if the destination blob has not been modified since the specified date/time. If the destination blob has been modified, the Blob service returns status code 412 (Precondition Failed).
etag (str) – The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The destination match condition to use upon the etag.
destination_lease (BlobLeaseClient or str) – The lease ID specified for this header must match the lease ID of the destination blob. If the request does not include the lease ID or it is not valid, the operation fails with status code 412 (Precondition Failed).
source_lease (BlobLeaseClient or str) – Specify this to perform the Copy Blob operation only if the lease ID given matches the active lease ID of the source blob.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.
rehydrate_priority (RehydratePriority) – Indicates the priority with which to rehydrate an archived blob
seal_destination_blob (bool) –
Seal the destination append blob. This operation is only for append blob.
Added in version 12.4.0.
requires_sync (bool) – Enforces that the service will not return a response until the copy is complete.
source_authorization (str) –
Authenticate as a service principal using a client secret to access a source blob. Ensure “bearer “ is the prefix of the source_authorization string. This option is only available when incremental_copy is set to False and requires_sync is set to True.
Added in version 12.9.0.
source_token_intent (Literal['backup']) –
Required when source is Azure Storage Files and using TokenCredential for authentication. This is ignored for other forms of authentication. Specifies the intent for all requests when using TokenCredential authentication. Possible values are:
- backup - Specifies requests are intended for backup/admin type operations, meaning that all file/directory
ACLs are bypassed and full permissions are granted. User must also have required RBAC permission.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the sync copied blob. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.10.0.
- Returns:
A dictionary of copy properties (etag, last_modified, copy_id, copy_status).
- Return type:
Example:
Copy a blob from a URL.# Get the blob client with the source blob source_blob = "https://www.gutenberg.org/files/59466/59466-0.txt" copied_blob = blob_service_client.get_blob_client("copyblobcontainer", '59466-0.txt') # start copy and check copy status copy = copied_blob.start_copy_from_url(source_blob) props = copied_blob.get_blob_properties() print(props.copy.status)
- undelete_blob(**kwargs: Any) None[source]
Restores soft-deleted blobs or snapshots.
Operation will only be successful if used within the specified number of days set in the delete retention policy.
If blob versioning is enabled, the base blob cannot be restored using this method. Instead use
start_copy_from_url()with the URL of the blob version you wish to promote to the current version.- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- Return type:
None
Example:
Undeleting a blob.# Undelete the blob before the retention policy expires blob_client.undelete_blob()
- upload_blob(data: bytes | str | Iterable | IO[bytes], blob_type: str | BlobType = BlobType.BLOCKBLOB, length: int | None = None, metadata: Dict[str, str] | None = None, **kwargs: Any) Dict[str, Any][source]
Creates a new blob from a data source with automatic chunking.
- Parameters:
data (Union[bytes, str, Iterable[AnyStr], IO[AnyStr]]) – The blob data to upload.
blob_type (BlobType) – The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob. The default value is BlockBlob.
length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.
- Keyword Arguments:
Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (’ ‘), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)
Added in version 12.4.0.
overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob will overwrite the existing data. If set to False, the operation will fail with ResourceExistsError. The exception to the above is with Append blob types: if set to False and the data already exists, an error will not be raised and the data will be appended to the existing blob. If set overwrite=True, then the existing append blob will be deleted, and a new one created. Defaults to False.
content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. If specified, upload_blob only succeeds if the blob’s lease is active and matches this ID. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.
immutability_policy (ImmutabilityPolicy) –
Specifies the immutability policy of a blob, blob snapshot or blob version. Currently this parameter of upload_blob() API is for BlockBlob only.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
legal_hold (bool) –
Specified if a legal hold should be set on the blob. Currently this parameter of upload_blob() API is for BlockBlob only.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).
max_concurrency (int) – Maximum number of parallel connections to use when transferring the blob in chunks. This option does not affect the underlying connection pool, and may require a separate configuration of the connection pool.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
encoding (str) – Defaults to UTF-8.
progress_hook (Callable[[int, Optional[int]], None]) – A callback to track the progress of a long running upload. The signature is function(current: int, total: Optional[int]) where current is the number of bytes transferred so far, and total is the size of the blob or None if the size is unknown.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here. This method may make multiple calls to the service and the timeout will apply to each call individually.
- Returns:
Blob-updated property Dict (Etag and last modified)
- Return type:
Dict[str, Any]
Example:
Upload a blob to the container.# Upload content to block blob with open(SOURCE_FILE, "rb") as data: blob_client.upload_blob(data, blob_type="BlockBlob")
- upload_blob_from_url(source_url: str, *, metadata: Dict[str, str] | None = None, **kwargs: Any) Dict[str, Any][source]
Creates a new Block Blob where the content of the blob is read from a given URL. The content of an existing blob is overwritten with the new blob.
- Parameters:
source_url (str) –
A URL of up to 2 KB in length that specifies a file or blob. The value should be URL-encoded as it would appear in a request URI. The source must either be public or must be authenticated via a shared access signature as part of the url or using the source_authorization keyword. 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
- Keyword Arguments:
metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.
overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob will overwrite the existing data. If set to False, the operation will fail with ResourceExistsError.
include_source_blob_properties (bool) – Indicates if properties from the source blob should be copied. Defaults to True.
tags (dict(str, str)) – Name-value pairs associated with the blob as tag. Tags are case-sensitive. The tag set may contain at most 10 tags. Tag keys must be between 1 and 128 characters, and tag values must be between 0 and 256 characters. Valid tag key and value characters include: lowercase and uppercase letters, digits (0-9), space (’ ‘), plus (+), minus (-), period (.), solidus (/), colon (:), equals (=), underscore (_)
source_content_md5 (bytearray) – Specify the md5 that is used to verify the integrity of the source bytes.
source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has been modified since the specified time.
source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time.
source_etag (str) – The source ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
source_match_condition (MatchConditions) – The source match condition to use upon the etag.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The destination match condition to use upon the etag.
destination_lease (BlobLeaseClient or str) – The lease ID specified for this header must match the lease ID of the destination blob. If the request does not include the lease ID or it is not valid, the operation fails with status code 412 (Precondition Failed).
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) – A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.
source_authorization (str) – Authenticate as a service principal using a client secret to access a source blob. Ensure “bearer “ is the prefix of the source_authorization string.
source_token_intent (Literal['backup']) –
Required when source is Azure Storage Files and using TokenCredential for authentication. This is ignored for other forms of authentication. Specifies the intent for all requests when using TokenCredential authentication. Possible values are:
- backup - Specifies requests are intended for backup/admin type operations, meaning that all file/directory
ACLs are bypassed and full permissions are granted. User must also have required RBAC permission.
- Returns:
Blob-updated property Dict (Etag and last modified)
- Return type:
Dict[str, Any]
- upload_page(page: bytes, offset: int, length: int, **kwargs: Any) Dict[str, str | datetime][source]
The Upload Pages operation writes a range of pages to a page blob.
- Parameters:
page (bytes) – Content of the page.
offset (int) – Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
length (int) – Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
validate_content (bool) – If true, calculates an MD5 hash of the page content. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob.
if_sequence_number_lte (int) – If the blob’s sequence number is less than or equal to the specified value, the request proceeds; otherwise it fails.
if_sequence_number_lt (int) – If the blob’s sequence number is less than the specified value, the request proceeds; otherwise it fails.
if_sequence_number_eq (int) – If the blob’s sequence number is equal to the specified value, the request proceeds; otherwise it fails.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
encoding (str) – Defaults to UTF-8.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Blob-updated property dict (Etag and last modified).
- Return type:
- upload_pages_from_url(source_url: str, offset: int, length: int, source_offset: int, **kwargs: Any) Dict[str, Any][source]
The Upload Pages operation writes a range of pages to a page blob where the contents are read from a URL.
- Parameters:
source_url (str) – The URL of the source data. It can point to any Azure Blob or File, that is either public or has a shared access signature attached.
offset (int) – Start of byte range to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
length (int) – Number of bytes to use for writing to a section of the blob. Pages must be aligned with 512-byte boundaries, the start offset must be a modulus of 512 and the length must be a modulus of 512.
source_offset (int) – This indicates the start of the range of bytes(inclusive) that has to be taken from the copy source. The service will read the same number of bytes as the destination range (length-offset).
- Keyword Arguments:
source_content_md5 (bytes) – If given, the service will calculate the MD5 hash of the block content and compare against this value.
source_if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has been modified since the specified time.
source_if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the source resource has not been modified since the specified date/time.
source_etag (str) – The source ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
source_match_condition (MatchConditions) – The source match condition to use upon the etag.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_sequence_number_lte (int) – If the blob’s sequence number is less than or equal to the specified value, the request proceeds; otherwise it fails.
if_sequence_number_lt (int) – If the blob’s sequence number is less than the specified value, the request proceeds; otherwise it fails.
if_sequence_number_eq (int) – If the blob’s sequence number is equal to the specified value, the request proceeds; otherwise it fails.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – The destination ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The destination match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
source_authorization (str) – Authenticate as a service principal using a client secret to access a source blob. Ensure “bearer “ is the prefix of the source_authorization string.
source_token_intent (Literal['backup']) –
Required when source is Azure Storage Files and using TokenCredential for authentication. This is ignored for other forms of authentication. Specifies the intent for all requests when using TokenCredential authentication. Possible values are:
- backup - Specifies requests are intended for backup/admin type operations, meaning that all file/directory
ACLs are bypassed and full permissions are granted. User must also have required RBAC permission.
- Returns:
Response after uploading pages from specified URL.
- Return type:
Dict[str, Any]
- property location_mode: str
The location mode that the client is currently using.
By default this will be “primary”. Options include “primary” and “secondary”.
- Returns:
The current location mode.
- Return type:
- property primary_endpoint: str
The full primary endpoint URL.
- Returns:
The full primary endpoint URL.
- Return type:
- property primary_hostname: str
The hostname of the primary endpoint.
- Returns:
The hostname of the primary endpoint.
- Return type:
- property secondary_endpoint: str
The full secondary endpoint URL if configured.
If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
- Returns:
The full secondary endpoint URL.
- Return type:
- Raises:
ValueError – If no secondary endpoint is configured.
- property secondary_hostname: str | None
The hostname of the secondary endpoint.
If not available this will be None. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
- Returns:
The hostname of the secondary endpoint, or None if not configured.
- Return type:
Optional[str]
- property url: str
The full endpoint URL to this entity, including SAS token if used.
This could be either the primary endpoint, or the secondary endpoint depending on the current
location_mode().- Returns:
The full endpoint URL to this entity, including SAS token if used.
- Return type:
- class azure.storage.blob.BlobImmutabilityPolicyMode(*values)[source]
Specifies the immutability policy mode to set on the blob. “Mutable” can only be returned by service, don’t set to “Mutable”.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- LOCKED = 'Locked'
- MUTABLE = 'Mutable'
- UNLOCKED = 'Unlocked'
- class azure.storage.blob.BlobLeaseClient(client: BlobClient | ContainerClient, lease_id: str | None = None)[source]
Creates a new BlobLeaseClient.
This client provides lease operations on a BlobClient or ContainerClient. :param client: The client of the blob or container to lease. :type client: Union[BlobClient, ContainerClient] :param lease_id: A string representing the lease ID of an existing lease. This value does not need to be specified in order to acquire a new lease, or break one. :type lease_id: Optional[str]
- acquire(lease_duration: int = -1, **kwargs: Any) 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:
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).
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- Return type:
None
- break_lease(lease_break_period: int | None = None, **kwargs: Any) int[source]
Break the lease, if the container or 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 container or blob. When a lease is successfully broken, the response indicates the interval in seconds until a new lease can be acquired.
- Parameters:
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.
- Keyword Arguments:
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_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Approximate time remaining in the lease period, in seconds.
- Return type:
- change(proposed_lease_id: str, **kwargs: Any) None[source]
Change the lease ID of an active lease.
- Parameters:
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.
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- release(**kwargs: Any) None[source]
Release the lease.
The lease may be released if the client lease id specified matches that associated with the container or blob. Releasing the lease allows another client to immediately acquire the lease for the container or blob as soon as the release is complete.
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- renew(**kwargs: Any) None[source]
Renews the lease.
The lease can be renewed if the lease ID specified in the lease client matches that associated with the container or blob. Note that the lease may be renewed even if it has expired as long as the container or blob has not been leased again since the expiration of that lease. When you renew a lease, the lease duration clock resets.
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- etag: str | None
The ETag of the lease currently being maintained. This will be None if no lease has yet been acquired or modified.
- class azure.storage.blob.BlobPrefix(*args: Any, **kwargs: Any)[source]
An Iterable of Blob properties.
Returned from walk_blobs when a delimiter is used. Can be thought of as a virtual blob directory.
Return an iterator of items.
args and kwargs will be passed to the PageIterator constructor directly, except page_iterator_class
- by_page(continuation_token: str | None = None) Iterator[Iterator[ReturnType]]
Get an iterator of pages of objects, instead of an iterator of objects.
- Parameters:
continuation_token (str) – An opaque continuation token. This value can be retrieved from the continuation_token field of a previous generator object. If specified, this generator will begin returning results from this point.
- Returns:
An iterator of pages (themselves iterator of objects)
- Return type:
iterator[iterator[ReturnType]]
- get(key, default=None)
- has_key(k)
- items()
- keys()
- next() ReturnType
Return the next item from the iterator. When exhausted, raise StopIteration
- update(*args, **kwargs)
- values()
- current_page: List[BlobProperties] | None
The current page of listed results.
- class azure.storage.blob.BlobProperties(**kwargs: Any)[source]
Blob Properties.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- append_blob_committed_block_count: int | None
(For Append Blobs) Number of committed blocks in the blob.
- blob_tier: StandardBlobTier | None
Indicates the access tier of the blob. The hot tier is optimized for storing data that is accessed frequently. The cool storage tier is optimized for storing data that is infrequently accessed and stored for at least a month. The archive tier is optimized for storing data that is rarely accessed and stored for at least six months with flexible latency requirements.
- blob_tier_inferred: bool | None
Indicates whether the access tier was inferred by the service. If false, it indicates that the tier was set explicitly.
- content_range: str | None
Indicates the range of bytes returned in the event that the client requested a subset of the blob.
- content_settings: ContentSettings
Stores all the content settings for the blob.
- copy: CopyProperties
Stores all the copy properties for the blob.
- creation_time: datetime
Indicates when the blob was created, in UTC.
- deleted_time: datetime | None
A datetime object representing the time at which the blob was deleted.
- encryption_scope: str | None
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
- has_legal_hold: bool | None
Specified if a legal hold should be set on the blob. Currently this parameter of upload_blob() API is for BlockBlob only.
- immutability_policy: ImmutabilityPolicy
Specifies the immutability policy of a blob, blob snapshot or blob version.
- last_accessed_on: datetime | None
Indicates when the last Read/Write operation was performed on a Blob.
- last_modified: datetime
A datetime object representing the last time the blob was modified.
- lease: LeaseProperties
Stores all the lease information for the blob.
- object_replication_destination_policy: str | None
Represents the Object Replication Policy Id that created this blob.
- object_replication_source_properties: List[ObjectReplicationPolicy] | None
Only present for blobs that have policy ids and rule ids applied to them.
- page_blob_sequence_number: int | None
(For Page Blobs) Sequence number for page blob used for coordinating concurrent writes.
- remaining_retention_days: int | None
The number of days that the blob will be retained before being permanently deleted by the service.
- class azure.storage.blob.BlobQueryError(error: str | None = None, is_fatal: bool = False, description: str | None = None, position: int | None = None)[source]
The error happened during quick query operation.
- class azure.storage.blob.BlobQueryReader(name: str = None, container: str = None, errors: Any = None, record_delimiter: str = '\n', encoding: str | None = None, headers: Dict[str, Any] = None, response: Any = None, error_cls: Type[BlobQueryError] = None)[source]
A streaming object to read query results.
- readall() bytes[source]
Return all query results.
This operation is blocking until all data is downloaded.
- Returns:
The query results.
- Return type:
- readinto(stream: IO) None[source]
Download the query result to a stream.
- Parameters:
stream (IO) – The stream to download to. This can be an open file-handle, or any writable stream.
- Returns:
None
- records() Iterable[bytes][source]
Returns a record generator for the query result.
Records will be returned line by line.
- Returns:
A record generator for the query result.
- Return type:
Iterable[bytes]
- class azure.storage.blob.BlobSasPermissions(read: bool = False, add: bool = False, create: bool = False, write: bool = False, delete: bool = False, delete_previous_version: bool = False, tag: bool = False, **kwargs: Any)[source]
BlobSasPermissions class to be used with the
generate_blob_sas()function.- Parameters:
read (bool) – Read the content, properties, metadata and block list. Use the blob as the source of a copy operation.
add (bool) – Add a block to an append blob.
create (bool) – Write a new blob, snapshot a blob, or copy a blob to a new blob.
write (bool) – Create or write content, properties, metadata, or block list. Snapshot or lease the blob. Resize the blob (page blob only). Use the blob as the destination of a copy operation within the same account.
delete (bool) – Delete the blob.
delete_previous_version (bool) – Delete the previous blob version for the versioning enabled storage account.
tag (bool) – Set or get tags on the blob.
- Keyword Arguments:
permanent_delete (bool) – To enable permanent delete on the blob is permitted.
move (bool) – Move a blob or a directory and its contents to a new location.
execute (bool) – Get the system properties and, if the hierarchical namespace is enabled for the storage account, get the POSIX ACL of a blob.
set_immutability_policy (bool) – To enable operations related to set/delete immutability policy. To get immutability policy, you just need read permission.
- classmethod from_string(permission: str) BlobSasPermissions[source]
Create a BlobSasPermissions from a string.
To specify read, add, create, write, or delete permissions you need only to include the first letter of the word in the string. E.g. For read and write permissions, you would provide a string “rw”.
- Parameters:
permission (str) – The string which dictates the read, add, create, write, or delete permissions.
- Returns:
A BlobSasPermissions object
- Return type:
- delete_previous_version: bool = False
Permission to delete previous blob version for versioning enabled storage accounts.
- class azure.storage.blob.BlobServiceClient(account_url: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any)[source]
A client to interact with the Blob Service at the account level.
This client provides operations to retrieve and configure the account properties as well as list, create and delete containers within the account. For operations relating to a specific container or blob, clients for those entities can also be retrieved using the get_client functions.
For more optional configuration, please click here.
- Parameters:
account_url (str) – The URL to the blob storage account. Any other entities included in the URL path (e.g. container or blob) will be discarded. This URL can be optionally authenticated with a SAS token.
credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
api_version (str) –
The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility.
Added in version 12.2.0.
secondary_hostname (str) – The hostname of the secondary endpoint.
max_block_size (int) – The maximum chunk size for uploading a block blob in chunks. Defaults to 4*1024*1024, or 4MB.
max_single_put_size (int) – If the blob size is less than or equal max_single_put_size, then the blob will be uploaded with only one http PUT request. If the blob size is larger than max_single_put_size, the blob will be uploaded in chunks. Defaults to 64*1024*1024, or 64MB.
min_large_block_upload_threshold (int) – The minimum chunk size required to use the memory efficient algorithm when uploading a block blob. Defaults to 4*1024*1024+1.
use_byte_buffer (bool) – Use a byte buffer for block blob uploads. Defaults to False.
max_page_size (int) – The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024, or 4MB.
max_single_get_size (int) – The maximum size for a blob to be downloaded in a single call, the exceeded part will be downloaded in chunks (could be parallel). Defaults to 32*1024*1024, or 32MB.
max_chunk_get_size (int) – The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024, or 4MB.
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
Example:
Creating the BlobServiceClient with account url and credential.from azure.storage.blob import BlobServiceClient blob_service_client = BlobServiceClient(account_url=self.url, credential=self.shared_access_key)
Creating the BlobServiceClient with Default Azure Identity credentials.# Get a credential for authentication # Default Azure Credentials attempt a chained set of authentication methods, per documentation here: https://github.com/Azure/azure-sdk-for-python/tree/azure-storage-blob_12.26.0/sdk/identity/azure-identity # For example user (who must be an Azure Event Hubs Data Owner role) to be logged in can be specified by the environment variable AZURE_USERNAME # Alternately, one can specify the AZURE_TENANT_ID, AZURE_CLIENT_ID, and AZURE_CLIENT_SECRET to use the EnvironmentCredentialClass. # The docs above specify all mechanisms which the defaultCredential internally support. from azure.identity import DefaultAzureCredential default_credential = DefaultAzureCredential() # Instantiate a BlobServiceClient using a token credential from azure.storage.blob import BlobServiceClient blob_service_client = BlobServiceClient( account_url=self.oauth_url, credential=default_credential )
- classmethod from_connection_string(conn_str: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any) Self[source]
Create BlobServiceClient from a Connection String.
- Parameters:
conn_str (str) – A connection string to an Azure Storage account.
credential (AzureNamedKeyCredential or AzureSasCredential or TokenCredential or str or dict[str, str] or None) – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
- Returns:
A Blob service client.
- Return type:
Example:
Creating the BlobServiceClient from a connection string.from azure.storage.blob import BlobServiceClient blob_service_client = BlobServiceClient.from_connection_string(self.connection_string)
- close() None
This method is to close the sockets opened by the client. It need not be used when using with a context manager.
- create_container(name: str, metadata: Dict[str, str] | None = None, public_access: PublicAccess | str | None = None, **kwargs: Any) ContainerClient[source]
Creates a new container under the specified account.
If the container with the same name already exists, a ResourceExistsError will be raised. This method returns a client with which to interact with the newly created container.
- Parameters:
- Keyword Arguments:
container_encryption_scope (dict or ContainerEncryptionScope) –
Specifies the default encryption scope to set on the container and use for all future writes.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A container client to interact with the newly created container.
- Return type:
Example:
Creating a container in the blob service.try: new_container = blob_service_client.create_container("containerfromblobservice") properties = new_container.get_container_properties() except ResourceExistsError: print("Container already exists.")
- delete_container(container: ContainerProperties | str, lease: BlobLeaseClient | str | None = None, **kwargs: Any) None[source]
Marks the specified container for deletion.
The container and any blobs contained within it are later deleted during garbage collection. If the container is not found, a ResourceNotFoundError will be raised.
- Parameters:
container (str or ContainerProperties) – The container to delete. This can either be the name of the container, or an instance of ContainerProperties.
lease (BlobLeaseClient or 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.
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- Return type:
None
Example:
Deleting a container in the blob service.# Delete container if it exists try: blob_service_client.delete_container("containerfromblobservice") except ResourceNotFoundError: print("Container already deleted.")
- find_blobs_by_tags(filter_expression: str, **kwargs: Any) ItemPaged[FilteredBlob][source]
The Filter Blobs operation enables callers to list blobs across all containers whose tags match a given search expression. Filter blobs searches across all containers within a storage account but can be scoped within the expression to a single container.
- Parameters:
filter_expression (str) – The expression to find blobs whose tags matches the specified condition. eg. “”yourtagname”=’firsttag’ and “yourtagname2”=’secondtag’” To specify a container, eg. “@container=’containerName’ and “Name”=’C’”
- Keyword Arguments:
results_per_page (int) – The max result per page when paginating.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterable (auto-paging) response of BlobProperties.
- Return type:
- get_account_information(**kwargs: Any) Dict[str, str][source]
Gets information related to the storage account.
The information can also be retrieved if the user has a SAS to a container or blob. The keys in the returned dictionary include ‘sku_name’ and ‘account_kind’.
Example:
Getting account information for the blob service.account_info = blob_service_client.get_account_information() print('Using Storage SKU: {}'.format(account_info['sku_name']))
- get_blob_client(container: ContainerProperties | str, blob: str, snapshot: str | Dict[str, Any] | None = None, *, version_id: str | None = None) BlobClient[source]
Get a client to interact with the specified blob.
The blob need not already exist.
- Parameters:
container (str or ContainerProperties) – The container that the blob is in. This can either be the name of the container, or an instance of ContainerProperties.
blob (str) – The name of the blob with which to interact.
snapshot (str or dict(str, Any)) – The optional blob snapshot on which to operate. This can either be the ID of the snapshot, or a dictionary output returned by
create_snapshot().
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to operate on.
- Returns:
A BlobClient.
- Return type:
Example:
Getting the blob client to interact with a specific blob.blob_client = blob_service_client.get_blob_client(container="containertest", blob="my_blob") try: stream = blob_client.download_blob() except ResourceNotFoundError: print("No blob found.")
- get_container_client(container: ContainerProperties | str) ContainerClient[source]
Get a client to interact with the specified container.
The container need not already exist.
- Parameters:
container (str or ContainerProperties) – The container. This can either be the name of the container, or an instance of ContainerProperties.
- Returns:
A ContainerClient.
- Return type:
Example:
Getting the container client to interact with a specific container.# Get a client to interact with a specific container - though it may not yet exist container_client = blob_service_client.get_container_client("containertest") try: for blob in container_client.list_blobs(): print("Found blob: ", blob.name) except ResourceNotFoundError: print("Container not found.")
- get_service_properties(**kwargs: Any) Dict[str, Any][source]
Gets the properties of a storage account’s Blob service, including Azure Storage Analytics.
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An object containing blob service properties such as analytics logging, hour/minute metrics, cors rules, etc.
- Return type:
Dict[str, Any]
Example:
Getting service properties for the blob service.properties = blob_service_client.get_service_properties()
- get_service_stats(**kwargs: Any) Dict[str, Any][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.
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
The blob service stats.
- Return type:
Dict[str, Any]
Example:
Getting service stats for the blob service.stats = blob_service_client.get_service_stats()
- get_user_delegation_key(key_start_time: datetime, key_expiry_time: datetime, **kwargs: Any) UserDelegationKey[source]
Obtain a user delegation key for the purpose of signing SAS tokens. A token credential must be present on the service object for this request to succeed.
- Parameters:
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
The user delegation key.
- Return type:
- list_containers(name_starts_with: str | None = None, include_metadata: bool = False, **kwargs: Any) ItemPaged[ContainerProperties][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.
- Parameters:
- Keyword Arguments:
include_deleted (bool) – Specifies that deleted containers to be returned in the response. This is for container restore enabled account. The default value is False. .. versionadded:: 12.4.0
include_system (bool) – Flag specifying that system containers should be included. .. versionadded:: 12.10.0
results_per_page (int) – The maximum number of container names to retrieve per API call. If the request does not specify the server will return up to 5,000 items.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterable (auto-paging) of ContainerProperties.
- Return type:
Example:
Listing the containers in the blob service.# List all containers all_containers = blob_service_client.list_containers(include_metadata=True) for container in all_containers: print(container['name'], container['metadata']) # Filter results with name prefix test_containers = blob_service_client.list_containers(name_starts_with='test-') for container in test_containers: print(container['name'], container['metadata'])
- set_service_properties(analytics_logging: BlobAnalyticsLogging | None = None, hour_metrics: Metrics | None = None, minute_metrics: Metrics | None = None, cors: List[CorsRule] | None = None, target_version: str | None = None, delete_retention_policy: RetentionPolicy | None = None, static_website: StaticWebsite | None = None, **kwargs: Any) None[source]
Sets the properties of a storage account’s Blob service, including Azure Storage Analytics.
If an element (e.g. analytics_logging) is left as None, the existing settings on the service for that functionality are preserved.
- Parameters:
analytics_logging (BlobAnalyticsLogging) – 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 (str) – Indicates the default version to use for requests if an incoming request’s version is not specified.
delete_retention_policy (RetentionPolicy) – The delete retention policy specifies whether to retain deleted blobs. It also specifies the number of days and versions of blob to keep.
static_website (StaticWebsite) – Specifies whether the static website feature is enabled, and if yes, indicates the index document and 404 error document to use.
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- Return type:
None
Example:
Setting service properties for the blob service.# Create service properties from azure.storage.blob import BlobAnalyticsLogging, Metrics, CorsRule, RetentionPolicy # Create logging settings logging = BlobAnalyticsLogging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Create metrics for requests statistics hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Create CORS rules cors_rule = CorsRule(['www.xyz.com'], ['GET']) cors = [cors_rule] # Set the service properties blob_service_client.set_service_properties(logging, hour_metrics, minute_metrics, cors)
- undelete_container(deleted_container_name: str, deleted_container_version: str, **kwargs: Any) ContainerClient[source]
Restores soft-deleted container.
Operation will only be successful if used within the specified number of days set in the delete retention policy.
Added in version 12.4.0: This operation was introduced in API version ‘2019-12-12’.
- Parameters:
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
The undeleted ContainerClient.
- Return type:
- property location_mode: str
The location mode that the client is currently using.
By default this will be “primary”. Options include “primary” and “secondary”.
- Returns:
The current location mode.
- Return type:
- property primary_endpoint: str
The full primary endpoint URL.
- Returns:
The full primary endpoint URL.
- Return type:
- property primary_hostname: str
The hostname of the primary endpoint.
- Returns:
The hostname of the primary endpoint.
- Return type:
- property secondary_endpoint: str
The full secondary endpoint URL if configured.
If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
- Returns:
The full secondary endpoint URL.
- Return type:
- Raises:
ValueError – If no secondary endpoint is configured.
- property secondary_hostname: str | None
The hostname of the secondary endpoint.
If not available this will be None. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
- Returns:
The hostname of the secondary endpoint, or None if not configured.
- Return type:
Optional[str]
- property url: str
The full endpoint URL to this entity, including SAS token if used.
This could be either the primary endpoint, or the secondary endpoint depending on the current
location_mode().- Returns:
The full endpoint URL to this entity, including SAS token if used.
- Return type:
- class azure.storage.blob.BlobType(*values)[source]
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- APPENDBLOB = 'AppendBlob'
- BLOCKBLOB = 'BlockBlob'
- PAGEBLOB = 'PageBlob'
- class azure.storage.blob.BlockState(*values)[source]
Block blob block types.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- COMMITTED = 'Committed'
Committed blocks.
- LATEST = 'Latest'
Latest blocks.
- UNCOMMITTED = 'Uncommitted'
Uncommitted blocks.
- class azure.storage.blob.ContainerClient(account_url: str, container_name: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any)[source]
A client to interact with a specific container, although that container may not yet exist.
For operations relating to a specific blob within this container, a blob client can be retrieved using the
get_blob_client()function.For more optional configuration, please click here.
- Parameters:
account_url (str) – The URI to the storage account. In order to create a client given the full URI to the container, use the
from_container_url()classmethod.container_name (str) – The name of the container for the blob.
credential – The credentials with which to authenticate. This is optional if the account URL already has a SAS token. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
api_version (str) –
The Storage API version to use for requests. Default value is the most recent service version that is compatible with the current SDK. Setting to an older version may result in reduced feature compatibility.
Added in version 12.2.0.
secondary_hostname (str) – The hostname of the secondary endpoint.
max_block_size (int) – The maximum chunk size for uploading a block blob in chunks. Defaults to 4*1024*1024, or 4MB.
max_single_put_size (int) – If the blob size is less than or equal max_single_put_size, then the blob will be uploaded with only one http PUT request. If the blob size is larger than max_single_put_size, the blob will be uploaded in chunks. Defaults to 64*1024*1024, or 64MB.
min_large_block_upload_threshold (int) – The minimum chunk size required to use the memory efficient algorithm when uploading a block blob. Defaults to 4*1024*1024+1.
use_byte_buffer (bool) – Use a byte buffer for block blob uploads. Defaults to False.
max_page_size (int) – The maximum chunk size for uploading a page blob. Defaults to 4*1024*1024, or 4MB.
max_single_get_size (int) – The maximum size for a blob to be downloaded in a single call, the exceeded part will be downloaded in chunks (could be parallel). Defaults to 32*1024*1024, or 32MB.
max_chunk_get_size (int) – The maximum chunk size used for downloading a blob. Defaults to 4*1024*1024, or 4MB.
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
Example:
Get a ContainerClient from an existing BlobServiceClient.# Instantiate a BlobServiceClient using a connection string from azure.storage.blob import BlobServiceClient blob_service_client = BlobServiceClient.from_connection_string(self.connection_string) # Instantiate a ContainerClient container_client = blob_service_client.get_container_client("mynewcontainer")
Creating the container client directly.from azure.storage.blob import ContainerClient sas_url = "https://account.blob.core.windows.net/mycontainer?sv=2015-04-05&st=2015-04-29T22%3A18%3A26Z&se=2015-04-30T02%3A23%3A26Z&sr=b&sp=rw&sip=168.1.5.60-168.1.5.70&spr=https&sig=Z%2FRHIX5Xcg0Mq2rqI3OlWTjEg2tYkboXr1P9ZUXDtkk%3D" container = ContainerClient.from_container_url(sas_url)
- classmethod from_connection_string(conn_str: str, container_name: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any) Self[source]
Create ContainerClient from a Connection String.
- Parameters:
conn_str (str) – A connection string to an Azure Storage account.
container_name (str) – The container name for the blob.
credential (AzureNamedKeyCredential or AzureSasCredential or TokenCredential or str or dict[str, str] or None) – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
- Returns:
A container client.
- Return type:
Example:
Creating the ContainerClient from a connection string.from azure.storage.blob import ContainerClient container_client = ContainerClient.from_connection_string( self.connection_string, container_name="mycontainer")
- classmethod from_container_url(container_url: str, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any) Self[source]
Create ContainerClient from a container url.
- Parameters:
container_url (str) – The full endpoint URL to the Container, including SAS token if used. This could be either the primary endpoint, or the secondary endpoint depending on the current location_mode.
credential (AzureNamedKeyCredential or AzureSasCredential or TokenCredential or str or dict[str, str] or None) – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
audience (str) – The audience to use when requesting tokens for Azure Active Directory authentication. Only has an effect when credential is of type TokenCredential. The value could be https://storage.azure.com/ (default) or https://<account>.blob.core.windows.net.
- Returns:
A container client.
- Return type:
- acquire_lease(lease_duration: int = -1, lease_id: str | None = None, **kwargs: Any) BlobLeaseClient[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:
lease_duration (int) – Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires. A non-infinite lease can be between 15 and 60 seconds. A lease duration cannot be changed using renew or change. Default is -1 (infinite lease).
lease_id (str) – Proposed lease ID, in a GUID string format. The Blob service returns 400 (Invalid request) if the proposed lease ID is not in the correct format.
- Keyword Arguments:
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A BlobLeaseClient object, that can be run in a context manager.
- Return type:
Example:
Acquiring a lease on the container.# Acquire a lease on the container lease = container_client.acquire_lease() # Delete container by passing in the lease container_client.delete_container(lease=lease)
- close() None
This method is to close the sockets opened by the client. It need not be used when using with a context manager.
- create_container(metadata: Dict[str, str] | None = None, public_access: PublicAccess | str | None = None, **kwargs: Any) Dict[str, str | datetime][source]
Creates a new container under the specified account. If the container with the same name already exists, the operation fails.
- Parameters:
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’.
- Keyword Arguments:
container_encryption_scope (dict or ContainerEncryptionScope) –
Specifies the default encryption scope to set on the container and use for all future writes.
Added in version 12.2.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
A dictionary of response headers.
- Return type:
Example:
Creating a container to store blobs.container_client.create_container()
- delete_blob(blob: str, delete_snapshots: str | None = None, **kwargs: Any) 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.
If a delete retention policy is enabled for the service, then this operation soft deletes the blob or snapshot and retains the blob or snapshot for specified number of days. After specified number of days, blob’s data is removed from the service during garbage collection. Soft deleted blob or snapshot is accessible through
list_blobs()specifying include=[“deleted”] option. Soft-deleted blob or snapshot can be restored usingundelete_blob()- Parameters:
- Keyword Arguments:
version_id (str) –
The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to delete.
Added in version 12.4.0.
This keyword argument was introduced in API version ‘2019-12-12’.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- Return type:
None
- delete_blobs(*blobs: str | Dict[str, Any] | BlobProperties, **kwargs: Any) Iterator[HttpResponse][source]
Marks the specified blobs or snapshots for deletion.
The blobs are later deleted during garbage collection. Note that in order to delete blobs, you must delete all of their snapshots. You can delete both at the same time with the delete_blobs operation.
If a delete retention policy is enabled for the service, then this operation soft deletes the blobs or snapshots and retains the blobs or snapshots for specified number of days. After specified number of days, blobs’ data is removed from the service during garbage collection. Soft deleted blobs or snapshots are accessible through
list_blobs()specifying include=[“deleted”] Soft-deleted blobs or snapshots can be restored usingundelete_blob()The maximum number of blobs that can be deleted in a single request is 256.
- Parameters:
blobs (Union[str, Dict[str, Any], BlobProperties]) –
The blobs to delete. This can be a single blob, or multiple values can be supplied, where each value is either the name of the blob (str) or BlobProperties.
Note
When the blob type is dict, here’s a list of keys, value rules.
- blob name:
key: ‘name’, value type: str
- snapshot you want to delete:
key: ‘snapshot’, value type: str
- version id:
key: ‘version_id’, value type: str
- whether to delete snapshots when deleting blob:
key: ‘delete_snapshots’, value: ‘include’ or ‘only’
- if the blob modified or not:
key: ‘if_modified_since’, ‘if_unmodified_since’, value type: datetime
- etag:
key: ‘etag’, value type: str
- match the etag or not:
key: ‘match_condition’, value type: MatchConditions
- tags match condition:
key: ‘if_tags_match_condition’, value type: str
- lease:
key: ‘lease_id’, value type: Union[str, LeaseClient]
- timeout for subrequest:
key: ‘timeout’, value type: int
- Keyword Arguments:
delete_snapshots (str) –
- Required if a blob has associated snapshots. Values include:
”only”: Deletes only the blobs snapshots.
”include”: Deletes the blob along with all 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_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
raise_on_any_failure (bool) – This is a boolean param which defaults to True. When this is set, an exception is raised even if there is a single operation failure.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterator of responses, one for each blob in order
- Return type:
Iterator[HttpResponse]
Example:
Deleting multiple blobs.# Delete multiple blobs in the container by name container_client.delete_blobs("my_blob1", "my_blob2") # Delete multiple blobs by properties iterator my_blobs = container_client.list_blobs(name_starts_with="my_blob") container_client.delete_blobs(*my_blobs)
- delete_container(**kwargs: Any) None[source]
Marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection.
- Keyword Arguments:
lease (BlobLeaseClient or 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.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
None
- Return type:
None
Example:
Delete a container.container_client.delete_container()
- download_blob(blob: str, offset: int | None = None, length: int | None = None, *, encoding: str | None = None, **kwargs: Any) StorageStreamDownloader[str] | StorageStreamDownloader[bytes][source]
Downloads a blob to the StorageStreamDownloader. The readall() method must be used to read all the content or readinto() must be used to download the blob into a stream. Using chunks() returns an iterator which allows the user to iterate over the content in chunks.
- Parameters:
- Keyword Arguments:
version_id (str) –
The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to download.
Added in version 12.4.0.
This keyword argument was introduced in API version ‘2019-12-12’.
validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
lease (BlobLeaseClient or str) – Required if the blob has an active lease. If specified, download_blob only succeeds if the blob’s lease is active and matches this ID. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
max_concurrency (int) – The number of parallel connections with which to download.
encoding (str) – Encoding to decode the downloaded bytes. Default is None, i.e. no decoding.
progress_hook (Callable[[int, int], None]) – A callback to track the progress of a long running download. The signature is function(current: int, total: int) where current is the number of bytes transferred so far, and total is the total size of the download.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here. This method may make multiple calls to the service and the timeout will apply to each call individually. multiple calls to the Azure service and the timeout will apply to each call individually.
- Returns:
A streaming object (StorageStreamDownloader)
- Return type:
- exists(**kwargs: Any) bool[source]
Returns True if a container exists and returns False otherwise.
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
boolean
- Return type:
- find_blobs_by_tags(filter_expression: str, **kwargs: Any) ItemPaged[FilteredBlob][source]
Returns a generator to list the blobs under the specified container whose tags match the given search expression. The generator will lazily follow the continuation tokens returned by the service.
- Parameters:
filter_expression (str) – The expression to find blobs whose tags matches the specified condition. eg. “”yourtagname”=’firsttag’ and “yourtagname2”=’secondtag’”
- Keyword Arguments:
results_per_page (int) – The max result per page when paginating.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterable (auto-paging) response of FilteredBlob.
- Return type:
- get_account_information(**kwargs: Any) Dict[str, str][source]
Gets information related to the storage account.
The information can also be retrieved if the user has a SAS to a container or blob. The keys in the returned dictionary include ‘sku_name’ and ‘account_kind’.
- get_blob_client(blob: str, snapshot: str | None = None, *, version_id: str | None = None) BlobClient[source]
Get a client to interact with the specified blob.
The blob need not already exist.
- Parameters:
blob (str) – The blob with which to interact.
snapshot (str) – The optional blob snapshot on which to operate. This can be the snapshot ID string or the response returned from
create_snapshot().
- Keyword Arguments:
version_id (str) – The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to operate on.
- Returns:
A BlobClient.
- Return type:
Example:
Get the blob client.# Get the BlobClient from the ContainerClient to interact with a specific blob blob_client = container_client.get_blob_client("mynewblob")
- get_container_access_policy(**kwargs: Any) Dict[str, Any][source]
Gets the permissions for the specified container. The permissions indicate whether container data may be accessed publicly.
- Keyword Arguments:
lease (BlobLeaseClient or str) – If specified, get_container_access_policy only succeeds if the container’s lease is active and matches this ID.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Access policy information in a dict.
- Return type:
Example:
Getting the access policy on the container.policy = container_client.get_container_access_policy()
- get_container_properties(**kwargs: Any) ContainerProperties[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.
- Keyword Arguments:
lease (BlobLeaseClient or str) – If specified, get_container_properties only succeeds if the container’s lease is active and matches this ID.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Properties for the specified container within a container object.
- Return type:
Example:
Getting properties on the container.properties = container_client.get_container_properties()
- list_blob_names(**kwargs: Any) ItemPaged[str][source]
Returns a generator to list the names of blobs under the specified container. The generator will lazily follow the continuation tokens returned by the service.
Note that no additional properties or metadata will be returned when using this API. Additionally, this API does not have an option to include additional blobs such as snapshots, versions, soft-deleted blobs, etc. To get any of this data, use
list_blobs().- Keyword Arguments:
name_starts_with (str) – Filters the results to return only blobs whose names begin with the specified prefix.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterable (auto-paging) response of blob names as strings.
- Return type:
- list_blobs(name_starts_with: str | None = None, include: str | List[str] | None = None, **kwargs: Any) ItemPaged[BlobProperties][source]
Returns a generator to list the blobs under the specified container. The generator will lazily follow the continuation tokens returned by the service.
- Parameters:
name_starts_with (str) – Filters the results to return only blobs whose names begin with the specified prefix.
include (list[str] or str) – Specifies one or more additional datasets to include in the response. Options include: ‘snapshots’, ‘metadata’, ‘uncommittedblobs’, ‘copy’, ‘deleted’, ‘deletedwithversions’, ‘tags’, ‘versions’, ‘immutabilitypolicy’, ‘legalhold’.
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterable (auto-paging) response of BlobProperties.
- Return type:
Example:
List the blobs in the container.blobs_list = container_client.list_blobs() for blob in blobs_list: print(blob.name + '\n')
- set_container_access_policy(signed_identifiers: Dict[str, AccessPolicy], public_access: PublicAccess | str | None = None, **kwargs: Any) Dict[str, str | datetime][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:
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’.
- Keyword Arguments:
lease (BlobLeaseClient or str) – Required if the container has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A datetime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified 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) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Container-updated property dict (Etag and last modified).
- Return type:
Example:
Setting access policy on the container.# Create access policy from azure.storage.blob import AccessPolicy, ContainerSasPermissions access_policy = AccessPolicy(permission=ContainerSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1), start=datetime.utcnow() - timedelta(minutes=1)) identifiers = {'test': access_policy} # Set the access policy on the container container_client.set_container_access_policy(signed_identifiers=identifiers)
- set_container_metadata(metadata: Dict[str, str] | None = None, **kwargs: Any) Dict[str, str | datetime][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:
metadata (dict[str, str]) – A dict containing name-value pairs to associate with the container as metadata. Example: {‘category’:’test’}
- Keyword Arguments:
lease (BlobLeaseClient or 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.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
Container-updated property dict (Etag and last modified).
- Return type:
Example:
Setting metadata on the container.# Create key, value pairs for metadata metadata = {'type': 'test'} # Set metadata on the container container_client.set_container_metadata(metadata=metadata)
Sets the page blob tiers on all blobs. This API is only supported for page blobs on premium accounts.
The maximum number of blobs that can be updated in a single request is 256.
- Parameters:
premium_page_blob_tier (PremiumPageBlobTier) –
A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
Note
If you want to set different tier on different blobs please set this positional parameter to None. Then the blob tier on every BlobProperties will be taken.
blobs (str or dict(str, Any) or BlobProperties) –
The blobs with which to interact. This can be a single blob, or multiple values can be supplied, where each value is either the name of the blob (str) or BlobProperties.
Note
When the blob type is dict, here’s a list of keys, value rules.
- blob name:
key: ‘name’, value type: str
- premium blob tier:
key: ‘blob_tier’, value type: PremiumPageBlobTier
- lease:
key: ‘lease_id’, value type: Union[str, LeaseClient]
- timeout for subrequest:
key: ‘timeout’, value type: int
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
raise_on_any_failure (bool) – This is a boolean param which defaults to True. When this is set, an exception is raised even if there is a single operation failure.
- Returns:
An iterator of responses, one for each blob in order
- Return type:
Iterator[HttpResponse]
- set_standard_blob_tier_blobs(standard_blob_tier: str | StandardBlobTier | None, *blobs: str | Dict[str, Any] | BlobProperties, **kwargs: Any) Iterator[HttpResponse][source]
This operation sets the tier on block blobs.
A block blob’s tier determines Hot/Cool/Archive storage type. This operation does not update the blob’s ETag.
The maximum number of blobs that can be updated in a single request is 256.
- Parameters:
standard_blob_tier (str or StandardBlobTier) –
Indicates the tier to be set on all blobs. Options include ‘Hot’, ‘Cool’, ‘Archive’. The hot tier is optimized for storing data that is accessed frequently. The cool storage tier is optimized for storing data that is infrequently accessed and stored for at least a month. The archive tier is optimized for storing data that is rarely accessed and stored for at least six months with flexible latency requirements.
Note
If you want to set different tier on different blobs please set this positional parameter to None. Then the blob tier on every BlobProperties will be taken.
blobs (str or dict(str, Any) or BlobProperties) –
The blobs with which to interact. This can be a single blob, or multiple values can be supplied, where each value is either the name of the blob (str) or BlobProperties.
Note
When the blob type is dict, here’s a list of keys, value rules.
- blob name:
key: ‘name’, value type: str
- standard blob tier:
key: ‘blob_tier’, value type: StandardBlobTier
- rehydrate priority:
key: ‘rehydrate_priority’, value type: RehydratePriority
- lease:
key: ‘lease_id’, value type: Union[str, LeaseClient]
- snapshot:
key: “snapshot”, value type: str
- version id:
key: “version_id”, value type: str
- tags match condition:
key: ‘if_tags_match_condition’, value type: str
- timeout for subrequest:
key: ‘timeout’, value type: int
- Keyword Arguments:
rehydrate_priority (RehydratePriority) – Indicates the priority with which to rehydrate an archived blob
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
raise_on_any_failure (bool) – This is a boolean param which defaults to True. When this is set, an exception is raised even if there is a single operation failure.
- Returns:
An iterator of responses, one for each blob in order
- Return type:
Iterator[HttpResponse]
- upload_blob(name: str, data: bytes | str | Iterable | IO, blob_type: str | BlobType = BlobType.BLOCKBLOB, length: int | None = None, metadata: Dict[str, str] | None = None, **kwargs) BlobClient[source]
Creates a new blob from a data source with automatic chunking.
- Parameters:
name (str) – The blob with which to interact.
data (Union[bytes, str, Iterable[AnyStr], IO[AnyStr]]) – The blob data to upload.
blob_type (BlobType) – The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob. The default value is BlockBlob.
length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
metadata (dict(str, str)) – Name-value pairs associated with the blob as metadata.
- Keyword Arguments:
overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob will overwrite the existing data. If set to False, the operation will fail with ResourceExistsError. The exception to the above is with Append blob types: if set to False and the data already exists, an error will not be raised and the data will be appended to the existing blob. If set overwrite=True, then the existing append blob will be deleted, and a new one created. Defaults to False.
content_settings (ContentSettings) – ContentSettings object used to set blob properties. Used to set content type, encoding, language, disposition, md5, and cache control.
validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https, as https (the default), will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
lease (BlobLeaseClient or str) – Required if the container has an active lease. Value can be a BlobLeaseClient object or the lease ID as a string.
if_modified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has been modified since the specified time.
if_unmodified_since (datetime) – A DateTime value. Azure expects the date value passed in to be UTC. If timezone is included, any non-UTC datetimes will be converted to UTC. If a date is passed in without timezone info, it is assumed to be UTC. Specify this header to perform the operation only if the resource has not been modified since the specified date/time.
etag (str) – An ETag value, or the wildcard character (*). Used to check if the resource has changed, and act according to the condition specified by the match_condition parameter.
match_condition (MatchConditions) – The match condition to use upon the etag.
if_tags_match_condition (str) –
Specify a SQL where clause on blob tags to operate only on blob with a matching value. eg.
"\"tagname\"='my tag'"Added in version 12.4.0.
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here. This method may make multiple calls to the service and the timeout will apply to each call individually.
premium_page_blob_tier (PremiumPageBlobTier) – A page blob tier value to set the blob to. The tier correlates to the size of the blob and number of allowed IOPS. This is only applicable to page blobs on premium storage accounts.
standard_blob_tier (StandardBlobTier) – A standard blob tier value to set the blob to. For this version of the library, this is only applicable to block blobs on standard storage accounts.
maxsize_condition (int) – Optional conditional header. The max length in bytes permitted for the append blob. If the Append Block operation would cause the blob to exceed that limit or if the blob size is already greater than the value specified in this header, the request will fail with MaxBlobSizeConditionNotMet error (HTTP status code 412 - Precondition Failed).
max_concurrency (int) – Maximum number of parallel connections to use when the blob size exceeds 64MB.
cpk (CustomerProvidedEncryptionKey) – Encrypts the data on the service-side with the given key. Use of customer-provided keys must be done over HTTPS. As the encryption key itself is provided in the request, a secure connection must be established to transfer the key.
encryption_scope (str) –
A predefined encryption scope used to encrypt the data on the service. An encryption scope can be created using the Management API and referenced here by name. If a default encryption scope has been defined at the container, this value will override it if the container-level scope is configured to allow overrides. Otherwise an error will be raised.
Added in version 12.2.0.
encoding (str) – Defaults to UTF-8.
progress_hook (Callable[[int, Optional[int]], None]) – A callback to track the progress of a long running upload. The signature is function(current: int, total: Optional[int]) where current is the number of bytes transferred so far, and total is the size of the blob or None if the size is unknown.
- Returns:
A BlobClient to interact with the newly uploaded blob.
- Return type:
Example:
Upload blob to the container.with open(SOURCE_FILE, "rb") as data: blob_client = container_client.upload_blob(name="myblob", data=data) properties = blob_client.get_blob_properties()
- walk_blobs(name_starts_with: str | None = None, include: str | List[str] | None = None, delimiter: str = '/', **kwargs: Any) ItemPaged[BlobProperties | BlobPrefix][source]
Returns a generator to list the blobs under the specified container. The generator will lazily follow the continuation tokens returned by the service. This operation will list blobs in accordance with a hierarchy, as delimited by the specified delimiter character.
- Parameters:
name_starts_with (str) – Filters the results to return only blobs whose names begin with the specified prefix.
include (list[str] or str) – Specifies one or more additional datasets to include in the response. Options include: ‘snapshots’, ‘metadata’, ‘uncommittedblobs’, ‘copy’, ‘deleted’, ‘deletedwithversions’, ‘tags’, ‘versions’, ‘immutabilitypolicy’, ‘legalhold’.
delimiter (str) – When the request includes this parameter, the operation returns a BlobPrefix element in the response body 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.
- Keyword Arguments:
timeout (int) – Sets the server-side timeout for the operation in seconds. For more details see https://learn.microsoft.com/rest/api/storageservices/setting-timeouts-for-blob-service-operations. This value is not tracked or validated on the client. To configure client-side network timesouts see here.
- Returns:
An iterable (auto-paging) response of BlobProperties or BlobPrefix.
- Return type:
- property location_mode: str
The location mode that the client is currently using.
By default this will be “primary”. Options include “primary” and “secondary”.
- Returns:
The current location mode.
- Return type:
- property primary_endpoint: str
The full primary endpoint URL.
- Returns:
The full primary endpoint URL.
- Return type:
- property primary_hostname: str
The hostname of the primary endpoint.
- Returns:
The hostname of the primary endpoint.
- Return type:
- property secondary_endpoint: str
The full secondary endpoint URL if configured.
If not available a ValueError will be raised. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
- Returns:
The full secondary endpoint URL.
- Return type:
- Raises:
ValueError – If no secondary endpoint is configured.
- property secondary_hostname: str | None
The hostname of the secondary endpoint.
If not available this will be None. To explicitly specify a secondary hostname, use the optional secondary_hostname keyword argument on instantiation.
- Returns:
The hostname of the secondary endpoint, or None if not configured.
- Return type:
Optional[str]
- property url: str
The full endpoint URL to this entity, including SAS token if used.
This could be either the primary endpoint, or the secondary endpoint depending on the current
location_mode().- Returns:
The full endpoint URL to this entity, including SAS token if used.
- Return type:
- class azure.storage.blob.ContainerEncryptionScope(default_encryption_scope: str, **kwargs: Any)[source]
The default encryption scope configuration for a container.
This scope is used implicitly for all future writes within the container, but can be overridden per blob operation.
Added in version 12.2.0.
- Parameters:
default_encryption_scope (str) – Specifies the default encryption scope to set on the container and use for all future writes.
prevent_encryption_scope_override (bool) – If true, prevents any request from specifying a different encryption scope than the scope set on the container. Default value is false.
- class azure.storage.blob.ContainerProperties(**kwargs: Any)[source]
Blob container’s properties class.
Returned
ContainerPropertiesinstances expose these values through a dictionary interface, for example:container_props["last_modified"]. Additionally, the container name is available ascontainer_props["name"].- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- encryption_scope: ContainerEncryptionScope | None
The default encryption scope configuration for the container.
- immutable_storage_with_versioning_enabled: bool
Represents whether immutable storage with versioning enabled on the container.
- last_modified: datetime
A datetime object representing the last time the container was modified.
- lease: LeaseProperties
Stores all the lease information for the container.
- class azure.storage.blob.ContainerSasPermissions(read: bool = False, write: bool = False, delete: bool = False, list: bool = False, delete_previous_version: bool = False, tag: bool = False, **kwargs: Any)[source]
ContainerSasPermissions class to be used with the
generate_container_sas()function and for the AccessPolicies used withset_container_access_policy().- Parameters:
read (bool) – Read the content, properties, metadata or block list of any blob in the container. Use any blob in the container as the source of a copy operation.
write (bool) – For any blob in the container, create or write content, properties, metadata, or block list. Snapshot or lease the blob. Resize the blob (page blob only). Use the blob as the destination of a copy operation within the same account. Note: You cannot grant permissions to read or write container properties or metadata, nor to lease a container, with a container SAS. Use an account SAS instead.
delete (bool) – Delete any blob in the container. Note: You cannot grant permissions to delete a container with a container SAS. Use an account SAS instead.
delete_previous_version (bool) – Delete the previous blob version for the versioning enabled storage account.
list (bool) – List blobs in the container.
tag (bool) – Set or get tags on the blobs in the container.
- Keyword Arguments:
add (bool) – Add a block to an append blob.
create (bool) – Write a new blob, snapshot a blob, or copy a blob to a new blob.
permanent_delete (bool) – To enable permanent delete on the blob is permitted.
filter_by_tags (bool) – To enable finding blobs by tags.
move (bool) – Move a blob or a directory and its contents to a new location.
execute (bool) – Get the system properties and, if the hierarchical namespace is enabled for the storage account, get the POSIX ACL of a blob.
set_immutability_policy (bool) – To enable operations related to set/delete immutability policy. To get immutability policy, you just need read permission.
- classmethod from_string(permission: str) ContainerSasPermissions[source]
Create a ContainerSasPermissions from a string.
To specify read, write, delete, or list permissions you need only to include the first letter of the word in the string. E.g. For read and write permissions, you would provide a string “rw”.
- Parameters:
permission (str) – The string which dictates the read, write, delete, and list permissions.
- Returns:
A ContainerSasPermissions object
- Return type:
- delete_previous_version: bool = False
Permission to delete previous blob version for versioning enabled storage accounts.
- class azure.storage.blob.ContentSettings(content_type: str | None = None, content_encoding: str | None = None, content_language: str | None = None, content_disposition: str | None = None, cache_control: str | None = None, content_md5: bytearray | None = None, **kwargs: Any)[source]
The content settings of a blob.
- Parameters:
content_type (Optional[str]) – The content type specified for the blob. If no content type was specified, the default content type is application/octet-stream.
content_encoding (Optional[str]) – If the content_encoding has previously been set for the blob, that value is stored.
content_language (Optional[str]) – If the content_language has previously been set for the blob, that value is stored.
content_disposition (Optional[str]) – content_disposition conveys additional information about how to process the response payload, and also can be used to attach additional metadata. If content_disposition has previously been set for the blob, that value is stored.
cache_control (Optional[str]) – If the cache_control has previously been set for the blob, that value is stored.
content_md5 (Optional[bytearray]) – If the content_md5 has been set for the blob, this response header is stored so that the client can check for message content integrity.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.CopyProperties(**kwargs: Any)[source]
Blob Copy Properties.
These properties will be None if this blob has never been the destination in a Copy Blob operation, or if this blob has been modified after a concluded Copy Blob operation, for example, using Set Blob Properties, Upload Blob, or Commit Block List.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- completion_time: datetime | None
Conclusion time of the last attempted Copy Blob operation where this blob was the destination blob. This value can specify the time of a completed, aborted, or failed copy attempt.
- destination_snapshot: datetime | None
Included if the blob is incremental copy blob or incremental copy snapshot, if x-ms-copy-status is success. Snapshot time of the last successful incremental copy snapshot for this blob.
- id: str | None
String identifier for the last attempted Copy Blob operation where this blob was the destination blob.
- incremental_copy: bool | None
Copies the snapshot of the source page blob to a destination page blob. The snapshot is copied such that only the differential changes between the previously copied snapshot are transferred to the destination.
- progress: str | None
Contains the number of bytes copied and the total bytes in the source in the last attempted Copy Blob operation where this blob was the destination blob. Can show between 0 and Content-Length bytes copied.
- source: str | None
URL up to 2 KB in length that specifies the source blob used in the last attempted Copy Blob operation where this blob was the destination blob.
- status: str | None
State of the copy operation identified by Copy ID, with these values: success: Copy completed successfully. pending: Copy is in progress. Check copy_status_description if intermittent, non-fatal errors impede copy progress but don’t cause failure. aborted: Copy was ended by Abort Copy Blob. failed: Copy failed. See copy_status_description for failure details.
- class azure.storage.blob.CorsRule(allowed_origins: List[str], allowed_methods: List[str], **kwargs: Any)[source]
CORS is an HTTP feature that enables a web application running under one domain to access resources in another domain. Web browsers implement a security restriction known as same-origin policy that prevents a web page from calling APIs in a different domain; CORS provides a secure way to allow one domain (the origin domain) to call APIs in another domain.
- Parameters:
allowed_origins (list(str)) – A list of origin domains that will be allowed via CORS, or “*” to allow all domains. The list of must contain at least one entry. Limited to 64 origin domains. Each allowed origin can have up to 256 characters.
allowed_methods (list(str)) – A list of HTTP methods that are allowed to be executed by the origin. The list of must contain at least one entry. For Azure Storage, permitted methods are DELETE, GET, HEAD, MERGE, POST, OPTIONS or PUT.
- Keyword Arguments:
allowed_headers (str) – Defaults to an empty list. A list of headers allowed to be part of the cross-origin request. Limited to 64 defined headers and 2 prefixed headers. Each header can be up to 256 characters.
exposed_headers (str) – Defaults to an empty list. A list of response headers to expose to CORS clients. Limited to 64 defined headers and two prefixed headers. Each header can be up to 256 characters.
max_age_in_seconds (int) – The number of seconds that the client/browser should cache a preflight response.
allowed_origins (str) – The origin domains that are permitted to make a request against the storage service via CORS. The origin domain is the domain from which the request originates. Note that the origin must be an exact case-sensitive match with the origin that the user age sends to the service. You can also use the wildcard character ‘*’ to allow all origin domains to make requests via CORS. Required.
allowed_methods (str) – The methods (HTTP request verbs) that the origin domain may use for a CORS request. (comma separated). Required.
allowed_headers – the request headers that the origin domain may specify on the CORS request. Required.
exposed_headers – The response headers that may be sent in the response to the CORS request and exposed by the browser to the request issuer. Required.
max_age_in_seconds – The maximum amount time that a browser should cache the preflight OPTIONS request. Required.
- classmethod deserialize(data: Any, content_type: str | None = None) Self
Parse a str using the RestAPI syntax and return a model.
- classmethod from_dict(data: Any, key_extractors: Callable[[str, Dict[str, Any], Any], Any] | None = None, content_type: str | None = None) Self
Parse a dict using given key extractor return a model.
By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)
- as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, ~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) MutableMapping[str, Any]
Return a dict that can be serialized using json.dump.
Advanced usage might optionally use a callback as parameter:
Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.
The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.
See the three examples in this file:
attribute_transformer
full_restapi_key_transformer
last_restapi_key_transformer
If you want XML serialization, you can pass the kwargs is_xml=True.
- serialize(keep_readonly: bool = False, **kwargs: Any) MutableMapping[str, Any]
Return the JSON that would be sent to server from this model.
This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).
If you want XML serialization, you can pass the kwargs is_xml=True.
- allowed_headers: str
The comma-delimited string representation of the list of headers allowed to be part of the cross-origin request.
- allowed_methods: str
The comma-delimited string representation of the list HTTP methods that are allowed to be executed by the origin.
- allowed_origins: str
The comma-delimited string representation of the list of origin domains that will be allowed via CORS, or “*” to allow all domains.
- class azure.storage.blob.CustomerProvidedEncryptionKey(key_value: str, key_hash: str)[source]
All data in Azure Storage is encrypted at-rest using an account-level encryption key. In versions 2018-06-17 and newer, you can manage the key used to encrypt blob contents and application metadata per-blob by providing an AES-256 encryption key in requests to the storage service.
When you use a customer-provided key, Azure Storage does not manage or persist your key. When writing data to a blob, the provided key is used to encrypt your data before writing it to disk. A SHA-256 hash of the encryption key is written alongside the blob contents, and is used to verify that all subsequent operations against the blob use the same encryption key. This hash cannot be used to retrieve the encryption key or decrypt the contents of the blob. When reading a blob, the provided key is used to decrypt your data after reading it from disk. In both cases, the provided encryption key is securely discarded as soon as the encryption or decryption process completes.
- Parameters:
- class azure.storage.blob.DelimitedJsonDialect(**kwargs: Any)[source]
Defines the input or output JSON serialization for a blob data query.
- Keyword Arguments:
delimiter (str) – The line separator character, default value is ‘\n’.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.DelimitedTextDialect(**kwargs: Any)[source]
Defines the input or output delimited (CSV) serialization for a blob query request.
- Keyword Arguments:
delimiter (str) – Column separator, defaults to ‘,’.
quotechar (str) – Field quote, defaults to ‘”’.
lineterminator (str) – Record separator, defaults to ‘\n’.
escapechar (str) – Escape char, defaults to empty.
has_header (bool) – Whether the blob data includes headers in the first line. The default value is False, meaning that the data will be returned inclusive of the first line. If set to True, the data will be returned exclusive of the first line.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.ExponentialRetry(initial_backoff: int = 15, increment_base: int = 3, retry_total: int = 3, retry_to_secondary: bool = False, random_jitter_range: int = 3, **kwargs: Any)[source]
Exponential retry.
Constructs an Exponential retry object. The initial_backoff is used for the first retry. Subsequent retries are retried after initial_backoff + increment_power^retry_count seconds.
- Parameters:
initial_backoff (int) – The initial backoff interval, in seconds, for the first retry.
increment_base (int) – The base, in seconds, to increment the initial_backoff by after the first retry.
retry_total (int) – The maximum number of retry attempts.
retry_to_secondary (bool) – Whether the request should be retried to secondary, if able. This should only be enabled of RA-GRS accounts are used and potentially stale data can be handled.
random_jitter_range (int) – A number in seconds which indicates a range to jitter/randomize for the back-off interval. For example, a random_jitter_range of 3 results in the back-off interval x to vary between x+3 and x-3.
- configure_retries(request: PipelineRequest) Dict[str, Any]
Configure the retry settings for the request.
- Parameters:
request (PipelineRequest) – A pipeline request object.
- Returns:
A dictionary containing the retry settings.
- Return type:
Dict[str, Any]
- get_backoff_time(settings: Dict[str, Any]) float[source]
Calculates how long to sleep before retrying.
- increment(settings: Dict[str, Any], request: PipelineRequest, response: PipelineResponse | None = None, error: AzureError | None = None) bool
Increment the retry counters.
- Parameters:
settings (Dict[str, Any]) – The configurable values pertaining to the increment operation.
request (PipelineRequest) – A pipeline request object.
response (PipelineResponse or None) – A pipeline response object.
error (AzureError or None) – An error encountered during the request, or None if the response was received successfully.
- Returns:
Whether the retry attempts are exhausted.
- Return type:
- send(request)
Send the request with retry logic.
- Parameters:
request (PipelineRequest) – A pipeline request object.
- Returns:
A pipeline response object.
- Return type:
- sleep(settings, transport)
Sleep for the backoff time.
- Parameters:
settings (Dict[str, Any]) – The configurable values pertaining to the sleep operation.
transport (AsyncioBaseTransport or BaseTransport) – The transport to use for sleeping.
- increment_base: int
The base, in seconds, to increment the initial_backoff by after the first retry.
- next: HTTPPolicy[HTTPRequestType, HTTPResponseType]
Pointer to the next policy or a transport (wrapped as a policy). Will be set at pipeline creation.
- class azure.storage.blob.FilteredBlob(**kwargs: Any)[source]
Blob info from a Filter Blobs API call.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.ImmutabilityPolicy(**kwargs: Any)[source]
Optional parameters for setting the immutability policy of a blob, blob snapshot or blob version.
Added in version 12.10.0: This was introduced in API version ‘2020-10-02’.
- Keyword Arguments:
expiry_time (datetime) – Specifies the date time when the blobs immutability policy is set to expire.
policy_mode (str or BlobImmutabilityPolicyMode) – Specifies the immutability policy mode to set on the blob. Possible values to set include: “Locked”, “Unlocked”. “Mutable” can only be returned by service, don’t set to “Mutable”.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.LeaseProperties(**kwargs: Any)[source]
Blob Lease Properties.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.LinearRetry(backoff: int = 15, retry_total: int = 3, retry_to_secondary: bool = False, random_jitter_range: int = 3, **kwargs: Any)[source]
Linear retry.
Constructs a Linear retry object.
- Parameters:
backoff (int) – The backoff interval, in seconds, between retries.
retry_total (int) – The maximum number of retry attempts.
retry_to_secondary (bool) – Whether the request should be retried to secondary, if able. This should only be enabled of RA-GRS accounts are used and potentially stale data can be handled.
random_jitter_range (int) – A number in seconds which indicates a range to jitter/randomize for the back-off interval. For example, a random_jitter_range of 3 results in the back-off interval x to vary between x+3 and x-3.
- configure_retries(request: PipelineRequest) Dict[str, Any]
Configure the retry settings for the request.
- Parameters:
request (PipelineRequest) – A pipeline request object.
- Returns:
A dictionary containing the retry settings.
- Return type:
Dict[str, Any]
- get_backoff_time(settings: Dict[str, Any]) float[source]
Calculates how long to sleep before retrying.
- increment(settings: Dict[str, Any], request: PipelineRequest, response: PipelineResponse | None = None, error: AzureError | None = None) bool
Increment the retry counters.
- Parameters:
settings (Dict[str, Any]) – The configurable values pertaining to the increment operation.
request (PipelineRequest) – A pipeline request object.
response (PipelineResponse or None) – A pipeline response object.
error (AzureError or None) – An error encountered during the request, or None if the response was received successfully.
- Returns:
Whether the retry attempts are exhausted.
- Return type:
- send(request)
Send the request with retry logic.
- Parameters:
request (PipelineRequest) – A pipeline request object.
- Returns:
A pipeline response object.
- Return type:
- sleep(settings, transport)
Sleep for the backoff time.
- Parameters:
settings (Dict[str, Any]) – The configurable values pertaining to the sleep operation.
transport (AsyncioBaseTransport or BaseTransport) – The transport to use for sleeping.
- next: HTTPPolicy[HTTPRequestType, HTTPResponseType]
Pointer to the next policy or a transport (wrapped as a policy). Will be set at pipeline creation.
- class azure.storage.blob.LocationMode[source]
Specifies the location the request should be sent to. This mode only applies for RA-GRS accounts which allow secondary read access. All other account types must use PRIMARY.
- PRIMARY = 'primary'
Requests should be sent to the primary location.
- SECONDARY = 'secondary'
Requests should be sent to the secondary location, if possible.
- class azure.storage.blob.Metrics(**kwargs: Any)[source]
A summary of request statistics grouped by API in hour or minute aggregates for blobs.
- Keyword Arguments:
version (str) – The version of Storage Analytics to configure. The default value is 1.0.
enabled (bool) – Indicates whether metrics are enabled for the Blob service. The default value is False.
include_apis (bool) – Indicates whether metrics should generate summary statistics for called API operations.
retention_policy (RetentionPolicy) – Determines how long the associated data should persist. If not specified the retention policy will be disabled by default.
version – The version of Storage Analytics to configure.
enabled – Indicates whether metrics are enabled for the Blob service. Required.
include_apis – Indicates whether metrics should generate summary statistics for called API operations.
retention_policy – the retention policy which determines how long the associated data should persist.
- classmethod deserialize(data: Any, content_type: str | None = None) Self
Parse a str using the RestAPI syntax and return a model.
- classmethod from_dict(data: Any, key_extractors: Callable[[str, Dict[str, Any], Any], Any] | None = None, content_type: str | None = None) Self
Parse a dict using given key extractor return a model.
By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)
- as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, ~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) MutableMapping[str, Any]
Return a dict that can be serialized using json.dump.
Advanced usage might optionally use a callback as parameter:
Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.
The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.
See the three examples in this file:
attribute_transformer
full_restapi_key_transformer
last_restapi_key_transformer
If you want XML serialization, you can pass the kwargs is_xml=True.
- serialize(keep_readonly: bool = False, **kwargs: Any) MutableMapping[str, Any]
Return the JSON that would be sent to server from this model.
This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).
If you want XML serialization, you can pass the kwargs is_xml=True.
- include_apis: bool | None
Indicates whether metrics should generate summary statistics for called API operations.
- retention_policy: RetentionPolicy = <azure.storage.blob._models.RetentionPolicy object>
Determines how long the associated data should persist.
- class azure.storage.blob.ObjectReplicationPolicy(**kwargs: Any)[source]
Policy id and rule ids applied to a blob.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- policy_id: str
Policy id for the blob. A replication policy gets created (policy id) when creating a source/destination pair.
- rules: List[ObjectReplicationRule]
Within each policy there may be multiple replication rules. e.g. rule 1= src/container/.pdf to dst/container2/; rule2 = src/container1/.jpg to dst/container3
- class azure.storage.blob.ObjectReplicationRule(**kwargs: Any)[source]
Policy id and rule ids applied to a blob.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.PageRange(start: int | None = None, end: int | None = None, *, cleared: bool = False)[source]
Page Range for page blob.
- get(key, default=None)
- has_key(k)
- items()
- keys()
- update(*args, **kwargs)
- values()
- class azure.storage.blob.PremiumPageBlobTier(*values)[source]
Specifies the page blob tier to set the blob to. This is only applicable to page blobs on premium storage accounts. Please take a look at: https://learn.microsoft.com/azure/storage/storage-premium-storage#scalability-and-performance-targets for detailed information on the corresponding IOPS and throughput per PageBlobTier.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- P10 = 'P10'
P10 Tier
- P15 = 'P15'
P15 Tier
- P20 = 'P20'
P20 Tier
- P30 = 'P30'
P30 Tier
- P4 = 'P4'
P4 Tier
- P40 = 'P40'
P40 Tier
- P50 = 'P50'
P50 Tier
- P6 = 'P6'
P6 Tier
- P60 = 'P60'
P60 Tier
- class azure.storage.blob.PublicAccess(*values)[source]
Specifies whether data in the container may be accessed publicly and the level of access.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- BLOB = 'blob'
Specifies public read access for blobs. Blob data within this container can be read via anonymous request, but container data is not available. Clients cannot enumerate blobs within the container via anonymous request.
- CONTAINER = 'container'
Specifies full public read access for container and blob data. Clients can enumerate blobs within the container via anonymous request, but cannot enumerate containers within the storage account.
- OFF = 'off'
Specifies that there is no public read access for both the container and blobs within the container. Clients cannot enumerate the containers within the storage account as well as the blobs within the container.
- class azure.storage.blob.QuickQueryDialect(*values)[source]
Specifies the quick query input/output dialect.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- DELIMITEDJSON = 'DelimitedJsonDialect'
- DELIMITEDTEXT = 'DelimitedTextDialect'
- PARQUET = 'ParquetDialect'
- class azure.storage.blob.RehydratePriority(*values)[source]
If an object is in rehydrate pending state then this header is returned with priority of rehydrate. Valid values are High and Standard.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- HIGH = 'High'
- STANDARD = 'Standard'
- class azure.storage.blob.ResourceTypes(service: bool = False, container: bool = False, object: bool = False)[source]
Specifies the resource types that are accessible with the account SAS.
- Parameters:
service (bool) – Access to service-level APIs (e.g., Get/Set Service Properties, Get Service Stats, List Containers/Queues/Shares)
container (bool) – Access to container-level APIs (e.g., Create/Delete Container, Create/Delete Queue, Create/Delete Share, List Blobs/Files and Directories)
object (bool) – Access to object-level APIs for blobs, queue messages, and files(e.g. Put Blob, Query Entity, Get Messages, Create File, etc.)
- classmethod from_string(string)[source]
Create a ResourceTypes from a string.
To specify service, container, or object you need only to include the first letter of the word in the string. E.g. service and container, you would provide a string “sc”.
- Parameters:
string (str) – Specify service, container, or object in in the string with the first letter of the word.
- Returns:
A ResourceTypes object
- Return type:
- class azure.storage.blob.RetentionPolicy(enabled: bool = False, days: int | None = None)[source]
The retention policy which determines how long the associated data should persist.
- Parameters:
enabled (bool) – Indicates whether a retention policy is enabled for the storage service. The default value is False.
days (Optional[int]) – Indicates the number of days that metrics or logging or soft-deleted data should be retained. All data older than this value will be deleted. If enabled=True, the number of days must be specified.
- Keyword Arguments:
enabled (bool) – Indicates whether a retention policy is enabled for the storage service. Required.
days (int) – Indicates the number of days that metrics or logging or soft-deleted data should be retained. All data older than this value will be deleted.
allow_permanent_delete (bool) – Indicates whether permanent delete is allowed on this storage account.
- classmethod deserialize(data: Any, content_type: str | None = None) Self
Parse a str using the RestAPI syntax and return a model.
- classmethod from_dict(data: Any, key_extractors: Callable[[str, Dict[str, Any], Any], Any] | None = None, content_type: str | None = None) Self
Parse a dict using given key extractor return a model.
By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)
- as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, ~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) MutableMapping[str, Any]
Return a dict that can be serialized using json.dump.
Advanced usage might optionally use a callback as parameter:
Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.
The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.
See the three examples in this file:
attribute_transformer
full_restapi_key_transformer
last_restapi_key_transformer
If you want XML serialization, you can pass the kwargs is_xml=True.
- class azure.storage.blob.SequenceNumberAction(*values)[source]
Sequence number actions.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- INCREMENT = 'increment'
Increments the value of the sequence number by 1. If specifying this option, do not include the x-ms-blob-sequence-number header.
- MAX = 'max'
Sets the sequence number to be the higher of the value included with the request and the value currently stored for the blob.
- UPDATE = 'update'
Sets the sequence number to the value included with the request.
- class azure.storage.blob.Services(*, blob: bool = False, queue: bool = False, fileshare: bool = False)[source]
Specifies the services accessible with the account SAS.
- Keyword Arguments:
- class azure.storage.blob.StandardBlobTier(*values)[source]
Specifies the blob tier to set the blob to. This is only applicable for block blobs on standard storage accounts.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- ARCHIVE = 'Archive'
Archive
- COLD = 'Cold'
Cold
- COOL = 'Cool'
Cool
- HOT = 'Hot'
Hot
- class azure.storage.blob.StaticWebsite(**kwargs: Any)[source]
The properties that enable an account to host a static website.
- Keyword Arguments:
enabled (bool) – Indicates whether this account is hosting a static website. The default value is False.
index_document (str) – The default name of the index page under each directory.
error_document404_path (str) – The absolute path of the custom 404 page.
default_index_document_path (str) – Absolute path of the default index page.
enabled – Indicates whether this account is hosting a static website. Required.
index_document – The default name of the index page under each directory.
error_document404_path – The absolute path of the custom 404 page.
default_index_document_path – Absolute path of the default index page.
- classmethod deserialize(data: Any, content_type: str | None = None) Self
Parse a str using the RestAPI syntax and return a model.
- classmethod from_dict(data: Any, key_extractors: Callable[[str, Dict[str, Any], Any], Any] | None = None, content_type: str | None = None) Self
Parse a dict using given key extractor return a model.
By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)
- as_dict(keep_readonly: bool = True, key_transformer: ~typing.Callable[[str, ~typing.Dict[str, ~typing.Any], ~typing.Any], ~typing.Any] = <function attribute_transformer>, **kwargs: ~typing.Any) MutableMapping[str, Any]
Return a dict that can be serialized using json.dump.
Advanced usage might optionally use a callback as parameter:
Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.
The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.
See the three examples in this file:
attribute_transformer
full_restapi_key_transformer
last_restapi_key_transformer
If you want XML serialization, you can pass the kwargs is_xml=True.
- class azure.storage.blob.StorageErrorCode(*values)[source]
Error codes returned by the service.
- static maketrans()
Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode ordinals (integers) or characters to Unicode ordinals, strings or None. Character keys will be then converted to ordinals. If there are two arguments, they must be strings of equal length, and in the resulting dictionary, each character in x will be mapped to the character at the same position in y. If there is a third argument, it must be a string, whose characters will be mapped to None in the result.
- capitalize()
Return a capitalized version of the string.
More specifically, make the first character have upper case and the rest lower case.
- casefold()
Return a version of the string suitable for caseless comparisons.
- center(width, fillchar=' ', /)
Return a centered string of length width.
Padding is done using the specified fill character (default is a space).
- count()
Return the number of non-overlapping occurrences of substring sub in string S[start:end].
Optional arguments start and end are interpreted as in slice notation.
- encode(encoding='utf-8', errors='strict')
Encode the string using the codec registered for encoding.
- encoding
The encoding in which to encode the string.
- errors
The error handling scheme to use for encoding errors. The default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.
- endswith()
Return True if the string ends with the specified suffix, False otherwise.
- suffix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- expandtabs(tabsize=8)
Return a copy where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed.
- find()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- format(*args, **kwargs)
Return a formatted version of the string, using substitutions from args and kwargs. The substitutions are identified by braces (‘{’ and ‘}’).
- format_map(mapping, /)
Return a formatted version of the string, using substitutions from mapping. The substitutions are identified by braces (‘{’ and ‘}’).
- index()
Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- isalnum()
Return True if the string is an alpha-numeric string, False otherwise.
A string is alpha-numeric if all characters in the string are alpha-numeric and there is at least one character in the string.
- isalpha()
Return True if the string is an alphabetic string, False otherwise.
A string is alphabetic if all characters in the string are alphabetic and there is at least one character in the string.
- isascii()
Return True if all characters in the string are ASCII, False otherwise.
ASCII characters have code points in the range U+0000-U+007F. Empty string is ASCII too.
- isdecimal()
Return True if the string is a decimal string, False otherwise.
A string is a decimal string if all characters in the string are decimal and there is at least one character in the string.
- isdigit()
Return True if the string is a digit string, False otherwise.
A string is a digit string if all characters in the string are digits and there is at least one character in the string.
- isidentifier()
Return True if the string is a valid Python identifier, False otherwise.
Call keyword.iskeyword(s) to test whether string s is a reserved identifier, such as “def” or “class”.
- islower()
Return True if the string is a lowercase string, False otherwise.
A string is lowercase if all cased characters in the string are lowercase and there is at least one cased character in the string.
- isnumeric()
Return True if the string is a numeric string, False otherwise.
A string is numeric if all characters in the string are numeric and there is at least one character in the string.
- isprintable()
Return True if all characters in the string are printable, False otherwise.
A character is printable if repr() may use it in its output.
- isspace()
Return True if the string is a whitespace string, False otherwise.
A string is whitespace if all characters in the string are whitespace and there is at least one character in the string.
- istitle()
Return True if the string is a title-cased string, False otherwise.
In a title-cased string, upper- and title-case characters may only follow uncased characters and lowercase characters only cased ones.
- isupper()
Return True if the string is an uppercase string, False otherwise.
A string is uppercase if all cased characters in the string are uppercase and there is at least one cased character in the string.
- join(iterable, /)
Concatenate any number of strings.
The string whose method is called is inserted in between each given string. The result is returned as a new string.
Example: ‘.’.join([‘ab’, ‘pq’, ‘rs’]) -> ‘ab.pq.rs’
- ljust(width, fillchar=' ', /)
Return a left-justified string of length width.
Padding is done using the specified fill character (default is a space).
- lower()
Return a copy of the string converted to lowercase.
- lstrip(chars=None, /)
Return a copy of the string with leading whitespace removed.
If chars is given and not None, remove characters in chars instead.
- partition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing the original string and two empty strings.
- removeprefix(prefix, /)
Return a str with the given prefix string removed if present.
If the string starts with the prefix string, return string[len(prefix):]. Otherwise, return a copy of the original string.
- removesuffix(suffix, /)
Return a str with the given suffix string removed if present.
If the string ends with the suffix string and that suffix is not empty, return string[:-len(suffix)]. Otherwise, return a copy of the original string.
- replace(old, new, /, count=-1)
Return a copy with all occurrences of substring old replaced by new.
- count
Maximum number of occurrences to replace. -1 (the default value) means replace all occurrences.
If the optional argument count is given, only the first count occurrences are replaced.
- rfind()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
- rindex()
Return the highest index in S where substring sub is found, such that sub is contained within S[start:end].
Optional arguments start and end are interpreted as in slice notation. Raises ValueError when the substring is not found.
- rjust(width, fillchar=' ', /)
Return a right-justified string of length width.
Padding is done using the specified fill character (default is a space).
- rpartition(sep, /)
Partition the string into three parts using the given separator.
This will search for the separator in the string, starting at the end. If the separator is found, returns a 3-tuple containing the part before the separator, the separator itself, and the part after it.
If the separator is not found, returns a 3-tuple containing two empty strings and the original string.
- rsplit(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the end of the string and works to the front.
- rstrip(chars=None, /)
Return a copy of the string with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- split(sep=None, maxsplit=-1)
Return a list of the substrings in the string, using sep as the separator string.
- sep
The separator used to split the string.
When set to None (the default value), will split on any whitespace character (including n r t f and spaces) and will discard empty strings from the result.
- maxsplit
Maximum number of splits. -1 (the default value) means no limit.
Splitting starts at the front of the string and works to the end.
Note, str.split() is mainly useful for data that has been intentionally delimited. With natural text that includes punctuation, consider using the regular expression module.
- splitlines(keepends=False)
Return a list of the lines in the string, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends is given and true.
- startswith()
Return True if the string starts with the specified prefix, False otherwise.
- prefix
A string or a tuple of strings to try.
- start
Optional start position. Default: start of the string.
- end
Optional stop position. Default: end of the string.
- strip(chars=None, /)
Return a copy of the string with leading and trailing whitespace removed.
If chars is given and not None, remove characters in chars instead.
- swapcase()
Convert uppercase characters to lowercase and lowercase characters to uppercase.
- title()
Return a version of the string where each word is titlecased.
More specifically, words start with uppercased characters and all remaining cased characters have lower case.
- translate(table, /)
Replace each character in the string using the given translation table.
- table
Translation table, which must be a mapping of Unicode ordinals to Unicode ordinals, strings, or None.
The table must implement lookup/indexing via __getitem__, for instance a dictionary or list. If this operation raises LookupError, the character is left untouched. Characters mapped to None are deleted.
- upper()
Return a copy of the string converted to uppercase.
- zfill(width, /)
Pad a numeric string with zeros on the left, to fill a field of the given width.
The string is never truncated.
- ACCOUNT_ALREADY_EXISTS = 'AccountAlreadyExists'
- ACCOUNT_BEING_CREATED = 'AccountBeingCreated'
- ACCOUNT_IS_DISABLED = 'AccountIsDisabled'
- APPEND_POSITION_CONDITION_NOT_MET = 'AppendPositionConditionNotMet'
- AUTHENTICATION_FAILED = 'AuthenticationFailed'
- AUTHORIZATION_FAILURE = 'AuthorizationFailure'
- BLOB_ACCESS_TIER_NOT_SUPPORTED_FOR_ACCOUNT_TYPE = 'BlobAccessTierNotSupportedForAccountType'
- BLOB_ALREADY_EXISTS = 'BlobAlreadyExists'
- BLOB_ARCHIVED = 'BlobArchived'
- BLOB_BEING_REHYDRATED = 'BlobBeingRehydrated'
- BLOB_NOT_ARCHIVED = 'BlobNotArchived'
- BLOB_NOT_FOUND = 'BlobNotFound'
- BLOB_OVERWRITTEN = 'BlobOverwritten'
- BLOB_TIER_INADEQUATE_FOR_CONTENT_LENGTH = 'BlobTierInadequateForContentLength'
- BLOCK_COUNT_EXCEEDS_LIMIT = 'BlockCountExceedsLimit'
- BLOCK_LIST_TOO_LONG = 'BlockListTooLong'
- CANNOT_CHANGE_TO_LOWER_TIER = 'CannotChangeToLowerTier'
- CANNOT_DELETE_FILE_OR_DIRECTORY = 'CannotDeleteFileOrDirectory'
- CANNOT_VERIFY_COPY_SOURCE = 'CannotVerifyCopySource'
- CLIENT_CACHE_FLUSH_DELAY = 'ClientCacheFlushDelay'
- CONDITION_HEADERS_NOT_SUPPORTED = 'ConditionHeadersNotSupported'
- CONDITION_NOT_MET = 'ConditionNotMet'
- CONTAINER_ALREADY_EXISTS = 'ContainerAlreadyExists'
- CONTAINER_BEING_DELETED = 'ContainerBeingDeleted'
- CONTAINER_DISABLED = 'ContainerDisabled'
- CONTAINER_NOT_FOUND = 'ContainerNotFound'
- CONTAINER_QUOTA_DOWNGRADE_NOT_ALLOWED = 'ContainerQuotaDowngradeNotAllowed'
- CONTENT_LENGTH_LARGER_THAN_TIER_LIMIT = 'ContentLengthLargerThanTierLimit'
- CONTENT_LENGTH_MUST_BE_ZERO = 'ContentLengthMustBeZero'
- COPY_ACROSS_ACCOUNTS_NOT_SUPPORTED = 'CopyAcrossAccountsNotSupported'
- COPY_ID_MISMATCH = 'CopyIdMismatch'
- DELETE_PENDING = 'DeletePending'
- DESTINATION_PATH_IS_BEING_DELETED = 'DestinationPathIsBeingDeleted'
- DIRECTORY_NOT_EMPTY = 'DirectoryNotEmpty'
- EMPTY_METADATA_KEY = 'EmptyMetadataKey'
- FEATURE_VERSION_MISMATCH = 'FeatureVersionMismatch'
- FILE_LOCK_CONFLICT = 'FileLockConflict'
- FILE_SHARE_PROVISIONED_BANDWIDTH_DOWNGRADE_NOT_ALLOWED = 'FileShareProvisionedBandwidthDowngradeNotAllowed'
- FILE_SHARE_PROVISIONED_IOPS_DOWNGRADE_NOT_ALLOWED = 'FileShareProvisionedIopsDowngradeNotAllowed'
- FILE_SYSTEM_ALREADY_EXISTS = 'FilesystemAlreadyExists'
- FILE_SYSTEM_BEING_DELETED = 'FilesystemBeingDeleted'
- FILE_SYSTEM_NOT_FOUND = 'FilesystemNotFound'
- INCREMENTAL_COPY_BLOB_MISMATCH = 'IncrementalCopyBlobMismatch'
- INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED = 'IncrementalCopyOfEarlierVersionSnapshotNotAllowed'
- INCREMENTAL_COPY_OF_ERALIER_VERSION_SNAPSHOT_NOT_ALLOWED = 'IncrementalCopyOfEarlierVersionSnapshotNotAllowed'
Please use INCREMENTAL_COPY_OF_EARLIER_VERSION_SNAPSHOT_NOT_ALLOWED instead.
- Type:
Deprecated
- INCREMENTAL_COPY_SOURCE_MUST_BE_SNAPSHOT = 'IncrementalCopySourceMustBeSnapshot'
- INFINITE_LEASE_DURATION_REQUIRED = 'InfiniteLeaseDurationRequired'
- INSUFFICIENT_ACCOUNT_PERMISSIONS = 'InsufficientAccountPermissions'
- INTERNAL_ERROR = 'InternalError'
- INVALID_AUTHENTICATION_INFO = 'InvalidAuthenticationInfo'
- INVALID_BLOB_OR_BLOCK = 'InvalidBlobOrBlock'
- INVALID_BLOB_TIER = 'InvalidBlobTier'
- INVALID_BLOB_TYPE = 'InvalidBlobType'
- INVALID_BLOCK_ID = 'InvalidBlockId'
- INVALID_BLOCK_LIST = 'InvalidBlockList'
- INVALID_DESTINATION_PATH = 'InvalidDestinationPath'
- INVALID_FILE_OR_DIRECTORY_PATH_NAME = 'InvalidFileOrDirectoryPathName'
- INVALID_FLUSH_POSITION = 'InvalidFlushPosition'
- INVALID_HEADER_VALUE = 'InvalidHeaderValue'
- INVALID_HTTP_VERB = 'InvalidHttpVerb'
- INVALID_INPUT = 'InvalidInput'
- INVALID_MARKER = 'InvalidMarker'
- INVALID_MD5 = 'InvalidMd5'
- INVALID_METADATA = 'InvalidMetadata'
- INVALID_OPERATION = 'InvalidOperation'
- INVALID_PAGE_RANGE = 'InvalidPageRange'
- INVALID_PROPERTY_NAME = 'InvalidPropertyName'
- INVALID_QUERY_PARAMETER_VALUE = 'InvalidQueryParameterValue'
- INVALID_RANGE = 'InvalidRange'
- INVALID_RENAME_SOURCE_PATH = 'InvalidRenameSourcePath'
- INVALID_RESOURCE_NAME = 'InvalidResourceName'
- INVALID_SOURCE_BLOB_TYPE = 'InvalidSourceBlobType'
- INVALID_SOURCE_BLOB_URL = 'InvalidSourceBlobUrl'
- INVALID_SOURCE_OR_DESTINATION_RESOURCE_TYPE = 'InvalidSourceOrDestinationResourceType'
- INVALID_SOURCE_URI = 'InvalidSourceUri'
- INVALID_URI = 'InvalidUri'
- INVALID_VERSION_FOR_PAGE_BLOB_OPERATION = 'InvalidVersionForPageBlobOperation'
- INVALID_XML_DOCUMENT = 'InvalidXmlDocument'
- INVALID_XML_NODE_VALUE = 'InvalidXmlNodeValue'
- LEASE_ALREADY_BROKEN = 'LeaseAlreadyBroken'
- LEASE_ALREADY_PRESENT = 'LeaseAlreadyPresent'
- LEASE_ID_MISMATCH_WITH_BLOB_OPERATION = 'LeaseIdMismatchWithBlobOperation'
- LEASE_ID_MISMATCH_WITH_CONTAINER_OPERATION = 'LeaseIdMismatchWithContainerOperation'
- LEASE_ID_MISMATCH_WITH_LEASE_OPERATION = 'LeaseIdMismatchWithLeaseOperation'
- LEASE_ID_MISSING = 'LeaseIdMissing'
- LEASE_IS_ALREADY_BROKEN = 'LeaseIsAlreadyBroken'
- LEASE_IS_BREAKING_AND_CANNOT_BE_ACQUIRED = 'LeaseIsBreakingAndCannotBeAcquired'
- LEASE_IS_BREAKING_AND_CANNOT_BE_CHANGED = 'LeaseIsBreakingAndCannotBeChanged'
- LEASE_IS_BROKEN_AND_CANNOT_BE_RENEWED = 'LeaseIsBrokenAndCannotBeRenewed'
- LEASE_LOST = 'LeaseLost'
- LEASE_NAME_MISMATCH = 'LeaseNameMismatch'
- LEASE_NOT_PRESENT_WITH_BLOB_OPERATION = 'LeaseNotPresentWithBlobOperation'
- LEASE_NOT_PRESENT_WITH_CONTAINER_OPERATION = 'LeaseNotPresentWithContainerOperation'
- LEASE_NOT_PRESENT_WITH_LEASE_OPERATION = 'LeaseNotPresentWithLeaseOperation'
- MAX_BLOB_SIZE_CONDITION_NOT_MET = 'MaxBlobSizeConditionNotMet'
- MD5_MISMATCH = 'Md5Mismatch'
- MESSAGE_NOT_FOUND = 'MessageNotFound'
- MESSAGE_TOO_LARGE = 'MessageTooLarge'
- METADATA_TOO_LARGE = 'MetadataTooLarge'
- MISSING_CONTENT_LENGTH_HEADER = 'MissingContentLengthHeader'
- MISSING_REQUIRED_HEADER = 'MissingRequiredHeader'
- MISSING_REQUIRED_QUERY_PARAMETER = 'MissingRequiredQueryParameter'
- MISSING_REQUIRED_XML_NODE = 'MissingRequiredXmlNode'
- MULTIPLE_CONDITION_HEADERS_NOT_SUPPORTED = 'MultipleConditionHeadersNotSupported'
- NO_AUTHENTICATION_INFORMATION = 'NoAuthenticationInformation'
- NO_PENDING_COPY_OPERATION = 'NoPendingCopyOperation'
- OPERATION_NOT_ALLOWED_ON_INCREMENTAL_COPY_BLOB = 'OperationNotAllowedOnIncrementalCopyBlob'
- OPERATION_TIMED_OUT = 'OperationTimedOut'
- OUT_OF_RANGE_INPUT = 'OutOfRangeInput'
- OUT_OF_RANGE_QUERY_PARAMETER_VALUE = 'OutOfRangeQueryParameterValue'
- PARENT_NOT_FOUND = 'ParentNotFound'
- PATH_ALREADY_EXISTS = 'PathAlreadyExists'
- PATH_CONFLICT = 'PathConflict'
- PATH_NOT_FOUND = 'PathNotFound'
- PENDING_COPY_OPERATION = 'PendingCopyOperation'
- POP_RECEIPT_MISMATCH = 'PopReceiptMismatch'
- PREVIOUS_SNAPSHOT_CANNOT_BE_NEWER = 'PreviousSnapshotCannotBeNewer'
- PREVIOUS_SNAPSHOT_NOT_FOUND = 'PreviousSnapshotNotFound'
- PREVIOUS_SNAPSHOT_OPERATION_NOT_SUPPORTED = 'PreviousSnapshotOperationNotSupported'
- QUEUE_ALREADY_EXISTS = 'QueueAlreadyExists'
- QUEUE_BEING_DELETED = 'QueueBeingDeleted'
- QUEUE_DISABLED = 'QueueDisabled'
- QUEUE_NOT_EMPTY = 'QueueNotEmpty'
- QUEUE_NOT_FOUND = 'QueueNotFound'
- READ_ONLY_ATTRIBUTE = 'ReadOnlyAttribute'
- RENAME_DESTINATION_PARENT_PATH_NOT_FOUND = 'RenameDestinationParentPathNotFound'
- REQUEST_BODY_TOO_LARGE = 'RequestBodyTooLarge'
- REQUEST_URL_FAILED_TO_PARSE = 'RequestUrlFailedToParse'
- RESOURCE_ALREADY_EXISTS = 'ResourceAlreadyExists'
- RESOURCE_NOT_FOUND = 'ResourceNotFound'
- RESOURCE_TYPE_MISMATCH = 'ResourceTypeMismatch'
- SEQUENCE_NUMBER_CONDITION_NOT_MET = 'SequenceNumberConditionNotMet'
- SEQUENCE_NUMBER_INCREMENT_TOO_LARGE = 'SequenceNumberIncrementTooLarge'
- SERVER_BUSY = 'ServerBusy'
- SHARE_ALREADY_EXISTS = 'ShareAlreadyExists'
- SHARE_BEING_DELETED = 'ShareBeingDeleted'
- SHARE_DISABLED = 'ShareDisabled'
- SHARE_HAS_SNAPSHOTS = 'ShareHasSnapshots'
- SHARE_NOT_FOUND = 'ShareNotFound'
- SHARE_SNAPSHOT_COUNT_EXCEEDED = 'ShareSnapshotCountExceeded'
- SHARE_SNAPSHOT_IN_PROGRESS = 'ShareSnapshotInProgress'
- SHARE_SNAPSHOT_OPERATION_NOT_SUPPORTED = 'ShareSnapshotOperationNotSupported'
- SHARING_VIOLATION = 'SharingViolation'
- SNAPHOT_OPERATION_RATE_EXCEEDED = 'SnapshotOperationRateExceeded'
Please use SNAPSHOT_OPERATION_RATE_EXCEEDED instead.
- Type:
Deprecated
- SNAPSHOTS_PRESENT = 'SnapshotsPresent'
- SNAPSHOT_COUNT_EXCEEDED = 'SnapshotCountExceeded'
- SNAPSHOT_OPERATION_RATE_EXCEEDED = 'SnapshotOperationRateExceeded'
- SOURCE_CONDITION_NOT_MET = 'SourceConditionNotMet'
- SOURCE_PATH_IS_BEING_DELETED = 'SourcePathIsBeingDeleted'
- SOURCE_PATH_NOT_FOUND = 'SourcePathNotFound'
- SYSTEM_IN_USE = 'SystemInUse'
- TARGET_CONDITION_NOT_MET = 'TargetConditionNotMet'
- UNAUTHORIZED_BLOB_OVERWRITE = 'UnauthorizedBlobOverwrite'
- UNSUPPORTED_HEADER = 'UnsupportedHeader'
- UNSUPPORTED_HTTP_VERB = 'UnsupportedHttpVerb'
- UNSUPPORTED_QUERY_PARAMETER = 'UnsupportedQueryParameter'
- UNSUPPORTED_REST_VERSION = 'UnsupportedRestVersion'
- UNSUPPORTED_XML_NODE = 'UnsupportedXmlNode'
- class azure.storage.blob.StorageStreamDownloader(clients: AzureBlobStorage = None, config: StorageConfiguration = None, start_range: int | None = None, end_range: int | None = None, validate_content: bool = None, encryption_options: Dict[str, Any] = None, max_concurrency: int = 1, name: str = None, container: str = None, encoding: str | None = None, download_cls: Callable | None = None, **kwargs: Any)[source]
A streaming object to download from Azure Storage.
- chunks() Iterator[bytes][source]
Iterate over chunks in the download stream. Note, the iterator returned will iterate over the entire download content, regardless of any data that was previously read.
NOTE: If the stream has been partially read, some data may be re-downloaded by the iterator.
- Returns:
An iterator of the chunks in the download stream.
- Return type:
Iterator[bytes]
Example:
Download a blob using chunks().# This returns a StorageStreamDownloader. stream = source_blob_client.download_blob() block_list = [] # Read data in chunks to avoid loading all into memory at once for chunk in stream.chunks(): # process your data (anything can be done here really. `chunk` is a byte array). block_id = str(uuid.uuid4()) destination_blob_client.stage_block(block_id=block_id, data=chunk) block_list.append(BlobBlock(block_id=block_id))
- content_as_bytes(max_concurrency=1)[source]
DEPRECATED: Download the contents of this file.
This operation is blocking until all data is downloaded.
This method is deprecated, use func:readall instead.
- content_as_text(max_concurrency=1, encoding='UTF-8')[source]
DEPRECATED: Download the contents of this blob, and decode as text.
This operation is blocking until all data is downloaded.
This method is deprecated, use func:readall instead.
- download_to_stream(stream, max_concurrency=1)[source]
DEPRECATED: Download the contents of this blob to a stream.
This method is deprecated, use func:readinto instead.
- Parameters:
stream (IO[T]) – The stream to download to. This can be an open file-handle, or any writable stream. The stream must be seekable if the download uses more than one parallel connection.
max_concurrency (int) – The number of parallel connections with which to download.
- Returns:
The properties of the downloaded blob.
- Return type:
Any
- read(size: int = -1, *, chars: int | None = None) T[source]
Read the specified bytes or chars from the stream. If encoding was specified on download_blob, it is recommended to use the chars parameter to read a specific number of chars to avoid decoding errors. If size/chars is unspecified or negative all bytes will be read.
- Parameters:
size (int) – The number of bytes to download from the stream. Leave unspecified or set negative to download all bytes.
- Keyword Arguments:
chars (Optional[int]) – The number of chars to download from the stream. Leave unspecified or set negative to download all chars. Note, this can only be used when encoding is specified on download_blob.
- Returns:
The requested data as bytes or a string if encoding was specified. If the return value is empty, there is no more data to read.
- Return type:
T
- readall() T[source]
Read the entire contents of this blob. This operation is blocking until all data is downloaded.
- Returns:
The requested data as bytes or a string if encoding was specified.
- Return type:
T
- properties: BlobProperties
The properties of the blob being downloaded. If only a range of the data is being downloaded, this will be reflected in the properties.
- class azure.storage.blob.UserDelegationKey[source]
Represents a user delegation key, provided to the user by Azure Storage based on their Azure Active Directory access token.
The fields are saved as simple strings since the user does not have to interact with this object; to generate an identify SAS, the user can simply pass it to the right API.
- azure.storage.blob.download_blob_from_url(blob_url: str, output: str | IO[bytes], credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any) None[source]
Download the contents of a blob to a local file or stream.
- Parameters:
blob_url (str) – The full URI to the blob. This can also include a SAS token.
output (str or IO.) – Where the data should be downloaded to. This could be either a file path to write to, or an open IO handle to write to.
credential (AzureNamedKeyCredential or AzureSasCredential or TokenCredential or str or dict[str, str] or None) – The credentials with which to authenticate. This is optional if the blob URL already has a SAS token or the blob is public. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
overwrite (bool) – Whether the local file should be overwritten if it already exists. The default value is False - in which case a ValueError will be raised if the file already exists. If set to True, an attempt will be made to write to the existing file. If a stream handle is passed in, this value is ignored.
max_concurrency (int) – The number of parallel connections with which to download.
offset (int) – Start of byte range to use for downloading a section of the blob. Must be set if length is provided.
length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
- Returns:
None
- Return type:
None
- azure.storage.blob.generate_account_sas(account_name: str, account_key: str, resource_types: ResourceTypes | str, permission: AccountSasPermissions | str, expiry: datetime | str, start: datetime | str | None = None, ip: str | None = None, *, services: ~azure.storage.blob._shared.models.Services | str = <azure.storage.blob._shared.models.Services object>, sts_hook: ~typing.Callable[[str], None] | None = None, **kwargs: ~typing.Any) str[source]
Generates a shared access signature for the blob service.
Use the returned signature with the credential parameter of any BlobServiceClient, ContainerClient or BlobClient.
- Parameters:
account_name (str) – The storage account name used to generate the shared access signature.
account_key (str) – The account key, also called shared key or access key, to generate the shared access signature.
resource_types (str or ResourceTypes) – Specifies the resource types that are accessible with the account SAS.
permission (str or AccountSasPermissions) – The permissions associated with the shared access signature. The user is restricted to operations allowed by the permissions.
expiry (datetime or str) – The time at which the shared access signature becomes invalid. The provided datetime will always be interpreted as 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. The provided datetime will always be interpreted as 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 ip=168.1.5.65 or ip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses.
- Keyword Arguments:
services (Union[Services, str]) – Specifies the services that the Shared Access Signature (sas) token will be able to be utilized with. Will default to only this package (i.e. blobs) if not provided.
protocol (str) – Specifies the protocol permitted for a request made. The default value is https.
encryption_scope (str) – Specifies the encryption scope for a request made so that all write operations will be service encrypted.
sts_hook (Optional[Callable[[str], None]]) – For debugging purposes only. If provided, the hook is called with the string to sign that was used to generate the SAS.
- Returns:
A Shared Access Signature (sas) token.
- Return type:
Example:
Generating a shared access signature.# Create a SAS token to use to authenticate a new client from datetime import datetime, timedelta from azure.storage.blob import ResourceTypes, AccountSasPermissions, generate_account_sas sas_token = generate_account_sas( blob_service_client.account_name, account_key=blob_service_client.credential.account_key, resource_types=ResourceTypes(object=True), permission=AccountSasPermissions(read=True), expiry=datetime.utcnow() + timedelta(hours=1) )
- azure.storage.blob.generate_blob_sas(account_name: str, container_name: str, blob_name: str, snapshot: str | None = None, account_key: str | None = None, user_delegation_key: UserDelegationKey | None = None, permission: BlobSasPermissions | str | None = None, expiry: datetime | str | None = None, start: datetime | str | None = None, policy_id: str | None = None, ip: str | None = None, *, sts_hook: Callable[[str], None] | None = None, **kwargs: Any) str[source]
Generates a shared access signature for a blob.
Use the returned signature with the credential parameter of any BlobServiceClient, ContainerClient or BlobClient.
- Parameters:
account_name (str) – The storage account name used to generate the shared access signature.
container_name (str) – The name of the container.
blob_name (str) – The name of the blob.
snapshot (str) – An optional blob snapshot ID.
account_key (str) – The account key, also called shared key or access key, to generate the shared access signature. Either account_key or user_delegation_key must be specified.
user_delegation_key (UserDelegationKey) – Instead of an account shared key, the user could pass in a user delegation key. A user delegation key can be obtained from the service by authenticating with an AAD identity; this can be accomplished by calling
get_user_delegation_key(). When present, the SAS is signed with the user delegation key instead.permission (str or BlobSasPermissions) – The permissions associated with the shared access signature. The user is restricted to operations allowed by the permissions. Permissions must be ordered racwdxytmei. 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. The provided datetime will always be interpreted as UTC.
policy_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_access_policy().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 ip=168.1.5.65 or ip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses.
- Keyword Arguments:
version_id (str) –
An optional blob version ID. This parameter is only applicable for versioning-enabled Storage accounts. Note that the ‘versionid’ query parameter is not included in the output SAS. Therefore, please provide the ‘version_id’ parameter to any APIs when using the output SAS to operate on a specific version.
Added in version 12.4.0: This keyword argument was introduced in API version ‘2019-12-12’.
protocol (str) – Specifies the protocol permitted for a request made. The default value is https.
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.
encryption_scope (str) – Specifies the encryption scope for a request made so that all write operations will be service encrypted.
correlation_id (str) – The correlation id to correlate the storage audit logs with the audit logs used by the principal generating and distributing the SAS. This can only be used when generating a SAS with delegation key.
sts_hook (Optional[Callable[[str], None]]) – For debugging purposes only. If provided, the hook is called with the string to sign that was used to generate the SAS.
- Returns:
A Shared Access Signature (sas) token.
- Return type:
- azure.storage.blob.generate_container_sas(account_name: str, container_name: str, account_key: str | None = None, user_delegation_key: UserDelegationKey | None = None, permission: ContainerSasPermissions | str | None = None, expiry: datetime | str | None = None, start: datetime | str | None = None, policy_id: str | None = None, ip: str | None = None, *, sts_hook: Callable[[str], None] | None = None, **kwargs: Any) str[source]
Generates a shared access signature for a container.
Use the returned signature with the credential parameter of any BlobServiceClient, ContainerClient or BlobClient.
- Parameters:
account_name (str) – The storage account name used to generate the shared access signature.
container_name (str) – The name of the container.
account_key (str) – The account key, also called shared key or access key, to generate the shared access signature. Either account_key or user_delegation_key must be specified.
user_delegation_key (UserDelegationKey) – Instead of an account shared key, the user could pass in a user delegation key. A user delegation key can be obtained from the service by authenticating with an AAD identity; this can be accomplished by calling
get_user_delegation_key(). When present, the SAS is signed with the user delegation key instead.permission (str or ContainerSasPermissions) – The permissions associated with the shared access signature. The user is restricted to operations allowed by the permissions. Permissions must be ordered racwdxyltfmei. 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. The provided datetime will always be interpreted as UTC.
policy_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_access_policy().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 ip=168.1.5.65 or ip=168.1.5.60-168.1.5.70 on the SAS restricts the request to those IP addresses.
- Keyword Arguments:
protocol (str) – Specifies the protocol permitted for a request made. The default value is https.
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.
encryption_scope (str) – Specifies the encryption scope for a request made so that all write operations will be service encrypted.
correlation_id (str) – The correlation id to correlate the storage audit logs with the audit logs used by the principal generating and distributing the SAS. This can only be used when generating a SAS with delegation key.
sts_hook (Optional[Callable[[str], None]]) – For debugging purposes only. If provided, the hook is called with the string to sign that was used to generate the SAS.
- Returns:
A Shared Access Signature (sas) token.
- Return type:
Example:
Generating a sas token.# Use access policy to generate a sas token from azure.storage.blob import generate_container_sas sas_token = generate_container_sas( container_client.account_name, container_client.container_name, account_key=container_client.credential.account_key, policy_id='my-access-policy-id' )
- azure.storage.blob.upload_blob_to_url(blob_url: str, data: Iterable | IO, credential: str | Dict[str, str] | AzureNamedKeyCredential | AzureSasCredential | TokenCredential | None = None, **kwargs: Any) Dict[str, Any][source]
Upload data to a given URL
The data will be uploaded as a block blob.
- Parameters:
blob_url (str) – The full URI to the blob. This can also include a SAS token.
data (bytes or str or Iterable) – The data to upload. This can be bytes, text, an iterable or a file-like object.
credential (AzureNamedKeyCredential or AzureSasCredential or TokenCredential or str or dict[str, str] or None) – The credentials with which to authenticate. This is optional if the blob URL already has a SAS token. The value can be a SAS token string, an instance of a AzureSasCredential or AzureNamedKeyCredential from azure.core.credentials, an account shared access key, or an instance of a TokenCredentials class from azure.identity. If the resource URI already contains a SAS token, this will be ignored in favor of an explicit credential - except in the case of AzureSasCredential, where the conflicting SAS tokens will raise a ValueError. If using an instance of AzureNamedKeyCredential, “name” should be the storage account name, and “key” should be the storage account key.
- Keyword Arguments:
overwrite (bool) – Whether the blob to be uploaded should overwrite the current data. If True, upload_blob_to_url will overwrite any existing data. If set to False, the operation will fail with a ResourceExistsError.
max_concurrency (int) – The number of parallel connections with which to download.
length (int) – Number of bytes to read from the stream. This is optional, but should be supplied for optimal performance.
metadata (dict(str,str)) – Name-value pairs associated with the blob as metadata.
validate_content (bool) – If true, calculates an MD5 hash for each chunk of the blob. The storage service checks the hash of the content that has arrived with the hash that was sent. This is primarily valuable for detecting bitflips on the wire if using http instead of https as https (the default) will already validate. Note that this MD5 hash is not stored with the blob. Also note that if enabled, the memory-efficient upload algorithm will not be used, because computing the MD5 hash requires buffering entire blocks, and doing so defeats the purpose of the memory-efficient algorithm.
encoding (str) – Encoding to use if text is supplied as input. Defaults to UTF-8.
- Returns:
Blob-updated property dict (Etag and last modified)
- Return type:
Subpackages
- azure.storage.blob.aio package
BlobClientBlobClient.from_blob_url()BlobClient.from_connection_string()BlobClient.abort_copy()BlobClient.acquire_lease()BlobClient.append_block()BlobClient.append_block_from_url()BlobClient.clear_page()BlobClient.close()BlobClient.commit_block_list()BlobClient.create_append_blob()BlobClient.create_page_blob()BlobClient.create_snapshot()BlobClient.delete_blob()BlobClient.delete_immutability_policy()BlobClient.download_blob()BlobClient.exists()BlobClient.get_account_information()BlobClient.get_blob_properties()BlobClient.get_blob_tags()BlobClient.get_block_list()BlobClient.get_page_range_diff_for_managed_disk()BlobClient.get_page_ranges()BlobClient.list_page_ranges()BlobClient.query_blob()BlobClient.resize_blob()BlobClient.seal_append_blob()BlobClient.set_blob_metadata()BlobClient.set_blob_tags()BlobClient.set_http_headers()BlobClient.set_immutability_policy()BlobClient.set_legal_hold()BlobClient.set_premium_page_blob_tier()BlobClient.set_sequence_number()BlobClient.set_standard_blob_tier()BlobClient.stage_block()BlobClient.stage_block_from_url()BlobClient.start_copy_from_url()BlobClient.undelete_blob()BlobClient.upload_blob()BlobClient.upload_blob_from_url()BlobClient.upload_page()BlobClient.upload_pages_from_url()BlobClient.api_versionBlobClient.location_modeBlobClient.primary_endpointBlobClient.primary_hostnameBlobClient.secondary_endpointBlobClient.secondary_hostnameBlobClient.url
BlobLeaseClientBlobPrefixBlobPrefix.by_page()BlobPrefix.get()BlobPrefix.has_key()BlobPrefix.items()BlobPrefix.keys()BlobPrefix.update()BlobPrefix.values()BlobPrefix.commandBlobPrefix.containerBlobPrefix.current_pageBlobPrefix.delimiterBlobPrefix.location_modeBlobPrefix.markerBlobPrefix.nameBlobPrefix.next_markerBlobPrefix.prefixBlobPrefix.results_per_pageBlobPrefix.service_endpoint
BlobServiceClientBlobServiceClient.from_connection_string()BlobServiceClient.close()BlobServiceClient.create_container()BlobServiceClient.delete_container()BlobServiceClient.find_blobs_by_tags()BlobServiceClient.get_account_information()BlobServiceClient.get_blob_client()BlobServiceClient.get_container_client()BlobServiceClient.get_service_properties()BlobServiceClient.get_service_stats()BlobServiceClient.get_user_delegation_key()BlobServiceClient.list_containers()BlobServiceClient.set_service_properties()BlobServiceClient.undelete_container()BlobServiceClient.api_versionBlobServiceClient.location_modeBlobServiceClient.primary_endpointBlobServiceClient.primary_hostnameBlobServiceClient.secondary_endpointBlobServiceClient.secondary_hostnameBlobServiceClient.url
ContainerClientContainerClient.from_connection_string()ContainerClient.from_container_url()ContainerClient.acquire_lease()ContainerClient.close()ContainerClient.create_container()ContainerClient.delete_blob()ContainerClient.delete_blobs()ContainerClient.delete_container()ContainerClient.download_blob()ContainerClient.exists()ContainerClient.find_blobs_by_tags()ContainerClient.get_account_information()ContainerClient.get_blob_client()ContainerClient.get_container_access_policy()ContainerClient.get_container_properties()ContainerClient.list_blob_names()ContainerClient.list_blobs()ContainerClient.set_container_access_policy()ContainerClient.set_container_metadata()ContainerClient.set_premium_page_blob_tier_blobs()ContainerClient.set_standard_blob_tier_blobs()ContainerClient.upload_blob()ContainerClient.walk_blobs()ContainerClient.api_versionContainerClient.location_modeContainerClient.primary_endpointContainerClient.primary_hostnameContainerClient.secondary_endpointContainerClient.secondary_hostnameContainerClient.url
ExponentialRetryExponentialRetry.configure_retries()ExponentialRetry.get_backoff_time()ExponentialRetry.increment()ExponentialRetry.send()ExponentialRetry.sleep()ExponentialRetry.connect_retriesExponentialRetry.increment_baseExponentialRetry.initial_backoffExponentialRetry.nextExponentialRetry.random_jitter_rangeExponentialRetry.retry_readExponentialRetry.retry_statusExponentialRetry.retry_to_secondaryExponentialRetry.total_retries
LinearRetryLinearRetry.configure_retries()LinearRetry.get_backoff_time()LinearRetry.increment()LinearRetry.send()LinearRetry.sleep()LinearRetry.connect_retriesLinearRetry.initial_backoffLinearRetry.nextLinearRetry.random_jitter_rangeLinearRetry.retry_readLinearRetry.retry_statusLinearRetry.retry_to_secondaryLinearRetry.total_retries
StorageStreamDownloaderStorageStreamDownloader.chunks()StorageStreamDownloader.content_as_bytes()StorageStreamDownloader.content_as_text()StorageStreamDownloader.download_to_stream()StorageStreamDownloader.read()StorageStreamDownloader.readall()StorageStreamDownloader.readinto()StorageStreamDownloader.containerStorageStreamDownloader.nameStorageStreamDownloader.propertiesStorageStreamDownloader.size
download_blob_from_url()upload_blob_to_url()