pint-xarray
Physical units interface to xarray using Pint
What it is and what it does
pint-xarray bridges Pint's physical units library with xarray's labeled multidimensional arrays, letting you attach and track units on dataset variables and perform unit-aware arithmetic and conversions. It works by registering accessor methods on xarray objects, so you call `.pint.quantify()` to add units, `.pint.to()` to convert between units, and `.pint.dequantify()` to strip units back off.
The package is designed for scientific and engineering workflows where dimensional consistency matters—tracking whether a measurement is in meters or kilometers, seconds or milliseconds—and catching unit mismatches before they propagate through calculations. It integrates directly with xarray's data model, so units stay attached to variables as you slice, combine, or transform datasets.
Use it for:
- Attach units to climate or weather model output and convert between unit systems for analysis.
- Track physical dimensions through geophysical data processing pipelines to catch unit errors early.
- Perform dimensional analysis on scientific datasets to ensure unit consistency across operations.
- Convert measurement data from one unit system to another while preserving xarray's labeled structure.
- Build unit-aware data pipelines for physics or engineering simulations using xarray as the data container.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds physical units support to xarray datasets and data variables using Pint, enabling unit-aware arithmetic and conversions on multidimensional labeled arrays.
Yes. The package is actively maintained, has no known vulnerabilities, installs with low friction, and fills a genuine gap for scientists and engineers working with xarray who need physical units. The Apache-2.0 license is permissive. Start with it if you're already using xarray and need dimensional tracking; the API is straightforward and the dependency footprint is small.
Install
pint-xarray on PyPI
pip
pip install pint-xarrayuv
uv add pint-xarraypoetry
poetry add pint-xarrayInstalling pint-xarray
Before you install
Low friction installation with a pure-Python wheel. Actively maintained as of 2026-08-14 with recent releases; depends on three well-established packages (xarray, numpy, pint) that are standard in scientific Python.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions, making it safe for most projects.
Quickstart
pip install pint-xarray
import pint_xarray
import xarray as xr
ds = xr.Dataset({"a": ("x", [0, 1, 2]), "b": ("y", [-3, 5, 1], {"units": "m"})})
q = ds.pint.quantify(a="s")
c = q.pint.to({"a": "ms", "b": "km"})
Requires Python 3.11 or later.
Verify before relying
- Whether unit-aware operations preserve xarray's lazy evaluation and chunking (Dask integration).
- Performance impact of unit tracking on large multidimensional arrays.
- Compatibility with xarray's groupby, resample, and other high-level operations when units are attached.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — xarray, numpy, pint |
| Maintenance | actively maintained — 144 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 113,278/month — #12,347 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pint_xarray-0.6.1-py3-none-any.whl
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
PintPint defines, operates on, and converts between…
permissive · top 5,000 on PyPI
unytAttaches units to NumPy arrays and provides…
permissive · top 15,000 on PyPI
xarray-dataclassDefines typed xarray DataArray and Dataset…
permissive · top 15,000 on PyPI
Pint-PandasPint-Pandas adds physical unit support to…
permissive · top 15,000 on PyPI
ucumvertParses UCUM (Unified Code for Units of Measure)…
permissive · top 15,000 on PyPI
typedunitsImplements unit of measurement arithmetic with…
permissive · top 15,000 on PyPI
xarrayxarray adds dimension, coordinate, and…
permissive · top 5,000 on PyPI
hepunitsProvides units and physical constants in the…
permissive · top 15,000 on PyPI
quantitiesQuantities handles arithmetic and unit…
unclear · top 15,000 on PyPI
spatial_imagespatial-image provides an N-dimensional spatial…
permissive · top 15,000 on PyPI