{"id":44551,"library":"cf-units","title":"cf-units","description":"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.","status":"active","version":"3.3.1","language":"python","source_language":"en","source_url":"https://github.com/SciTools/cf-units","tags":["cf-conventions","units","climate","forecast","udunits"],"install":[{"cmd":"pip install cf-units","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"System library required for unit definitions and conversion; must be installed separately (e.g., via conda or system package manager).","package":"udunits2","optional":false}],"imports":[{"note":"Importing the package alone does not expose Unit directly; you must import the class.","wrong":"import cf_units","symbol":"Unit","correct":"from cf_units import Unit"},{"note":"Common function for converting dates to numeric values.","symbol":"date2num","correct":"from cf_units import date2num"}],"quickstart":{"code":"from cf_units import Unit\n\n# Define units\nspeed = Unit('m/s')\ntemperature = Unit('celsius')\n\n# Convert value\nvalue_in_kmh = speed.convert(10.0, 'km/h')\nprint(f'10 m/s in km/h: {value_in_kmh}')\n\n# Check compatibility\nprint(speed.is_convertible(Unit('knots')))  # True","lang":"python","description":"Basic usage: create Unit objects and perform conversions."},"warnings":[{"fix":"Upgrade Python to 3.11+.","message":"cf-units v3 requires Python >=3.11. Python 3.10 and older are not supported.","severity":"breaking","affected_versions":">=3.0"},{"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).","message":"The underlying UDUNITS-2 library must be installed at the system level. pip install cf-units does not install it automatically.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure unit strings follow UDUNITS-2 conventions; double-check case, especially for prefixes.","message":"Unit strings are case-sensitive. For example, 'K' (kelvin) is different from 'k' (kilo prefix).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'-2':37 '3.3.1':42 'built':31 'cadenc':47 'cf':2,19,49 'cf-convent':48 'cf-unit':1 'climat':16,52 'comput':28 'convent':21,50 'convers':26 'current':39 'forecast':18,53 'handl':8 'librari':6,38 'measur':11 'metadata':20 'pars':25 'python':5 'releas':46 'requir':13 'stabl':45 'support':23 'top':33 'udunit':36,54 'unit':3,9,24,51 'version':40","created_at":"2026-06-07T12:50:40.949496+00:00","updated_at":"2026-06-07T12:50:40.949496+00:00","problems":[{"fix":"Use 'import cf_units' (underscore) in your code.","cause":"The package is installed as cf-units but imported as cf_units (with underscore).","error":"ModuleNotFoundError: No module named 'cf_units'"},{"fix":"Check the unit string for typos and ensure it adheres to UDUNITS definitions. Use cf_units.Unit.is_udunits() to validate.","cause":"The unit string is invalid or not recognized by UDUNITS-2.","error":"cf_units.external.ParserError: Can't parse unit string 'foo'"},{"fix":"Install UDUNITS-2 system-wide (e.g., conda install -c conda-forge udunits2 on Linux, or use conda environment).","cause":"UDUNITS-2 shared library is not installed or not in the library path.","error":"OSError: Could not load UDUNITS library: 'libudunits2.so.0: cannot open shared object file: No such file or directory'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/SciTools/cf-units","github":"https://github.com/SciTools/cf-units","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["analytics","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}