azure
detdevlib.etl.azure
AzureBlobManager
A client for managing blobs in Azure Blob Storage.
This client can be authenticated via a connection string, default Azure credentials, or a SAS URL.
Attributes:
| Name | Type | Description |
|---|---|---|
blob_service_client |
The Azure BlobServiceClient. |
__init__
__init__(
conn_str: str | None = None,
acc_url: str | None = None,
sas_url: str | None = None,
)
Initializes the Azure Blob Manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn_str
|
str | None
|
The connection string for the Azure Storage account. |
None
|
acc_url
|
str | None
|
The URL to the storage account (used with DefaultAzureCredential). |
None
|
sas_url
|
str | None
|
A SAS URL for authentication. |
None
|
create_container_if_not_exists
create_container_if_not_exists(container_name: str)
Creates a container if it does not already exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_name
|
str
|
The name of the container. |
required |
exists
exists(container_name: str, blob_name: str) -> bool
Checks if a blob exists in the specified container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_name
|
str
|
The name of the container. |
required |
blob_name
|
str
|
The name of the blob. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the blob exists, False otherwise. |
upload_blob
upload_blob(
container_name: str,
blob_name: str,
data: Union[bytes, str, Path],
overwrite: bool = True,
)
Uploads data to a blob in the specified container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_name
|
str
|
The name of the container. |
required |
blob_name
|
str
|
The name of the blob. |
required |
data
|
Union[bytes, str, Path]
|
The data to upload. Can be bytes, a string, or a local file path. |
required |
overwrite
|
bool
|
Whether to overwrite the blob if it already exists. |
True
|
download_blob
download_blob(container_name: str, blob_name: str) -> bytes
Downloads a blob's content as bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_name
|
str
|
The name of the container. |
required |
blob_name
|
str
|
The name of the blob. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The content of the blob. |
list_blobs
list_blobs(container_name: str, **kwargs) -> list[str]
Lists the names of all blobs in a container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_name
|
str
|
The name of the container. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of blob names. |
delete_blob
delete_blob(container_name: str, blob_name: str)
Deletes a blob from the container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_name
|
str
|
The name of the container. |
required |
blob_name
|
str
|
The name of the blob to delete. |
required |
get_sas_url
get_sas_url(
account_name: str,
account_key: str,
container_name: str,
blob_name: str,
) -> str
Gets a sas URL for the specified account, container and blob.
get_sas_token
get_sas_token(
account_name: str, account_key: str, container_name: str
) -> str
Gets a sas token for the specified account and container with full permissions.