API reference

Top-level Rest class

The Rest class can be used for publishing a xarray.Dataset object or a collection of Dataset objects.

Rest(datasets[, routers, cache_kws, app_kws])

Used to publish one or more Xarray Datasets via a REST API (FastAPI application).

Rest.app

Returns the fastapi.FastAPI application instance.

Rest.cache

Returns the cachey.Cache instance used by the FastAPI application.

Rest.serve([host, port, log_level])

Serve this FastAPI application via uvicorn.run().

Dataset.rest (xarray accessor)

This accessor extends xarray.Dataset with the same interface than Rest. It is a convenient method for publishing one single dataset. Proper use of this accessor should be like:

>>> import xarray as xr         # first import xarray
>>> import xpublish             # import xpublish (the dataset 'rest' accessor is registered)
>>> ds = xr.Dataset()           # create or load an xarray Dataset
>>> ds.rest(...)                # call the 'rest' accessor on the dataset
>>> ds.rest.<meth_or_prop>      # access to the methods and properties listed below

Calling the accessor

Dataset.rest(**kwargs)

Initialize this accessor by setting optional configuration values.

Properties

Dataset.rest.app

Returns the fastapi.FastAPI application instance.

Dataset.rest.cache

Returns the cachey.Cache instance used by the FastAPI application.

Methods

Dataset.rest.serve(**kwargs)

Serve this FastAPI application via uvicorn.run().

FastAPI dependencies

The functions below are defined in module xpublish.dependencies and can be used as FastAPI dependencies when creating custom API endpoints.

get_dataset_ids()

FastAPI dependency for getting the list of ids (string keys) of the collection of datasets being served.

get_dataset(dataset_id)

FastAPI dependency for accessing the published xarray dataset object.

get_cache()

FastAPI dependency for accessing the application's cache.

get_zvariables([dataset, cache])

FastAPI dependency that returns a dictionary of zarr encoded variables.

get_zmetadata([dataset, cache, zvariables])

FastAPI dependency that returns a consolidated zmetadata dictionary.