Registry / analytics / cf-units

cf-units

JSON →
library3.3.1pypypi✓ verified 83d ago

A Python library for handling units of measure as required by the Climate and Forecast (CF) metadata conventions. It supports unit parsing, conversion, and computation, and is built on top of the UDUNITS-2 library. Current version is 3.3.1, with a stable release cadence.

pip install cf-units
INSTALL
IMPORT
SIG · CF-UNITS
C
cf-units
analyticspythonv3.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Unit
from cf_units import Unit
import cf_units
Importing the package alone does not expose Unit directly; you must import the class.
date2num
from cf_units import date2num
Common function for converting dates to numeric values.

Basic usage: create Unit objects and perform conversions.

from cf_units import Unit # Define units speed = Unit('m/s') temperature = Unit('celsius') # Convert value value_in_kmh = speed.convert(10.0, 'km/h') print(f'10 m/s in km/h: {value_in_kmh}') # Check compatibility print(speed.is_convertible(Unit('knots'))) # True
Debug
Known issues
breakingcf-units v3 requires Python >=3.11. Python 3.10 and older are not supported.
fix
Upgrade Python to 3.11+.
affects: >=3.0
gotchaThe underlying UDUNITS-2 library must be installed at the system level. pip install cf-units does not install it automatically.
fix
Install UDUNITS-2 via conda (conda install -c conda-forge udunits2) or your system package manager (e.g., apt-get install libudunits2-dev on Debian/Ubuntu).
affects: all
gotchaUnit strings are case-sensitive. For example, 'K' (kelvin) is different from 'k' (kilo prefix).
fix
Ensure unit strings follow UDUNITS-2 conventions; double-check case, especially for prefixes.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cf_units'
The package is installed as cf-units but imported as cf_units (with underscore).
fix
Use 'import cf_units' (underscore) in your code.
cf_units.external.ParserError: Can't parse unit string 'foo'
The unit string is invalid or not recognized by UDUNITS-2.
fix
Check the unit string for typos and ensure it adheres to UDUNITS definitions. Use cf_units.Unit.is_udunits() to validate.
OSError: Could not load UDUNITS library: 'libudunits2.so.0: cannot open shared object file: No such file or directory'
UDUNITS-2 shared library is not installed or not in the library path.
fix
Install UDUNITS-2 system-wide (e.g., conda install -c conda-forge udunits2 on Linux, or use conda environment).
Upgrade
Version history
3.3.1latest on PyPI · released Jan 16, 2026
Audit
Dependencies
udunits2requiredSystem library required for unit definitions and conversion; must be installed separately (e.g., via conda or system package manager).
Agent activity
34 hits · last 30 days
node
30
OpenAI (training)
1
Resources
cf-units — pip install cf-units · libregistry