Skip to main content

simple-zarr-server

License PyPI Python Version tests

A minimal server for sharing zarr over HTTP.


Installation

You can install simple-zarr-server via pip:

pip install simple-zarr-server

Usage

CLI:

$ simple-zarr-server --help

# Usage: simple-zarr-server [OPTIONS] PATH
#
# Options:
#  --cors TEXT                     Origin to allow CORS. Use wildcard '*' to allow all.
#  -w, --allow-write
#  --host TEXT                     Bind socket to this host.  [default: 127.0.0.1]
#
#  --port INTEGER                  Bind socket to this port.  [default: 8000]
#  --reload                        Enable auto-reload.
#  --loop [auto|asyncio|uvloop]    Event loop implementation.  [default: auto]
#  --http [auto|h11|httptools]     HTTP protocol implementation.  [default: auto]
#
#  --ws [auto|none|websockets|wsproto]
#                                  WebSocket protocol implementation. [default: auto]
#
#  --use-colors / --no-use-colors  Enable/Disable colorized logging.
#  --proxy-headers / --no-proxy-headers
#                                  Enable/Disable X-Forwarded-Proto,
#                                  X-Forwarded-For, X-Forwarded-Port to
#                                  populate remote address info.
#
#  --forwarded-allow-ips TEXT      Comma seperated list of IPs to trust with
#                                  proxy headers. Defaults to the
#                                  $FORWARDED_ALLOW_IPS environment variable if
#                                  available, or '127.0.0.1'.

$ simple-zarr-server /dataset.zarr # or /dataset.n5, or /dataset.zip
# INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)

Python API:

The python API is more flexible than the CLI, and can serve any zarr.Array, zarr.Group or np.ndarray.

Server
from simple_zarr_server import serve
import numpy as np
arr = np.random.rand(1024, 1024)
serve(arr) # creates an in-memory store if not zarr.Array or zarr.Group
Client
zarr-python
import zarr
from fsspec import get_mapper
store = get_mapper("http://localhost:8000")
arr = zarr.open(store, mode='r')
# or 
import dask.array as da
arr = da.from_zarr("http://localhost:8000")
zarr.js
import { openArray } from 'zarr';
arr = await openArray({ store: 'http://localhost:8000' });

Advanced: Serving a remote pyramidal tiff as Zarr

Server
from napari_lazy_openslide import OpenSlideStore
from simple_zarr_server import serve
import zarr

store = OpenSlideStore('tumor_004.tif') # custom zarr store
grp = zarr.open(store)
serve(grp)
Client
import napari
import dask.array as da
import zarr
from fsspec import get_mapper

store = get_mapper("http://localhost:8000")
z_grp = zarr.open(store)
datasets = z_grp.attrs["multiscales"][0]["datasets"]
pyramid = [
    da.from_zarr(store, component=d["path"]) for d in datasets
]
with napari.gui_qt():
    napari.view_image(pyramid)

Note

This package is experimental. It wraps any zarr-python store as a REST API, enabling remote access over HTTP. It is similar to xpublish, but is more minimal and does not provide special endpoints that are specific to Xarray datasets. If your data are Xarray dataset, please use xpublish! simple-zarr-server was designed with imaging data in mind, and when combined with a tool like ngrok provides an interesting way to share local images with collaborators.

Some non-standard zarr stores that might be of interest include:

Contributing

Contributions are very welcome. Tests can be run with hatch run cov.

License

Distributed under the terms of the BSD-3 license, "simple-zarr-server" is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Metadata

Release files for simple-zarr-server 0.2.0

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

Source distribution (sdist)

Source distribution for simple-zarr-server 0.2.0
File Size Uploaded
simple_zarr_server-0.2.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simple-zarr-server 0.2.0
File Interpreter ABI Platform
simple_zarr_server-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.5 kB

Release files / simple_zarr_server-0.2.0.tar.gz

Download URL simple_zarr_server-0.2.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
eef475bb342bb606a0fddf6969f84b3d15a96b4555bf2d8fd709042f8338b93e
BLAKE2b-256 checksum
How to use checksums
f319abe4d8529a677bd49f0f0a0ba9885ac40e5371108e5e72b1e58493c551a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.4

Release files / simple_zarr_server-0.2.0-py3-none-any.whl

Download URL simple_zarr_server-0.2.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
56c668936bae5ff090794127d28385c5c4726bacfa47d415d19b2eab76d01f0d
BLAKE2b-256 checksum
How to use checksums
77d37562a8a62e5fcd6e81d5f5fffd4f4abbbf858877b9390d64c99d2ed1f11b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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