AzureBlobStorage

class AzureBlobStorage(BaseObjectStorage):

A class to connect to Azure Blob Storage. It will connect to one container in the storage account.

Parameters:

  • storage_account_name (str): The name of the storage account.
  • container_name (str): The name of the container.
  • access_key (Optional[str], optional): The access key of the storage account. Defaults to None.
  • References:
  • https: //azure.microsoft.com/en-us/products/storage/blobs

init

def __init__(
    self,
    storage_account_name: str,
    container_name: str,
    create_if_not_exists: bool = True,
    access_key: Optional[str] = None
):

_prepare_and_check

def _prepare_and_check(self):

Check privileges and existence of the container.

canonicalize_path

def canonicalize_path(file_path: PurePath):

Canonicalize file path for Azure Blob Storage.

Parameters:

  • file_path (PurePath): The path to be canonicalized.

Returns:

Tuple[str, str]: The canonicalized file key and file name.

_put_file

def _put_file(self, file_key: str, file: File):

Put a file to the Azure Blob Storage container.

Parameters:

  • file_key (str): The path to the object in the container.
  • file (File): The file to be uploaded.

_get_file

def _get_file(self, file_key: str, filename: str):

Get a file from the Azure Blob Storage container.

Parameters:

  • file_key (str): The path to the object in the container.
  • filename (str): The name of the file.

Returns:

File: The object from the container.

_upload_file

def _upload_file(self, local_file_path: Path, remote_file_key: str):

Upload a local file to the Azure Blob Storage container.

Parameters:

  • local_file_path (Path): The path to the local file to be uploaded.
  • remote_file_key (str): The path to the object in the container.

_download_file

def _download_file(self, local_file_path: Path, remote_file_key: str):

Download a file from the Azure Blob Storage container to the local system.

Parameters:

  • local_file_path (Path): The path to the local file to be saved.
  • remote_file_key (str): The key of the object in the container.

_object_exists

def _object_exists(self, file_key: str):

Check if the object exists in the Azure Blob Storage container.

Parameters:

  • file_key: The key of the object in the container.

Returns:

bool: Whether the object exists in the container.