Registry / data / cdflib

cdflib

JSON →
library1.3.12pypypi✓ verified 85d ago

A Python library for reading and writing NASA Common Data Format (CDF) files. Current version 1.3.10, released 2025-05. Maintained by LASP, supports Python >=3.9. Includes integration with xarray and handles ISTP compliance checks.

pip install cdflib
INSTALL
IMPORT
SIG · CDFLIB
C
cdflib
datapythonv1.3.12
Install
3.6s avg
Import
383ms
Disk
90MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.12 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.380s · 90MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.6s · import 0.386s · 86MB
90MB installed
● package 90MB
Code
Verified usage

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

CDF
from cdflib import CDF
from cdflib.cdf import CDF
CDF is a top-level class in cdflib, not a submodule.
cdf_to_xarray
from cdflib import cdf_to_xarray
from cdflib.xarray import cdf_to_xarray
cdf_to_xarray is a top-level function, not nested in an xarray submodule.
xarray_to_cdf
from cdflib import xarray_to_cdf
from cdflib.xarray import xarray_to_cdf
Same as cdf_to_xarray; both are top-level functions.

Open a CDF file, read global attributes, list variables, and read data for a variable.

from cdflib import CDF cdf_file = CDF('example.cdf') info = cdf_file.globalattsget() print(info) vars = cdf_file.cdf_info() print(vars) data = cdf_file.varget('variable_name') print(data.shape) cdf_file.close()
Debug
Known issues
breakingIn version 1.3.3, the deprecated functions `from_unixtime`, `from_datetime`, `unixtime_to_cdftt2000`, `datetime_to_cdftt2000`, and `datetime64_to_cdftt2000` were fully removed. Use `CDFtime` class or `astropy.time.Time` conversion instead.
fix
Replace `from cdflib.util import from_unixtime` with `CDFtime(utc).tt2000` or use astropy.
affects: >=1.3.3
gotchaWhen using `cdf_to_xarray`, `DELTA_VAR` variables are no longer promoted to coordinates (since 1.3.5). If you rely on them as coordinates, you must manually add them via xarray.
fix
After calling `cdf_to_xarray`, do `ds = ds.assign_coords(delta_var=ds['delta_var'])` if needed.
affects: >=1.3.5
gotchaThe CDF class is not thread-safe. Do not share a CDF object across threads; open separate instances per thread.
fix
Use a new CDF instance per thread (or use read locks).
affects: all
deprecatedAs of version 1.3.10, `CDF.varget()` with `start` and `count` parameters uses 0-based indexing. Some users mistakenly use 1-based indexing from IDL/old CDF standards.
fix
Always use 0-based indices: `cdf.varget('var', start=[0], count=[10])`.
affects: >=1.0.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'cdflib.cdf'
Incorrect import path; CDF is a class in the top-level cdflib package, not a submodule.
fix
Use `from cdflib import CDF` instead.
AttributeError: module 'cdflib' has no attribute 'cdf_to_xarray'
Attempting to import cdf_to_xarray from a wrong location or missing install (e.g., without xarray dependency).
fix
Install xarray (`pip install xarray`) and import using `from cdflib import cdf_to_xarray`.
TypeError: 'numpy.float64' object cannot be interpreted as an integer
Passing a numpy float as start/count index to varget(). varget() expects Python ints.
fix
Cast to int: `start=int(start_val)` or use `varget('var', start=[int(s) for s in start])`.
Upgrade
Version history
1.3.12latest on PyPI · released Jun 1, 2026
Audit
Dependencies
numpyrequiredcore dependency for array operations and CDF data type conversion
astropyoptionaloptional, used for time conversions and FITS compatibility
xarrayoptionaloptional, used for xarray integration (cdf_to_xarray, xarray_to_cdf)
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
cdflib — pip install cdflib · libregistry