Deleting Contents from Azure Blob

Deleting files and containers made easy.

Package Content

class azblobexplorer.AzureBlobDelete(account_name: str, account_key: str, container_name: str)[source]

Bases: azblobexplorer.base.BlobBase

Delete file and folder from Azure blob storage.

delete_container(timeout: int = 10) → bool[source]

Delete the current container.

Parameters

timeout (int) –

Request timeout in seconds

New in version 2.0.

Return type

bool

Returns

Returns True is the current container is deleted.

>>> from azblobexplorer import AzureBlobDelete
>>> az = AzureBlobDelete('account name', 'account key', 'container name')
>>> az.delete_container()
True
delete_file(file_name: str, timeout: int = 10) → bool[source]

Delete a file from Azure Storage Blob.

Parameters
  • file_name (str) – Give a file name to delete

  • timeout (int) –

    Request timeout in seconds

    New in version 2.0.

Return type

bool

Returns

True if a file is deleted.

>>> from azblobexplorer import AzureBlobDelete
>>> az = AzureBlobDelete('account name', 'account key', 'container name')
>>> az.delete_file('file_name.txt')
True
delete_files(file_names: list, timeout: int = 10) → bool[source]

Delete a list of file from Azure Storage Blob.

Parameters
  • file_names (str) – Give a list of file names to delete

  • timeout (int) –

    Request timeout in seconds

    New in version 2.0.

Return type

bool

Returns

True if files are deleted.

>>> from azblobexplorer import AzureBlobDelete
>>> az = AzureBlobDelete('account name', 'account key', 'container name')
>>> blob_list = [
...     'folder_1/file1.txt',
...     'file3.txt'
... ]
>>> az.delete_files(blob_list)
True
delete_folder(blob_folder_name: str, timeout: int = 10) → bool[source]

Delete a folder from Azure Storage Blob.

Parameters
  • blob_folder_name (str) – Give a folder name to delete

  • timeout (int) –

    Request timeout in seconds

    New in version 2.0.

Return type

bool

Returns

True if a folder is deleted.

Raises

NoBlobsFound – If the blob folder is empty or is not found.

>>> from azblobexplorer import AzureBlobDelete
>>> az = AzureBlobDelete('account name', 'account key', 'container name')
>>> az.delete_folder('temp/')
True
generate_url(blob_name: str, read: bool = True, add: bool = False, create: bool = False, write: bool = False, delete: bool = False, sas: bool = False, access_time: int = 1) → str

Generate’s blob URL. It can also generate Shared Access Signature (SAS) if sas=True.

Parameters
  • write (bool) –

    Write access

    New in version 2.0.

  • create (bool) –

    Create access

    New in version 2.0.

  • add (bool) –

    Add access

    New in version 2.0.

  • read (bool) –

    Read access

    New in version 2.0.

  • delete (bool) –

    Delete access

    New in version 2.0.

  • access_time (int) – Time till the URL is valid

  • blob_name (str) – Name of the blob, this could be a path

  • sas (bool) – Set True to generate SAS key

Returns

Blob URL

Example without ``sas``

>>> import os
>>> from azblobexplorer import AzureBlobDownload
>>> az = AzureBlobDownload('account name', 'account key', 'container name')
>>> az.generate_url("filename.txt")
https://containername.blob.core.windows.net/blobname/filename.txt

Example with ``upload_to`` and ``sas``

>>> import os
>>> from azblobexplorer import AzureBlobDownload
>>> az = AzureBlobDownload('account name', 'account key', 'container name')
>>> az.generate_url("filename.txt", sas=True)
https://containername.blob.core.windows.net/blobname/filename.txt?se=2019-11-05T16%3A33%3A46Z&sp=w&sv=2019-02-02&sr=b&sig=t%2BpUG2C2FQKp/Hb8SdCsmaZCZxbYXHUedwsquItGx%2BM%3D
generate_url_mime(blob_name: str, mime_type: str, sas: bool = False, read: bool = True, add: bool = False, create: bool = False, write: bool = False, delete: bool = False, access_time: int = 1) → str

Generate’s blob URL with MIME type. It can also generate Shared Access Signature (SAS) if sas=True.

Parameters
  • write (bool) –

    Write access

    New in version 2.0.

  • create (bool) –

    Create access

    New in version 2.0.

  • add (bool) –

    Add access

    New in version 2.0.

  • read (bool) –

    Read access

    New in version 2.0.

  • delete (bool) –

    Delete access

    New in version 2.0.

  • access_time (int) – Time till the URL is valid

  • blob_name (str) – Name of the blob

  • access_time – Time till the URL is valid

  • mime_type (str) – MIME type of the application

  • sas (bool) – Set True to generate SAS key

Returns

Blob URL

>>> import os
>>> from azblobexplorer import AzureBlobDownload
>>> az = AzureBlobDownload('account name', 'account key', 'container name')
>>> az.generate_url_mime("filename.zip", sas=True, mime_type="application/zip")
https://containername.blob.core.windows.net/blobname/filename.zip?se=2019-11-05T16%3A33%3A46Z&sp=w&sv=2019-02-02&sr=b&sig=t%2BpUG2C2FQKp/Hb8SdCsmaZCZxbYXHUedwsquItGx%2BM%3D