API reference#
Top-level Rest class#
The Rest class can be used for publishing a
xarray.Dataset or xarray.DataTree object, or a collection of either.
A bare Dataset is wrapped in a single-node DataTree internally so the rest of the
library operates uniformly on hierarchical data.
The main interfaces to Xpublish that many users may use.
|
Used to publish multiple Xarray Datasets / DataTrees via a REST API (FastAPI application). |
Returns the |
|
Returns the |
|
Returns the loaded plugins. |
|
|
Serve this FastAPI application via |
|
Register a plugin with the xpublish system. |
FastAPI dependencies to pass to plugin router methods. |
There are also a handful of methods that are more likely to be used
when subclassing xpublish.Rest to modify functionality, or are used
by plugin dependencies.
|
Initialize datasets and dataset accessor functions. |
Return dataset ids from directly loaded datasets and plugins. |
|
|
Resolve a Dataset by |
|
Resolve a DataTree by |
|
Initialize and load plugins from entry_points unless explicitly provided. |
|
Set up cache kwargs. |
|
Set up FastAPI application kwargs. |
Load the app and dataset routers for plugins. |
There is also a specialized version of xpublish.Rest for use
when only a single dataset is being served, instead of a collection
of datasets.
|
Used to publish a single Xarray Dataset or DataTree via a REST API (FastAPI application). |
|
Modifies dataset loading to instead connect to the single dataset/DataTree. |
For serving a single dataset the SingleDatasetRest is used instead.
|
Used to publish a single Xarray Dataset or DataTree via a REST API (FastAPI application). |
Dataset.rest (xarray accessor)#
This accessor extends xarray.Dataset with the same interface than
SingleDatasetRest. 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
|
Initialize this accessor by setting optional configuration values. |
Properties
Returns the |
|
Returns the |
Methods
|
Serve this FastAPI application via |
DataTree.rest (xarray accessor)#
The same accessor is registered on xarray.DataTree, exposing the
same interface for publishing a single hierarchical tree:
>>> import xarray as xr
>>> import xpublish
>>> dt = xr.DataTree() # or load one with xr.open_datatree(...)
>>> dt.rest(...) # configure (optional)
>>> dt.rest.serve() # serve the tree
Calling the accessor
|
Initialize this accessor by setting optional configuration values. |
Properties
Returns the |
|
Returns the |
Methods
|
Serve this FastAPI application via |
FastAPI dependencies#
The functions below are defined in module xpublish.dependencies and can
be used as FastAPI dependencies
when creating custom API endpoints directly.
When creating routers with plugins, instead use xpublish.Dependency that will be
passed in to the Plugin.app_router or Plugin.dataset_router method.
FastAPI dependency for getting the list of ids (string keys) of the collection of datasets being served. |
|
|
FastAPI dependency for accessing the published xarray dataset object. |
|
FastAPI dependency for accessing the published xarray DataTree object. |
FastAPI dependency for accessing the application's cache. |
|
FastAPI dependency that returns the a dictionary of loaded plugins. |
|
Return the active plugin manager. |
When a route declares a {group_path:path} segment, get_dataset returns
the Dataset at that node of the underlying DataTree (or the root dataset if no
group_path is present). get_datatree returns the subtree rooted at the
requested group.