msticpy.data.storage.azure_blob_storage module

Uses the Azure Python SDK to interact with Azure Blob Storage.

class msticpy.data.storage.azure_blob_storage.AzureBlobStorage(abs_name: str | None = None, connect: bool = False, abs_connection_string: str | None = None)

Bases: object

Class for interacting with Azure Blob Storage.

Initialize connector for Azure Python SDK.

blobs(container_name: str) DataFrame | None

Get a list of blobs in a container.

Parameters:

container_name (str) – The name of the container to get blobs from.

Returns:

Details of the blobs.

Return type:

pd.DataFrame

connect(auth_methods: List | None = None, silent: bool = False)

Authenticate with the SDK.

containers() DataFrame

Return containers in the Azure Blob Storage Account.

create_container(container_name: str, **kwargs) DataFrame

Create a new container within the Azure Blob Storage account.

Parameters:
  • container_name (str) – The name for the new container.

  • kwargs (Additional container parameters can be passed as)

Returns:

Details of the created container.

Return type:

pd.DataFrame

delete_blob(container_name: str, blob_name: str) bool

Delete a blob from the Azure Blob Storage account.

Parameters:
  • container_name (str) – The container name that has the blob.

  • blob_name (str) – The name of the blob to delete.

  • snapshots. (Note deleting a blob also deletes associated)

Returns:

True if blob successfully deleted

Return type:

bool

get_blob(container_name: str, blob_name: str) bytes

Get a blob from the Azure Blob Storage account.

Parameters:
  • container_name (str) – The name of the container that holds the blob.

  • blob_name (str) – The name of the blob to download.

Returns:

The content of the blob in bytes.

Return type:

bytes

get_sas_token(container_name: str, blob_name: str, end: datetime | None = None, permission: str = 'r') str

Generate a shared access string (SAS) token for a blob.

Parameters:
  • container_name (str) – The name of the Azure Blob Storage container that holds the blob.

  • blob_name (str) – The name of the blob to generate the SAS token for.

  • end (datetime.datetime, optional) – The datetime the SAS token should expire, by default this is 7 days from now.

  • permission (str, optional) – The permissions to give the SAS token, by default ‘r’ for read.

Returns:

A URI of the blob with SAS token.

Return type:

str

upload_to_blob(blob: Any, container_name: str, blob_name: str, overwrite: bool = True)

Upload a blob of data.

Parameters:
  • blob (Any) – The data to upload.

  • container_name (str) – The name of the container to upload the blob to.

  • blob_name (str) – The name to give the blob.

  • overwrite (bool, optional) – Whether or not you want to overwrite the blob if it exists, by default True.