Skip to content

Getting Started

Installation

pip install xrlint

or

conda install -c conda-forge xrlint

Command line interface

Get basic help:

xrlint --help

Initializing a new project with

xrlint --init

writes a configuration file xrlint-config.yaml into the current working directory:

- recommended

This configuration file tells XRLint to use the predefined configuration named recommended.

Create a dataset to test XRLint:

python
>>> import xarray as xr
>>> test_ds = xr.Dataset(attrs={"title": "Test Dataset"})
>>> test_ds.to_zarr("test.zarr") 
>>> exit()

And run XRLint:

xrlint test.zarr 

You can now override the predefined settings by adding your custom rule configurations:

- recommended
- rules:
    no-empty-attrs: off
    var-units-attr: warn
    grid-mappings: error

Built in and auto-loading plugins

The included plugins (such as xcube in the example configs here) and those from external libraries that are findable via entry points do not need to be explicitly loaded.

Run xrlint --print-config <dataset> to view the loaded plugins and configured rules.

Custom plugins, or those that are not loadable via entry points will need to be explcitly loaded via the plugins object.

You can add rules from plugins as well:

- recommended
- plugins:
    xcube: xrlint.plugins.xcube
- xcube/recommended  

And customize its rules, if desired:

- recommended
# Explicit loading of included plugins is unneeded, see note
# - plugins:
#    xcube: xrlint.plugins.xcube
- xcube/recommended  
- rules:
    xcube/grid-mapping-naming: off
    xcube/lat-lon-naming: warn

Note the prefix xcube/ used for the rule names.

Python API

The easiest approach to use the Python API is to import xrlint.all. It contains all the public definitions from the xrlint package.

import xrlint.all as xrl

Start by creating a linter with recommended settings using the new_linter() function .

import xarray as xr
import xrlint.all as xrl

test_ds = xr.Dataset(attrs={"title": "Test Dataset"})

linter = xrl.new_linter("recommended")
linter.validate(test_ds)