Skip to content

AzureContainerClient

A client for interacting with single Azure Blob Storage Container.

Inherits from:

  • BaseContainerClient: to provide a generic interface for object storage clients
  • AzureClient: to provide an interface for Azure Python SDK

Parameters:

  • container_sas_url (str): SAS URL to an Azure Blob Storage Container. This url will define the specific container that the client has access. Respecting the permission set up in the SAS Token.

__init__

Initialize an instance of AzureContainerClient.

Parameters

  • container_sas_url (str): SAS URL to an Azure Blob Storage Container.

delete

Deletes the container specified by the SAS URL.

Parameters

  • None

Returns

  • Dict[str, Any]: A dictionary containing deleted container information.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

upload_file

Uploads a file to a blob in the specified container.

Parameters

  • key (str): The name of the blob.
  • file_path (str): The path to the file to upload.
  • chunk_size (Optional[int], optional): The size of each chunk to upload. Defaults to 4 * 1024 * 1024.
  • progress_callback (Optional[Callable[[str, int, int], Awaitable[Any]]], optional): A callback function to track the progress of the upload. Defaults to None.

Returns

  • Dict[str, Any]: A dictionary containing the response information.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

upload_file_from_bytes

Uploads a file to a blob in the specified container from byte stream.

Parameters

  • key (str): The name of the blob.
  • buffer (BytesIO): the byte stream of the file.
  • chunk_size (Optional[int], optional): The size of each chunk to upload. Defaults to 4 * 1024 * 1024.
  • progress_callback (Optional[Callable[[str, int, int], Awaitable[Any]]], optional): A callback function to track the progress of the upload. Defaults to None.

Returns

  • Dict[str, Any]: A dictionary containing the response information.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

resume_upload

Uploads a file to an Azure Blob Storage container, resuming an interrupted upload if there is an uncommitted block list.

Parameters

  • key (str): The name of the blob.
  • file_path (str): The path to the file to upload.
  • chunk_size (int, optional): The size of each chunk to upload. Defaults to 4 * 1024 * 1024.
  • progress_callback (Optional[Callable[[str, int, int], Awaitable[Any]]], optional): A callback function to track the progress of the upload. Defaults to None.

Returns

  • None

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

download_file_to_bytes

Download a file from the specified container and return its content as bytes.

Parameters

  • key (str): The name of the blob.
  • chunk_size (Optional[int], optional): The size of each chunk to download. Defaults to 4 * 1024 * 1024.
  • progress_callback (Optional[Callable[[str, int, int], Awaitable[Any]]], optional): A callback function to track the progress of the download. Defaults to None.

Returns

  • bytes: The content of the downloaded file as bytes.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

download_file

Download a file from the specified container and save it to the specified file path.

Parameters

  • key (str): The name of the blob.
  • file_path (str): The path where the file will be saved.
  • chunk_size (Optional[int], optional): The size of each chunk to download. Defaults to 4 * 1024 * 1024.
  • progress_callback (Optional[Callable[[str, int, int], Awaitable[Any]]], optional): A callback function to track the progress of the download. Defaults to None.

Returns

  • None

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

copy_file_from_url

Copies a file from a URL to a blob in the specified container.

Parameters

  • key (str): The name of the destination blob.
  • source_url (str): The URL of the source file to copy.

Returns

  • str: The URL of the destination blob.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

delete_file

Deletes a file with all its snapshots from the specified container.

Parameters

  • key (str): The name of the blob to delete.

Returns

  • None

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

get_file_url

Returns the URL that can be used to access the specified file in specified container.

Parameters

  • key (str): The name of the blob.

Returns

  • str: The URL of the file.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

get_file_properties

Retrieves the properties of a blob in the specified container.

Parameters

  • key (str): The name of the blob.

Returns

  • BlobProperties: The properties of the blob.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

commit_file

Commits the uncommitted blocks of the blob. This method commits the uncommitted blocks of the blob using the specified blob SAS URL plus key .

Parameters

  • key (str): The name of the blob to commit.

Returns

  • None

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

get_file_chunks

list the information of committed and uncommitted blocks of the blob. This method lists the committed and uncommitted blocks of the blob using the specified blob SAS URL plus key .

Parameters

  • key (str): The name of the blob to retrieve the chunks.

Returns

  • Tuple[List[BlobBlock], List[BlobBlock]]: the return will contain two lists of BlobBlock objects, one for committed blocks and one for uncommitted blocks.

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

is_exists

Checks if container in the context exists.

Parameters

  • None

Returns

  • bool: True when the container exists and False in case it doesn't

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

is_file_exists

Checks if blob exists in the context container.

Parameters

  • None

Returns

  • bool: True when the blob exists and False in case it doesn't

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

restore_file

Restore a file from delete state to active state. This method will fetch the latest version. And restore it to base blob.

Parameters

  • key(str): the key of the blob to restore

Returns

  • None

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.

batch_restore_files

Restore a list of files from delete state to active state. similar with restore_file This method will fetch the latest version. And restore it to base blob.

Parameters

  • keys(List[str]): the key list of the blob to restore

Returns

  • None

Tip

You can check here an example

Raises:

  • ClientAuthenticationError: Raised when authentication with Azure fails.
  • ResourceNotFoundError: Raised when the requested resource is not found.
  • HttpResponseError: Raised when an error occurs in the HTTP response.
  • Exception: Raised for any unexpected errors.