sc_tools.storage — Storage Abstraction#
fsspec-based URI resolution for reading and writing data across local filesystem, SFTP/HPC, S3, GCS, Azure, and Box.
from sc_tools.storage import smart_read_h5ad, smart_write_checkpoint
# Read from HPC scratch via SFTP
adata = smart_read_h5ad("sftp://brb//athena/.../adata.raw.h5ad")
# Write to S3
smart_write_checkpoint(adata, "s3://bucket/results/adata.normalized.h5ad")
Install remote backends: pip install sc-tools[storage]
- sc_tools.storage.resolve_fs(uri)[source]#
Return
(AbstractFileSystem, path)for any URI or local path.- Parameters:
uri (
str|PathLike) – File URI or local path. Examples:"/local/path","s3://bucket/key","sftp://brb//athena/.../file.h5ad".- Returns:
Filesystem object and the path within that filesystem.
- Return type:
- Raises:
ImportError – When the backend required for the URI scheme is not installed.
- sc_tools.storage.with_local_copy(uri)[source]#
Yield a local Path, downloading from remote when necessary.
For local URIs this is a no-op (returns the original path unchanged). For remote URIs the file is downloaded to a temporary file first.
Useful for libraries (
scanpy,tifffile) that need a real filesystem path rather than a file-like object.
- sc_tools.storage.smart_read_h5ad(uri, *, backed=None)[source]#
Read an AnnData
.h5adfile from any URI.For local paths calls
anndata.read_h5addirectly (backed mode supported). For remote URIs the file is downloaded first (backed mode not supported remotely).
- sc_tools.storage.smart_write_checkpoint(adata, uri, *, fmt='h5ad')[source]#
Write AnnData to any URI in h5ad or zarr format.
For local paths writes directly. For remote URIs with
fmt="h5ad"the file is serialised to a buffer and then uploaded. Zarr format delegates toadata.write_zarr(uri)which uses fsspec natively.