diff --git a/src/spatialdata/__init__.py b/src/spatialdata/__init__.py index 8b0664ab..dbe0dcbe 100644 --- a/src/spatialdata/__init__.py +++ b/src/spatialdata/__init__.py @@ -53,6 +53,7 @@ ] from spatialdata import dataloader, datasets, models, transformations +from spatialdata._accessors import io from spatialdata._core._deepcopy import deepcopy from spatialdata._core.centroids import get_centroids from spatialdata._core.concatenate import concatenate diff --git a/src/spatialdata/_accessors.py b/src/spatialdata/_accessors.py new file mode 100644 index 00000000..ff402a9c --- /dev/null +++ b/src/spatialdata/_accessors.py @@ -0,0 +1,16 @@ +import types + +try: + import spatialdata_io as io +except ImportError: + + io = types.ModuleType("spatialdata_io") + + def _raise_install_spatialdata_io() -> None: + raise AttributeError( + "To use readers, `spatialdata_io` must be installed, e.g. via `pip install spatialdata-io`." + ) + + io.__getattr__ = lambda *_: _raise_install_spatialdata_io() + +__all__ = ["io"]