hdf5-rust
Library Featured
Thread-safe Rust bindings for the HDF5 library.
- Downloads
- 253,180
- Dependents
- 70
- Stars
- 85
- Forks
- 29
- Contributors
- 30
- Commits
- 2,045
- Latest release
- 0.15.1 ·
About
HDF5 for Rust.
The hdf5-metno crate (also known under the pre-fork name of hdf5) provides thread-safe Rust bindings and
high-level wrappers for the HDF5 library API. Some of the features include:
- Thread-safety with non-threadsafe libhdf5 builds guaranteed via reentrant mutexes.
- Native representation of most HDF5 types, including variable-length strings and arrays.
- Derive-macro for automatic mapping of user structs and enums to HDF5 types.
- Multi-dimensional array reading/writing interface via
ndarray.
Direct low-level bindings are also available and are provided in the hdf5-sys crate.
Requires HDF5 library of version 1.8.4 or later.
Fork
This is a fork of https://github.com/aldanor/hdf5-rust used for publishing newer versions of the crate. This includes a change in the crate name to allow publishing on crates.io. For backwards compatibility consider using the following in your Cargo.toml:
hdf5 = { package = "hdf5-metno", version = "0.10.0" }
Read the full README
Example
#[cfg(feature = "blosc")]
use hdf5::filters::blosc_set_nthreads;
use hdf5::{File, H5Type, Result};
use ndarray::{arr2, s};
#[derive(H5Type, Clone, PartialEq, Debug)] // register with HDF5
#[repr(u8)]
pub enum Color {
R = 1,
G = 2,
B = 3,
}
#[derive(H5Type, Clone, PartialEq, Debug)] // register with HDF5
#[repr(C)]
pub struct Pixel {
x: i64,
y: i64,
color: Color,
}
impl Pixel {
pub fn new(x: i64, y: i64, color: Color) -> Self {
Self { x, y, color }
}
}
fn write_hdf5() -> Result<()> {
use Color::*;
let file = File::create("pixels.h5")?; // open for writing
let group = file.create_group("dir")?; // create a group
#[cfg(feature = "blosc")]
blosc_set_nthreads(2); // set number of blosc threads
let builder = group.new_dataset_builder();
#[cfg(feature = "blosc")]
let builder = builder.blosc_zstd(9, true); // zstd + shuffle
let ds = builder
.with_data(&arr2(&[
// write a 2-D array of data
[Pixel::new(1, 2, R), Pixel::new(2, 3, B)],
[Pixel::new(3, 4, G), Pixel::new(4, 5, R)],
[Pixel::new(5, 6, B), Pixel::new(6, 7, G)],
]))
// finalize and write the dataset
.create("pixels")?;
// create an attr with fixed shape but don't write the data
let attr = ds.new_attr::<Color>().shape([3]).create("colors")?;
// write the attr data
attr.write(&[R, G, B])?;
Ok(())
}
fn read_hdf5() -> Result<()> {
use Color::*;
let file = File::open("pixels.h5")?; // open for reading
let ds = file.dataset("dir/pixels")?; // open the dataset
assert_eq!(
// read a slice of the 2-D dataset and verify it
ds.read_slice::<Pixel, _, _>(s![1.., ..])?,
arr2(&[
[Pixel::new(3, 4, G), Pixel::new(4, 5, R)],
[Pixel::new(5, 6, B), Pixel::new(6, 7, G)],
])
);
let attr = ds.attr("colors")?; // open the attribute
assert_eq!(attr.read_1d::<Color>()?.as_slice().unwrap(), &[R, G, B]);
Ok(())
}
fn main() -> Result<()> {
write_hdf5()?;
read_hdf5()?;
Ok(())
}
You can find this example as well as other example projects in the example directory.
Compatibility
Platforms
hdf5 crate is known to run on these platforms: Linux, macOS, Windows (tested on:
Ubuntu 16.04, 18.04, and 20.04; Windows Server 2019 with both MSVC and GNU
toolchains; macOS Catalina).
Rust
hdf5 crate is tested continuously for all three official release channels, and
requires a reasonably recent Rust compiler (e.g. of version 1.80 or newer).
HDF5
Required HDF5 version is 1.8.4 or newer. The library doesn't have to be built with threadsafe option enabled in order to make the user code threadsafe.
Various HDF5 installation options are supported and tested: via package managers like homebrew and apt; system-wide installations on Windows; conda installations from both the official channels and conda-forge. On Linux and macOS, both OpenMPI and MPICH parallel builds are supported and tested.
The HDF5 C library can also be built from source and linked in statically by
enabling hdf5-sys/static feature (CMake required).
Building
HDF5 version
Build scripts for both hdf5-sys and hdf5 crates check the actual version of the
HDF5 library that they are being linked against, and some functionality may be conditionally
enabled or disabled at compile time. While this allows supporting multiple versions of HDF5
in a single codebase, this is something the library user should be aware of in case they
choose to use the low level FFI bindings.
Environment variables
If HDF5_DIR is set, the build script will look there (and nowhere else) for HDF5
headers and binaries (i.e., it will look for headers under $HDF5_DIR/include).
If HDF5_VERSION is set, the build script will check that the library version matches
the specified version string; in some cases it may also be used by the build script to
help locating the library (e.g. when both 1.8 and 1.10 are installed via Homebrew on macOS).
conda
It is possible to link against hdf5 conda package; a few notes and tips:
- Point
HDF5_DIRto conda environment root. - The build script knows about conda environment layout specifics and will adjust
paths accordingly (e.g.
Librarysubfolder in Windows environments). - On Windows, environment's
binfolder must be inPATH(or the environment can be activated prior to running cargo). - On Linux / macOS, it is recommended to set rpath, e.g. by setting
RUSTFLAGS="-C link-args=-Wl,-rpath,$HDF5_DIR/lib". - For old versions of HDF5 conda packages on macOS, it may also be necessary to set
DYLD_FALLBACK_LIBRARY_PATH="$HDF5_DIR/lib".
Linux
The build script will attempt to use pkg-config first, which will likely work out without further tweaking for the more recent versions of HDF5. The build script will then also look in some standard locations where HDF5 can be found after being apt-installed on Ubuntu.
macOS
On macOS, the build script will attempt to locate HDF5 via Homebrew if it's available.
If both 1.8 and 1.10 are installed and available, the default (1.10) will be used
unless HDF5_VERSION is set.
Windows
hdf5 crate fully supports MSVC toolchain, which allows using the
official releases of
HDF5 and is generally the recommended way to go. That being said, previous experiments have
shown that all tests pass on the gnu target as well, one just needs to be careful with
building the HDF5 binary itself and configuring the build environment.
Few things to note when building on Windows:
hdf5.dllshould be available in the search path at build time and runtime (bothgnuandmsvc). This normally requires adding thebinfolder of HDF5 installation toPATH. If using an official HDF5 release (msvconly), this will typically be done automatically by the installer.msvc: installed Visual Studio version should match the HDF5 binary (2013 or 2015). Note that it is not necessary to runvcvarsscripts; Rust build system will take care of that.- When building for either target, make sure that there are no conflicts in the search path (e.g., some binaries from MinGW toolchain may shadow MSVS executables or vice versa).
- The recommended platform for
gnutarget is TDM distribution of MinGW-GCC as it contains bintools for both 32-bit and 64-bit. - The recommended setup for
msvctarget is VS2015 x64 since that matches CI build configuration, however VS2013 and x86 should work equally well.
License
hdf5 crate is primarily distributed under the terms of both the MIT license and the
Apache License (Version 2.0). See LICENSE-APACHE and
LICENSE-MIT for details.
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- Required
- Binds native code: hdf5-metno-sys, blosc-src (feature blosc), lzf-sys (feature lzf), mpi-sys (feature mpio), zfp-sys (feature zfp)
- Python bindings
- No Python binding crate found
- License
- Apache-2.0 OR MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Thread-safe Rust bindings for the HDF5 library. |
253,180 downloads over 30 days | 70 | 85 | 0.15.1 | GPU support unknown | Binds native code: hdf5-metno-sys, blosc-src (feature blosc), lzf-sys (feature lzf), mpi-sys (feature mpio), zfp-sys (feature zfp) | Apache-2.0 OR MIT |
|
zarrs Featured
A library for the Zarr storage format for multidimensional arrays and metadata |
75,052 downloads over 30 days | 51 | 285 | 0.23.14 | GPU support unknown | Binds native code: blosc-src (feature blosc), gdeflate-sys (feature gdeflate), zfp-sys (feature zfp), zstd-sys (feature zstd) | Apache-2.0 OR MIT |
|
hdf5-pure Featured
Pure-Rust HDF5 library: read, write, and edit files in place (WASM-compatible, no C dependencies) |
64,279 downloads over 30 days | 18 | 42 | 0.47.0 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
netcdf Featured
High-level NetCDF bindings for Rust |
22,481 downloads over 30 days | 29 | 106 | 0.12.1 | GPU support unknown | Binds native code: netcdf-sys, hdf5-metno-sys, libz-sys, mpi-sys (feature mpi) | Apache-2.0 OR MIT |
|
vortex Listed
An extensible, state-of-the-art framework for columnar compression, and the fastest FOSS columnar file format. Formerly at @spiraldb, now an Incubation Stage project at LFAI&Data, part of the Linux Foundation. |
98,129 downloads over 30 days | 32 | 3,310 | 0.93.0 | GPU support unknown | Binds native code: zstd-sys | Apache-2.0 |
|
hdf5-pure-rs New
Pure Rust implementation of the HDF5 file format |
801 downloads over 30 days | 5 | 5 | 0.3.10 | GPU support unknown | No native code found | BSD-3-Clause |
|
Model conversion and quantization with no Python: reads SafeTensors, GGUF, TCF and PyTorch state dicts, writes SafeTensors, GGUF and TCF, and quantizes to Q2_K through Q8_0 and IQ4 formats, including Q4_K_M mixes. GPTQ, AWQ, NF4, FP8, EXL2 and ONNX input are not implemented. Python bindings |
23 downloads over 30 days | Not applicable | 0 | 0.2.1 | GPU support unknown | No native code found | Apache-2.0 |
Why FeaturedIt passes every Featured gate.
What it meets
- It has 49 active dependents and 39 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days.
- Active dependents are at 100% of their peak. Featured needs at least 50%.
- Docs are present. The release commit or a manifest ties the crate to the repository.
- No vulnerability advisory stays unpatched past the grace window. At least one version is neither a prerelease nor 0.0.x.
- The last activity is on 3 Nov 2026, 6 days ago. The rules expect an update within 1200 days. Dormancy rule
Exact rules: Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.15.1 base 300, doubled for 253180 downloads per month, doubled for 49 active users: E = 1200 daysdormancy: last activity 2026-11-03, 6 days ago, E = 1200: activefeatured: featured: active_users 49, new_adopters 39, former_glory 1
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption49 active dependents, 39 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 49 | crates.io database dump | Yes | |
| New dependents (365 days) | 39 | crates.io database dump | Yes | |
| Peak active dependents | 49.3333 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 6 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-11-03 | GitHub repository | Yes | |
| Latest release | 2026-10-26 | crates.io database dump | Yes | |
| First release | 2024-08-08 | crates.io database dump | Yes | |
| Latest version | 0.15.1 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 130 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 35 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution20 releases, 253,180 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 20 | crates.io database dump | Yes | |
| Downloads over 30 days | 253180 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository85 stars, 29 forks, 30 contributors, 2,045 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 85 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 29 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 30 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 2045 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Apache-2.0 OR MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | Binds native code: hdf5-metno-sys, blosc-src (feature blosc), lzf-sys (feature lzf), mpi-sys (feature mpio), zfp-sys (feature zfp) | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 70 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.