tx_azure_blobs documentation

Indices and tables

Classes

This is the asynchronous Azure blob helper.

class blobs_async.AzBlobManagerAsync[source]

Bases: object

A utility class to help working with Azure Blob Storage.
This class implements asynchronous methods based on the Microsoft Python SDK azure.storage.blob.aio
See:
https://docs.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.aio?view=azure-python
Available:
  • Basic methods to work with containers and blobs
append_block(data, container_name, blob_name)[source]

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

Parameters:
  • data – Content of the block.
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
Returns:

The return value. True for success, False otherwise.

Return type:

bool

classmethod create(connection_string=None, account_url=None, credential=None)[source]

Instantiate an asynchronous AzBlobManagerAsync object.

Parameters:
  • connection_string (str) – A connection string to an Azure Storage account.
  • 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 (str) – The credentials with which to authenticate. This is optional if the account URL already has a SAS token, or the connection string already has shared access key values. The value can be a SAS token string, an account shared access key, or an instance of a TokenCredentials class from azure.identity. Credentials provided here will take precedence over those in the connection string.
Returns:

AzBlobManagerAsync object

Examples

Creating the AzBlobManagerAsync with account url and a shared access key: azStorageManager = AzBlobManagerAsync.create(account_url=self.url, credential=self.shared_access_key)

Creating the AzBlobManagerAsync with a connection string that has the shared access key: azStorageManager = AzBlobManagerAsync.create(connection_string=’DefaultEndpointsProtocol=http;…’)

create_append_blob(container_name, blob_name, replace_blob=False)[source]

Creates an append blob in an existing container.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
  • replace_blob (bool) – If True, deletes existing blob with same name
Returns:

The return value. True for success, False otherwise.

Return type:

bool

create_container(container_name)[source]

Creates a new container.

Parameters:
  • container_name (str) – The name of the container.
  • https (See) – //docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers–blobs–and-metadata for naming convention
Returns:

The return value. True for success, False otherwise.

Return type:

bool

create_page_blob(container_name, blob_name, size=1024, content_settings=None, metadata=None, premium_page_blob_tier=None)[source]

Creates a page blob in an existing container.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
  • 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
Returns:

The return value. True for success, False otherwise.

Return type:

bool

delete_blob(container_name, blob_name)[source]

Deletes a blob.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
Returns:

The return value. True for success, False otherwise.

Return type:

bool

delete_container(container_name)[source]

Deletes a container.

Parameters:container_name (str) – The name of the container.
Returns:The return value. True for success, False otherwise.
Return type:bool
download_data(container_name, blob_name)[source]

Downloads a blob.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
Returns:

The data stream

Return type:

stream

list_blobs(container_name)[source]

Lists the blobs in the specified container.

Parameters:container_name (str) – The name of the container.
Returns:A list of strings representing the blob names.
Return type:list
list_containers_name(name_starts_with=None)[source]

Lists containers’ name.

Parameters:name_starts_with (str) – Filters the results to return only containers whose names begin with the specified prefix.
Returns:A list of strings representing the container names.
Return type:list
upload_data(data, container_name, blob_name, blob_type='BlockBlob')[source]

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

Parameters:
  • data – The blob data to upload.
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
  • blob_typr (str) – The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob.
Returns:

The return value. True for success, False otherwise.

Return type:

bool

This is the synchronous Azure blob helper.

class blobs_sync.AzBlobManagerSync(connection_string=None, account_url=None, credential=None)[source]

Bases: object

A utility class to help working with Azure Storage.
This class implements synchronous methods based on the Microsoft Python SDK azure.storage.blob
See:
https://docs.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob?view=azure-python
Avalaible:
  • Basic methods to work with containers and blobs
append_block(data, container_name, blob_name)[source]

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

Parameters:
  • data – Content of the block.
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
Returns:

The return value. True for success, False otherwise.

Return type:

bool

create_append_blob(container_name, blob_name, replace_blob=False)[source]

Creates an append blob in an existing container.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
  • replace_blob (bool) – If True, deletes existing blob with same name
Returns:

The return value. True for success, False otherwise.

Return type:

bool

create_container(container_name)[source]

Creates a new container.

Parameters:
  • container_name (str) – The name of the container.
  • https (See) – //docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers–blobs–and-metadata for naming convention
Returns:

The return value. True for success, False otherwise.

Return type:

bool

create_page_blob(container_name, blob_name, size=1024, content_settings=None, metadata=None, premium_page_blob_tier=None)[source]

Creates a page blob in an existing container.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
  • 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
Returns:

The return value. True for success, False otherwise.

Return type:

bool

delete_blob(container_name, blob_name)[source]

Deletes a blob.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
Returns:

The return value. True for success, False otherwise.

Return type:

bool

delete_container(container_name)[source]

Deletes a container.

Parameters:container_name (str) – The name of the container.
Returns:The return value. True for success, False otherwise.
Return type:bool
download_data(container_name, blob_name)[source]

Downloads a blob.

Parameters:
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
Returns:

The data stream

Return type:

stream

list_blobs(container_name)[source]

Lists the blobs in the specified container.

Parameters:container_name (str) – The name of the container.
Returns:A list of strings representing the blob names.
Return type:list
list_containers_name(name_starts_with=None)[source]

Lists containers’ name.

Parameters:name_starts_with (str) – Filters the results to return only containers whose names begin with the specified prefix.
Returns:A list of strings representing the container names.
Return type:list
upload_data(data, container_name, blob_name, blob_type='BlockBlob')[source]

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

Parameters:
  • data – The blob data to upload.
  • container_name (str) – The name of the container.
  • blob_name (str) – The name of the blob.
  • blob_typr (str) – The type of the blob. This can be either BlockBlob, PageBlob or AppendBlob.
Returns:

The return value. True for success, False otherwise.

Return type:

bool

Contents: