skillfed

cf-xarray

A convenience wrapper for using CF attributes on xarray objects

cf-xarray v0.11.3 353.4K downloads/30d#7,303 on PyPI180
Permissive license Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) Active released

What it is and what it does

cf-xarray is a lightweight wrapper that extends xarray with a `.cf` accessor, allowing you to write operations using CF (Climate and Forecast) convention attribute names instead of dataset-specific dimension and coordinate names. Instead of needing to know that a particular file uses 'lat' or 'latitude' or 'y', you can write `.cf.mean('latitude')` and the accessor resolves the actual dimension name from CF metadata attributes on your dataset.

The package is designed for scientists and data engineers working with climate, weather, or other geospatial datasets that follow CF conventions. It reduces the friction of writing code that must work across multiple datasets with different naming schemes, and it depends only on xarray, making it a minimal addition to existing workflows. The package is in production-stable status, actively maintained, and supports Python 3.11, 3.12, and 3.13.

Use it for:

  • Write climate analysis code that works across multiple datasets without hardcoding dimension names like 'lat', 'lon', or 'time'.
  • Automate data processing pipelines where input files may use different naming conventions but follow CF standards.
  • Build reusable analysis functions that accept CF-compliant xarray datasets and operate on standard semantic dimensions.
  • Simplify exploratory data analysis on unfamiliar CF-compliant netCDF or HDF5 files by using semantic names.
  • Integrate with Pangeo or other Earth science data ecosystems where CF conventions are standard.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

cf-xarray adds a `.cf` accessor to xarray objects that lets you reference dimensions and coordinates by their CF (Climate and Forecast) convention attributes instead of hardcoded names, enabling dataset-agnostic operations like `.cf.mean("latitude")`.

Yes. cf-xarray is actively maintained, has no known vulnerabilities, carries a permissive Apache 2.0 license, and adds minimal install friction (pure Python, single dependency). It is worth installing if you work with CF-compliant xarray datasets and want to write code that is independent of dataset-specific naming schemes. If your datasets do not follow CF conventions or you do not use xarray, it offers no benefit.

Install

cf-xarray on PyPI

pip

pip install cf-xarray

uv

uv add cf-xarray

poetry

poetry add cf-xarray

Installing cf-xarray

Before you install

Low friction: pure Python wheel with a single runtime dependency on xarray. Repository is active with a recent commit on 2026-08-01 and 180 stars; last release was 2026-06-12, 63 days ago.

License in practice

Apache License 2.0 is permissive; you may use, modify, and distribute the package freely provided you include a copy of the license and note any changes you make.

Quickstart

pip install cf-xarray

import xarray as xr
import cf_xarray

ds = xr.open_dataset('data.nc')
result = ds.cf.mean('latitude')

Requires xarray to be installed; your dataset must have CF-compliant attributes (e.g., `standard_name` or `long_name`) set on dimensions or coordinates for the `.cf` accessor to recognize them.

Verify before relying

  • Which specific CF attributes (standard_name, long_name, etc.) the accessor recognizes and prioritizes
  • Performance overhead of the accessor layer compared to direct xarray operations
  • Scope of CF convention coverage (e.g., does it handle all CF standard names or a subset)

Package facts

License Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive)
Python support supports the current Python release (>=3.11)
Install friction low — pure-Python wheel
Runtime dependencies 1 — xarray
Maintenance actively maintained — 63 days since the last release
Last repo commit
First released
Downloads 353,374/month — #7,303 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: cf_xarray-0.11.3-py3-none-any.whl

Keywords: xarray, metadata, CF conventions

Development Status :: 5 - Production/StableLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13

Tags

xarray CF conventions wrapperclimate forecast metadata xarraydimension name abstraction xarrayCF attribute accessordataset-agnostic xarray operationsCF-compliant coordinate accessmetadata-driven xarray selection
climate-datametadata-drivenxarray-ecosystem

More Information Analysis packages