Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

spatialbatch

Tests Documentation

A minibatch loader for on-disk SpatialData stores: tiles of every image and labels element, centered on each cell, together with the cell's expression and annotations, streamed in large preloaded chunks.

spatialbatch is built on, and has annbatch as a dependency. It follows the same design: a Sampler emits requests for chunks of consecutive cells, one request is read from disk at once (concurrently for every modality, through async zarr and optionally zarrs-python), shuffled in memory and split into batches. No torch DataLoader is needed. It reimplements spatialstream.dataloaders.XeniumDataset, which it reproduces exactly (see tests/test_parity.py).

import spatialdata as sd
import zarr
from spatialbatch import Loader

zarr.config.set({"codec_pipeline.path": "zarrs.ZarrsCodecPipeline"})  # optional, see docs/zarr-configuration.md

loader = Loader(
    images=["morphology_focus"],
    labels=["cell_labels"],
    tile_dim_in_units=224,
    rasterize=True,
    rasterize_kwargs={"target_unit_to_pixels": 1.0},
    return_annotations=["cell_labels"],
    batch_size=32,
    shuffle=True,
    to="torch",
).add_sdata(sd.read_zarr("xenium.zarr"))

for batch in loader:
    batch["images"]["morphology_focus"]  # (32, 1, 224, 224)
    batch["labels"]["cell_labels"]  # (32, 224, 224)
    batch["X"]  # (32, n_genes) sparse CSR expression

For the best throughput, write the stores once into a spatially sorted, sharded SpatialDatasetCollection:

from spatialbatch import Loader, SpatialDatasetCollection

collection = SpatialDatasetCollection("collection.zarr")
collection.add_sdatas(["a.zarr", "b.zarr"], images=["morphology_focus"], labels=["cell_labels"], tile_dim_in_units=224)
loader = Loader(images=["morphology_focus"], batch_size=32, shuffle=True, tile_dim_in_units=224).use_collection(
    collection
)

Getting started

Please refer to the documentation, in particular, the API documentation.

Installation

You need to have Python 3.12 or newer installed on your system. If you don't have Python installed, we recommend installing uv.

We recommend managing dependencies in project-specific virtual environments to avoid dependency conflicts. This is most convenient using package managers such as uv. Choose from the options below to install spatialbatch:

  1. Install the latest development version:

    pip install git+https://github.com/rushin682/spatialbatch.git  # (or `uv add`)
    

Release notes

See the changelog.

Contact

For questions and help requests, you can reach out in the scverse discourse. If you found a bug, please use the issue tracker.

Citation

t.b.a

Metadata

Release files for spatialbatch 0.0.1rc1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spatialbatch 0.0.1rc1
File Size Uploaded Provenance Actions
spatialbatch-0.0.1rc1.tar.gz 27.7 kB With provenance Details for spatialbatch-0.0.1rc1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spatialbatch 0.0.1rc1
File Interpreter ABI Platform Actions
spatialbatch-0.0.1rc1-py3-none-any.whl Python 3 none any Details for spatialbatch-0.0.1rc1-py3-none-any.whl

Total release size: 51.3 kB

Release files / spatialbatch-0.0.1rc1.tar.gz

Download URL spatialbatch-0.0.1rc1.tar.gz
Size 27.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a161f65e91f43df1cf6e29cfdbb1e0a0f8a7b5bd56697f1718223f265ee9f9b5
BLAKE2b-256 checksum
How to use checksums
00cbd4e337760ab4e0443829439f0bc9bb83734903f924e0783ce48524769fe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Release files / spatialbatch-0.0.1rc1-py3-none-any.whl

Download URL spatialbatch-0.0.1rc1-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0df473f519d8851ef2e885a30c453006d1125e058cfbb4a4d8eed7a95fddcd69
BLAKE2b-256 checksum
How to use checksums
d7cfb324f8ed05ee2eb26a9f104d41ee3053eaa3650a18afbebb70d88575ae7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

Security for spatialbatch 0.0.1rc1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spatialbatch-0.0.1rc1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page