xpublish.SingleDatasetRest#
- class xpublish.SingleDatasetRest(dataset, routers=None, cache_kws=None, app_kws=None, plugins=None)[source]#
Used to publish a single Xarray dataset via a REST API (FastAPI application).
Use
xpublish.Rest
to publish multiple datasets.- __init__(dataset, routers=None, cache_kws=None, app_kws=None, plugins=None)[source]#
Initialize the SingleDatasetRest object.
- Parameters:
dataset (
Dataset
) – A singlexarray.Dataset
object to be served.routers (
Optional
[List
[APIRouter
]]) – A list of dataset-specificfastapi.APIRouter
instances 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.APIRouter
instance 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])Attempts to load dataset from plugins.
get_datasets_from_plugins
()Return dataset ids from directly loaded datasets and plugins.
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.
setup_plugins
([plugins])Initialize and load plugins from entry_points unless explicitly provided.
Attributes
app
Returns the
fastapi.FastAPI
application instance.cache
Returns the
cachey.Cache
instance used by the FastAPI application.plugins
Returns the loaded plugins.