xaviernogueira / xpublish-file-metadata

A xpublish plugin to serve xarray source file metadata (netcdf, GRIB, hdf5, or geoTIFF)
MIT License
1 stars 0 forks source link
api-rest file-formats geospatial-data plugin xarray

Pre-Commit Status Tests Status Coverage

xpublish-file-metadata

A simple xpublish "dataset router" plugin for serving metadata from the underlying files xarray is reading from.

Note: Zarr format metadata is already served by xpublish natively and is not handled by this plugin.

Overview

Roadmap

Installation

Since this plugin is split into multiple submodules (or sub-plugins, one for each file format), you can install only the parts you need. The drawback is that if you just install this library without any of the optional dependencies, the endpoints provided won't work.

To install the plugin without any file-format sub-plugins use:

pip install xpublish-file-metadata

We provide the the following dependency groups for ease of installation:

# for netcdf file support
pip install xpublish-file-metadata[netcdf]

# for geotiff file support
pip install xpublish-file-metadata[geotiff]

# for hdf5 file support
pip install xpublish-file-metadata[hdf5]

# for grib file support
pip install xpublish-file-metadata[grib]

# for support of any combination of the above
pip install xpublish-file-metadata[netcdf,geotiff,hdf5,grib]

Hiding Attributes

For a variety of security reasons one may not want to expose all file metadata on a server. To hide certain attributes from being served, one can use the hide_attrs parameter when registering the plugin. This parameter can take either a list of strings attribute names to hide regardless of file format or a dictionary mapping file format names to a list of attribute names to hide for that file format.

Below are two examples using the xpublish.Rest syntax:

import xpublish
from xpublish_file_metadata import FileMetadataPlugin

mock_dataset: xarray.Dataset = ...

# to hide "history" attributes from all file formats
xpublish.Rest(
    datasets={'my_data': mock_dataset},
    plugins=[
        FileMetadataPlugin(
            hide_attrs=['history'],
        ),
    ],
)

# to hide "history" attributes from netcdf files only
xpublish.Rest(
    datasets={'my_data': mock_dataset},
    plugins=[
        FileMetadataPlugin(
            hide_attrs={'netcdf': ['history']}
        ),
    ],
)

Contributing

Contributions are welcome! We encourage you to open an issue or pull request if you have anything to request or add respectively.