pyrit.models.AzureBlobStorageIO#
- class AzureBlobStorageIO(*, container_url: str = None, sas_token: str | None = None, blob_content_type: SupportedContentType = SupportedContentType.PLAIN_TEXT)[source]#
Bases:
StorageIO
Implementation of StorageIO for Azure Blob Storage.
- __init__(*, container_url: str = None, sas_token: str | None = None, blob_content_type: SupportedContentType = SupportedContentType.PLAIN_TEXT) None [source]#
Methods
__init__
(*[, container_url, sas_token, ...])create_directory_if_not_exists
(directory_path)Asynchronously creates a directory or equivalent in the storage system if it doesn't exist.
is_file
(path)Check if the path refers to a file (blob) in Azure Blob Storage.
parse_blob_url
(file_path)Parses the blob URL to extract the container name and blob name.
path_exists
(path)Check if a given path exists in the Azure Blob Storage container.
read_file
(path)Asynchronously reads the content of a file (blob) from Azure Blob Storage.
write_file
(path, data)Writes data to Azure Blob Storage at the specified path.
- async create_directory_if_not_exists(directory_path: Path | str) None [source]#
Asynchronously creates a directory or equivalent in the storage system if it doesn’t exist.
- async is_file(path: Path | str) bool [source]#
Check if the path refers to a file (blob) in Azure Blob Storage.
- parse_blob_url(file_path: str)[source]#
Parses the blob URL to extract the container name and blob name.
- async path_exists(path: Path | str) bool [source]#
Check if a given path exists in the Azure Blob Storage container.
- async read_file(path: Path | str) bytes [source]#
Asynchronously reads the content of a file (blob) from Azure Blob Storage.
If the provided path is a full URL (e.g., “https://<Azure STorage Account>.blob.core.windows.net/<container name>/dir1/dir2/sample.png”), it extracts the relative blob path (e.g., “dir1/dir2/sample.png”) to correctly access the blob. If a relative path is provided, it will use it as-is.
- Parameters:
path (str) – The path to the file (blob) in Azure Blob Storage. This can be either a full URL or a relative path.
- Returns:
The content of the file (blob) as bytes.
- Return type:
- Raises:
Exception – If there is an error in reading the blob file, an exception will be logged and re-raised.
Example
file_content = await read_file(”https://account.blob.core.windows.net/container/dir2/1726627689003831.png”) # Or using a relative path: file_content = await read_file(“dir1/dir2/1726627689003831.png”)