AsyncAzureBackend¶
Native async Azure Storage backend. Uses the async Blob SDK for non-HNS
accounts (plain Blob Storage, Azurite) and the async DataLake SDK for HNS
accounts (ADLS Gen2) to get atomic rename and real directory support.
Whether the account is HNS is declared via the required hns argument; use
AzureUtils.adetect_hns() to discover it once if unknown.
AsyncAzureBackend
¶
AsyncAzureBackend(
container: str,
*,
hns: bool | None = None,
account_name: str | None = None,
account_url: str | None = None,
account_key: str | Secret | None = None,
sas_token: str | Secret | None = None,
connection_string: str | Secret | None = None,
credential: Any | None = None,
client_options: dict[str, Any] | None = None,
retry: RetryPolicy | None = None,
max_concurrency: int = 1,
reject_write_under_file_ancestor: bool = False,
)
Async Azure Storage backend.
Uses the async Blob SDK for non-HNS accounts (plain Blob Storage, Azurite)
and the async DataLake SDK for HNS accounts (ADLS Gen2) to get atomic
rename and real directory support. Whether the account is HNS is declared
explicitly via the required hns argument -- the backend does not probe
for it.
Parameters:
-
container(str) –Azure Storage container name (required, non-empty).
-
hns(bool | None, default:None) –Whether the storage account has Hierarchical Namespace enabled (ADLS Gen2). Required -- there is no default and no runtime auto-detection. Pass
Truefor ADLS Gen2 accounts (atomic rename, real directories) orFalsefor flat Blob Storage. UseAzureUtils.adetect_hns()to discover the value once if you do not already know it. -
account_name(str | None, default:None) –Storage account name.
-
account_url(str | None, default:None) –Full account URL (e.g.
https://myaccount.dfs.core.windows.net). -
account_key(str | Secret | None, default:None) –Storage account key.
-
sas_token(str | Secret | None, default:None) –Shared Access Signature token.
-
connection_string(str | Secret | None, default:None) –Azure Storage connection string.
-
credential(Any | None, default:None) –Any credential object (e.g.
DefaultAzureCredential()). -
client_options(dict[str, Any] | None, default:None) –Additional options passed to service clients. The library sets
max_single_put_size,max_block_size, andmin_large_block_upload_thresholddefaults for streaming memory discipline; user-supplied values take precedence. -
retry(RetryPolicy | None, default:None) –Retry policy for transient failures.
-
max_concurrency(int, default:1) –Maximum number of parallel connections for uploads and downloads (default
1-- sequential). -
reject_write_under_file_ancestor(bool, default:False) –If
True,write/write_atomic/move/copyHEAD each slash-aligned ancestor of the target path on non-HNS accounts and raiseInvalidPathon the first regular-file hit, matching the cross-backend contract that hierarchical filesystems enforce natively. On HNS accounts the kwarg short-circuits:hdi_isfolderrejects the operation natively, and the backend detects the file ancestor on that rejection and re-raises it asInvalidPath, so HNS delivers the cross-backend contract with or without the kwarg set. DefaultFalse.
check_health
async
¶
Verify the backend is reachable and credentials are valid.
Raises:
-
PermissionDenied–If credentials are invalid.
-
NotFound–If the container does not exist.
-
BackendUnavailable–If the backend cannot be reached.
to_key
¶
Convert a backend-native path to a backend-relative key.
Parameters:
-
native_path(str) –Absolute or backend-native path string.
Returns:
-
str–Path relative to the backend's root.
native_path
¶
Convert a backend-relative key to the backend-native path.
Parameters:
-
path(str) –Backend-relative key.
Returns:
-
str–Backend-native path (
container/path).
resolve
¶
resolve(path: str) -> ResolutionPlan
Return a ResolutionPlan with Azure-specific details.
Parameters:
-
path(str) –Backend-relative key.
Returns:
-
ResolutionPlan–Plan with
kind="async-azure"anddetailscontaining -
ResolutionPlan–containerandaccount_url.
exists
async
¶
Check if a file or folder exists.
The root always exists, decided from the key before any request, so it
answers True whether the container is missing or denied. For every
other path an absent container answers False — a container that
does not exist holds no path either, and this probe never raises for a
missing path — while a denied container raises: the prefix listing is
the determinant there, so it fails closed rather than reporting "nothing
there" for something you may not see.
Parameters:
-
path(str) –Backend-relative key, or
""for the root.
Returns:
-
bool–Trueif a file or folder exists at path.
is_file
async
¶
Return True if path is an existing file.
Parameters:
-
path(str) –Backend-relative key, or a root spelling (
""/"."), which is a folder and answersFalsewithout a round trip.
Returns:
-
bool–Trueif path exists and is a file.
is_folder
async
¶
Return True if path is an existing folder.
The root is always a folder, decided from the key and so answered for a
denied container as well as a missing one. For every other path an absent
container answers False, on the same terms as exists.
Parameters:
-
path(str) –Backend-relative key, or
""for the root.
Returns:
-
bool–Trueif path exists and is a folder.
read
async
¶
Open a file for reading and return an async iterator of byte chunks.
Parameters:
-
path(str) –Backend-relative key.
Returns:
-
AsyncIterator[bytes]–An async iterator yielding byte chunks.
Raises:
-
NotFound–If the file does not exist.
-
InvalidPath–If
pathnames a directory (HNS accounts only).
read_bytes
async
¶
Read the full content of a file as bytes.
Parameters:
-
path(str) –Backend-relative key.
Returns:
-
bytes–The file content.
Raises:
-
NotFound–If the file does not exist.
-
InvalidPath–If
pathnames a directory (HNS accounts only).
write
async
¶
write(
path: str,
content: AsyncWritableContent,
*,
overwrite: bool = False,
metadata: Mapping[str, str] | None = None,
) -> WriteResult
Write content to a file.
Parameters:
-
path(str) –Backend-relative key.
-
content(AsyncWritableContent) –Data to write (bytes or async iterator of bytes).
-
overwrite(bool, default:False) –If
False, raise if file already exists. -
metadata(Mapping[str, str] | None, default:None) –Optional user-defined string metadata.
Returns:
-
WriteResult–WriteResultwith native Azure fields (etag,last_modified, -
WriteResult–etc.) populated from the SDK upload response.
Raises:
-
AlreadyExists–If the file exists and
overwriteisFalse. -
InvalidPath–If
pathis the store root, or names a directory.
write_atomic
async
¶
write_atomic(
path: str,
content: AsyncWritableContent,
*,
overwrite: bool = False,
metadata: Mapping[str, str] | None = None,
) -> WriteResult
Write content atomically via temp file + rename.
For non-HNS accounts, direct upload is atomic (PUT semantics). For HNS accounts, write to temp file via DFS then atomic rename.
Parameters:
-
path(str) –Backend-relative key.
-
content(AsyncWritableContent) –Data to write.
-
overwrite(bool, default:False) –If
False, raise if file already exists. -
metadata(Mapping[str, str] | None, default:None) –Optional user-defined string metadata.
Returns:
-
WriteResult–WriteResultwith native Azure fields populated from the SDK -
WriteResult–response (non-HNS) or from
get_file_properties()after rename -
WriteResult–(HNS).
Raises:
-
AlreadyExists–If the file exists and
overwriteisFalse. -
InvalidPath–If
pathis the store root, or names a directory.
delete
async
¶
Delete a file.
Parameters:
-
path(str) –Backend-relative key.
-
missing_ok(bool, default:False) –If
True, do not raise when the file is absent. This covers an absent container too, on the same terms asdelete_folder. Verified on flat (non-HNS) accounts; the HNS branch is not exercised against an absent container, so the same answer there is expected rather than measured.
Raises:
-
NotFound–If the file is missing (including when the container itself is absent) and
missing_okisFalse. -
InvalidPath–If
pathnames a directory (HNS accounts only). -
PermissionDenied–If credentials are rejected or lack access (401/403).
-
BackendUnavailable–On throttling (429), 5xx, or transport failure.
delete_folder
async
¶
Delete a folder.
Parameters:
-
path(str) –Backend-relative key.
-
recursive(bool, default:False) –If
True, delete all contents first. -
missing_ok(bool, default:False) –If
True, do not raise when absent. This covers an absent container too: it holds no folder either, so it reads as a missing path rather than a failure.
Raises:
-
NotFound–If the folder is missing (including when the container itself is absent) and
missing_okisFalse. -
InvalidPath–If
pathnames a file (usedeleteinstead). -
DirectoryNotEmpty–If non-empty and
recursiveisFalse. -
PermissionDenied–If credentials are rejected or lack access (401/403).
-
BackendUnavailable–On throttling (429), 5xx, or transport failure.
list_files
async
¶
list_files(
path: str,
*,
recursive: bool = False,
max_depth: int | None = None,
) -> AsyncIterator[FileInfo]
List files under path.
A missing path yields nothing, and so does an absent container — it holds nothing either.
Parameters:
-
path(str) –Backend-relative folder key, or
""for the root. -
recursive(bool, default:False) –If
True, include files in all subdirectories. -
max_depth(int | None, default:None) –Optional maximum folder depth. The whole prefix is listed and depth is filtered client-side, so the bound trims results without reducing I/O.
Returns:
-
AsyncIterator[FileInfo]–An async iterator of
FileInfoobjects.
list_folders
async
¶
list_folders(path: str) -> AsyncIterator[FolderEntry]
List immediate subfolders under path.
A missing path yields nothing, and so does an absent container.
Parameters:
-
path(str) –Backend-relative folder key, or
""for the root.
Returns:
-
AsyncIterator[FolderEntry]–An async iterator of
FolderEntryobjects.
iter_children
async
¶
iter_children(
path: str,
) -> AsyncIterator[FileInfo | FolderEntry]
Yield both files and folders under path in a single pass.
A missing path yields nothing, and so does an absent container.
Parameters:
-
path(str) –Backend-relative folder key, or
""for the root.
Returns:
-
AsyncIterator[FileInfo | FolderEntry]–An async iterator of
FileInfo(files) andFolderEntry(folders).
glob
async
¶
glob(pattern: str) -> AsyncIterator[FileInfo]
Match files against a glob pattern.
Reaches the wire only through list_files, so an absent container
yields nothing here too.
Parameters:
-
pattern(str) –Glob pattern (e.g.,
"data/*.csv","**/*.txt").
Returns:
-
AsyncIterator[FileInfo]–An async iterator of matching
FileInfoobjects.
get_file_info
async
¶
get_file_info(path: str) -> FileInfo
Get metadata for a file.
Parameters:
-
path(str) –Backend-relative key.
Returns:
-
FileInfo–A
FileInfowith size, modification time, etc.
Raises:
-
InvalidPath–If
pathnames a directory (HNS:hdi_isfolder=true). -
NotFound–If the file does not exist.
get_folder_info
async
¶
get_folder_info(path: str) -> FolderInfo
Get metadata for a folder.
Parameters:
-
path(str) –Backend-relative folder key, or
""for the root.
Returns:
-
FolderInfo–A
FolderInfowith file count, total size, etc.
The root aggregates whether or not the container is there: an absent container is an empty store at the root, not a missing path.
Raises:
-
NotFound–If the folder does not exist. Not for the root, which exists by definition.
-
InvalidPath–If
pathnames a file (useget_file_infoinstead).
move
async
¶
Move or rename a file.
Parameters:
-
src(str) –Backend-relative source key.
-
dst(str) –Backend-relative destination key.
-
overwrite(bool, default:False) –If
True, replace any existing file at dst.
Raises:
-
NotFound–If
srcdoes not exist. -
InvalidPath–If
srcordstis the store root, or names a directory (HNS only). -
AlreadyExists–If
dstexists andoverwriteisFalse.
copy
async
¶
Copy a file.
Parameters:
-
src(str) –Backend-relative source key.
-
dst(str) –Backend-relative destination key.
-
overwrite(bool, default:False) –If
True, replace any existing file at dst.
Raises:
-
NotFound–If
srcdoes not exist. -
InvalidPath–If
srcordstis the store root, or names a directory (HNS only). -
AlreadyExists–If
dstexists andoverwriteisFalse.
unwrap
¶
Return the native async FileSystemClient if it matches the requested type.
Parameters:
-
type_hint(type[T]) –The expected type.
Returns:
-
T–The native async client instance matching type_hint.
Raises:
-
CapabilityNotSupported–If backend cannot provide the requested type.
See also¶
- AzureBackend — synchronous counterpart
- Azure Backend Guide — configuration and usage
- Azure HNS setup — ADLS Gen2 provisioning