Storix session¶
Everything you call on a session. A Storix is created over a backend (or built
by get_storage), and every path argument is resolved the unix way (~, ..,
and the current working directory) before it reaches the backend. Any operation
raises a typed error on failure; nothing returns a boolean you have
to check.
Unless noted, every method has an awaitable twin under storix.aio with the same
name and signature.
Session and navigation¶
pwd¶
The current working directory.
cd¶
Change the working directory. No argument returns to home. Returns the session
for chaining.
ls¶
List a directory (the cwd by default). Dotfiles are hidden unless all=True.
abs=True returns absolute paths instead of names.
resolve¶
Resolve a path to its absolute, normalized port path (applying cwd, ~, ..),
without touching the backend. Useful for logging and bookmarking.
locate¶
The physical URI of a path (file://..., abfss://...), resolved through any
sandbox. Use it for audit and cross-system references.
Properties¶
backend -> StorageBackend # the raw port, for backend-specific calls
root -> StorixPath # always '/'
home -> StorixPath # the '~' anchor
Reading¶
cat¶
Read one or more files fully and concatenate them into bytes. Use for small,
known-size content. For large files, prefer stream.
stream¶
Read files back in chunks, so a large file never lands in memory all at once. See Reading and writing.
stat¶
Facts about a path: kind, size, and (where the backend supports it) content type and custom metadata.
du¶
Total size in bytes of a tree (apparent content bytes).
exists, isfile, isdir¶
exists(path: StrPathLike | None = None) -> bool
isfile(path: StrPathLike | None = None) -> bool
isdir(path: StrPathLike | None = None) -> bool
Existence and kind checks.
Writing and creating¶
echo¶
echo(
data: DataBuffer[str] | DataBuffer[bytes],
path: StrPathLike,
/,
*,
mode: EchoMode = "w",
content_type: str | None = None,
metadata: Mapping[str, str] | None = None,
) -> None
Write data to path. data accepts native Python: bytes, str, a Buffer,
an open file (IO), or an iterable of chunks (and an async iterable under
storix.aio). mode="a" appends. content_type and metadata are applied where
the backend supports them.
touch¶
Create empty files, or refresh their modification time if they exist.
mkdir¶
Create directories. parents=True creates missing parents and does not error if
the directory already exists (unix mkdir -p).
set_metadata¶
Replace a file's custom metadata ({} clears it). merge=True does a
non-atomic read-modify-write to add keys instead of replacing. Requires the
custom_metadata capability.
Moving, copying, removing¶
Move and copy are variadic; the last argument is the destination, like unix.
mv¶
Move or rename. With more than two paths, all sources move into the final directory.
cp¶
Copy. recursive=True to copy directories.
rm¶
Remove files. recursive=True removes directories and their contents (unix
rm -r).
rmdir¶
Remove strictly empty directories.
URLs and sharing¶
url¶
A presigned URL (an Azure SAS link). Requires the presigned_urls capability;
raises UnsupportedOperationError otherwise. Use DataUrlLayer to
get one on any backend.
data_url¶
A base64 data: URL, generated by the core for any backend.
Composition¶
with_layer, with_layer_missing¶
Return a new session with layer wrapping this backend. with_layer_missing
skips the layer when the backend already provides its capability. See
Layers.
without_layer, uncached¶
without_layer(*layers: type) -> Self
uncached -> Self # property; sugar for without_layer(CacheLayer)
Return a session with the given layer types bypassed. Absent layers are a no-op;
a SandboxLayer cannot be stripped.
chroot, scratch¶
chroot(path: StrPathLike, /) -> Self
scratch(*, root: StrPathLike | None = None, prefix: str = "scratch-") -> ContextManager[Storix]
chroot returns a sandboxed session rooted at path. scratch is a context
manager giving a disposable (or pinned, with root) workspace on the same
backend.
Lifecycle¶
Release the backend's resources (idempotent). In async code, use the session as
a context manager: async with get_storage("azure") as fs: ....