xpublish.SingleDatasetRest#
- class xpublish.SingleDatasetRest(dataset, routers=None, cache_kws=None, app_kws=None, plugins=None)[source]#
Used to publish a single Xarray Dataset or DataTree via a REST API (FastAPI application).
Use
xpublish.Restto publish multiple datasets.- __init__(dataset, routers=None, cache_kws=None, app_kws=None, plugins=None)[source]#
Initialize the SingleDatasetRest object.
- Parameters:
dataset (
Union[Dataset,DataTree]) – A singlexarray.Datasetorxarray.DataTreeobject to be served. A Dataset is wrapped in a single-node DataTree internally.routers (
Optional[List[APIRouter]]) – A list of dataset-specificfastapi.APIRouterinstances to include in the fastAPI application. These routers are in addition to any loaded via plugins. The items of the list may also be tuples with the following format:[(router1, {'prefix': '/foo', 'tags': ['foo', 'bar']})], where the 1st tuple element is afastapi.APIRouterinstance and the 2nd element is a dictionary that is used to pass keyword arguments tofastapi.FastAPI.include_router().cache_kws (
Optional[Dict]) – Dictionary of keyword arguments to be passed tocachey.Cache.__init__(). By default, the cache size is set to 1MB, but this can be changed withavailable_bytes.app_kws (
Optional[Dict]) – Dictionary of keyword arguments to be passed tofastapi.FastAPI.__init__().plugins (
Optional[Dict[str,Plugin]]) – Optional dictionary of loaded, configured plugins. Overrides automatic loading of plugins. If no plugins are desired, set to an empty dict.
Methods
__init__(dataset[, routers, cache_kws, ...])Initialize the SingleDatasetRest object.
dependencies()FastAPI dependencies to pass to plugin router methods.
get_dataset_from_plugins(dataset_id[, group])Resolve a Dataset by
dataset_id(and optionalgroup).get_datasets_from_plugins()Return dataset ids from directly loaded datasets and plugins.
get_datatree_from_plugins(dataset_id[, group])Resolve a DataTree by
dataset_id(and optionalgroup).init_app_kwargs(app_kws)Set up FastAPI application kwargs.
init_cache_kwargs(cache_kws)Set up cache kwargs.
plugin_routers()Load the app and dataset routers for plugins.
register_plugin(plugin[, plugin_name, overwrite])Register a plugin with the xpublish system.
serve([host, port, log_level])Serve this FastAPI application via
uvicorn.run().setup_datasets(datasets)Modifies dataset loading to instead connect to the single dataset/DataTree.
setup_plugins([plugins])Initialize and load plugins from entry_points unless explicitly provided.
Attributes
appReturns the
fastapi.FastAPIapplication instance.cacheReturns the
cachey.Cacheinstance used by the FastAPI application.pluginsReturns the loaded plugins.