Skip to content
/ hdf5 Public

Modern Pure Go implementation of the HDF5 file format

License

scigolib/hdf5

HDF5 Go Library

Pure Go implementation of the HDF5 file format - No CGo required

Go Version Go Report Card CI Coverage License Status GoDoc

A modern, pure Go library for reading HDF5 files without CGo dependencies. ~98% production-ready for common scientific datasets!


✨ Features

  • Pure Go - No CGo, no C dependencies, cross-platform
  • Modern Design - Built with Go 1.25+ best practices
  • HDF5 Compatibility - Supports superblock versions 0, 2, 3
  • Full Dataset Reading - Compact, contiguous, chunked layouts with GZIP
  • Rich Datatypes - Integers, floats, strings (fixed/variable), compounds
  • Memory Efficient - Buffer pooling and smart memory management
  • Production Ready - ~98% complete for common scientific HDF5 files
  • 📖 Read-Only - Write support planned for future versions

🚀 Quick Start

Installation

go get github.com/scigolib/hdf5

Basic Usage

package main

import (
    "fmt"
    "log"
    "github.com/scigolib/hdf5"
)

func main() {
    // Open HDF5 file
    file, err := hdf5.Open("data.h5")
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()

    // Walk through file structure
    file.Walk(func(path string, obj hdf5.Object) {
        switch v := obj.(type) {
        case *hdf5.Group:
            fmt.Printf("📁 %s (%d children)\n", path, len(v.Children()))
        case *hdf5.Dataset:
            fmt.Printf("📊 %s\n", path)
        }
    })
}

Output:

📁 / (2 children)
📊 /temperature
📁 /experiments/ (3 children)

More examples →


📚 Documentation

Getting Started

Reference

Advanced


🎯 Current Status

Version: v0.10.0-beta (83% complete - 5/6 tasks) 🚀

Production Readiness: ~98% for reading common HDF5 scientific datasets! 🎉

✅ Fully Implemented

  • File Structure:

    • Superblock parsing (v0, v2, v3)
    • Object headers v1 (legacy HDF5 < 1.8) with continuations ✨ NEW
    • Object headers v2 (modern HDF5 >= 1.8) with continuations
    • Groups (traditional symbol tables + modern object headers)
    • B-trees (leaf + non-leaf nodes for large files)
    • Local heaps (string storage)
    • Global Heap (variable-length data)
    • Fractal heap (direct blocks for dense attributes) ✨ NEW
  • Dataset Reading:

    • Compact layout (data in object header)
    • Contiguous layout (sequential storage)
    • Chunked layout with B-tree indexing
    • GZIP/Deflate compression
    • Filter pipeline for compressed data ✨ NEW
  • Datatypes:

    • Fixed-point (int32, int64)
    • Floating-point (float32, float64)
    • Fixed-length strings (null/space/null-padded)
    • Variable-length strings (via Global Heap)
    • Compound types (struct-like with nested members)
  • Attributes:

    • Compact attributes (in object header) ✨ NEW
    • Dense attributes (fractal heap foundation) ✨ NEW
    • Attribute reading for groups and datasets ✨ NEW
    • Full attribute API (Group.Attributes(), Dataset.Attributes()) ✨ NEW
  • Navigation: Full file tree traversal via Walk()

  • Code Quality:

    • Test coverage: 76.3% (target: >70%) ✅
    • Lint issues: 0 (34+ linters) ✅
    • TODO items: 0 (all resolved) ✅
    • 57 reference HDF5 test files ✅

⚠️ Partial Support

  • Dense Attributes: Infrastructure ready, B-tree v2 iteration deferred to v0.11.0 (<10% of files affected)

❌ Not Implemented

  • Other compression (SZIP, LZF, BZIP2) - GZIP covers 95%+ of files
  • Advanced datatypes (arrays, enums, references, opaque, time)
  • Virtual datasets / external files
  • Soft links (deferred to v0.11.0)
  • Write support (planned for v0.11.0+)

🔧 Development

Requirements

  • Go 1.25 or later
  • No external dependencies for the library
  • Testing requires: Python 3 with h5py (for generating test files)

Building

# Clone repository
git clone https://github.com/scigolib/hdf5.git
cd hdf5

# Run tests
go test ./...

# Build examples
go build ./examples/...

# Build tools
go build ./cmd/...

Testing

# Run all tests
go test ./...

# Run with race detector
go test -race ./...

# Run with coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

🤝 Contributing

Contributions are welcome! This is an early-stage project and we'd love your help.

Before contributing:

  1. Read CONTRIBUTING.md - Git workflow and development guidelines
  2. Check open issues
  3. Review the Architecture Overview

Ways to contribute:

  • 🐛 Report bugs
  • 💡 Suggest features
  • 📝 Improve documentation
  • 🔧 Submit pull requests
  • ⭐ Star the project

🗺️ Comparison with Other Libraries

Feature This Library gonum/hdf5 go-hdf5/hdf5
Pure Go ✅ Yes ❌ CGo wrapper ✅ Yes
Reading ✅ Partial ✅ Full ❌ Limited
Writing 📋 Planned ✅ Full ❌ No
HDF5 1.8+ ✅ Yes ⚠️ Limited ❌ No
Maintained ✅ Active ⚠️ Slow ❌ Inactive
Thread-safe 📋 Planned ⚠️ Conditional ❌ No

📖 HDF5 Resources


📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • The HDF Group for the HDF5 format specification
  • gonum/hdf5 for inspiration
  • All contributors to this project

Special Thanks

Professor Ancha Baranova - This project would not have been possible without her invaluable help and support. Her assistance was crucial in bringing this library to life.


📞 Support


Status: Beta - ~98% production-ready for reading Version: 0.10.0-beta (83% complete - 5/6 tasks) Last Updated: 2025-10-29


Built with ❤️ by the HDF5 Go community