AzureBlobClient
A client for interacting with single Azure Blob Storage Blob.
Inherits from:
BaseContainerClient
: to provide a generic interface for object storage clientsAzureClient
: to provide an interface for Azure Python SDK
Parameters:
blob_sas_url
(str): SAS URL to an Azure Blob Storage Blob. This url will define the specific blob that the client has access. Respecting the permission set up in the SAS Token.
__init__
Initialize an instance of AzureBlobClient
.
Parameters
blob_sas_url
(str): SAS URL to an Azure Blob Storage Blob.
upload_file
Uploads a file to the blob
Parameters
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
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 the blob, resuming an interrupted upload if there is an uncommitted block list.
Parameters
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 the Blob and return its content as bytes.
Parameters
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 the Blob and save it to the specified file path.
Parameters
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 the Blob.
Parameters
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 Blob with all its snapshots.
Parameters
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.
get_file_url
Retrieves Blob's URL.
Parameters
None
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 Blob's properties.
Parameters
None
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.
Parameters
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.
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.
Parameters
None
Returns
Tuple[List[BlobBlock], List[BlobBlock]]
: the return will contain two lists ofBlobBlock
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 blob in the context exists.
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.