Skip to main content

A simple server for sharing zarr over HTTP.

Project description

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 tox.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple-zarr-server-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

simple_zarr_server-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file simple-zarr-server-0.1.0.tar.gz.

File metadata

  • Download URL: simple-zarr-server-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for simple-zarr-server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 066c46ec4ba57d3e7df6ae6f0d2d6a702b36b599c37e36dae70831cfb8c9bd30
MD5 4e67d1b0e63bb84491dc30a0c3f6ef52
BLAKE2b-256 b5beecb4397ccee3ed2c2843e03d344e623f93ae1c0e1170fe7bd390e7a8aea0

See more details on using hashes here.

File details

Details for the file simple_zarr_server-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: simple_zarr_server-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for simple_zarr_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b8915b23422ef9aaa5c67b3426e084dfa5a26b10038826c9f754d80fa1470a6
MD5 0679d2851ce58f3a24cf4524110d4a24
BLAKE2b-256 8db583fe5a2ccd582d8cbe69c59518c46f0abb545b332e602ffcbb20c9745d2c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page