Reading of HDF5 structure


How to get the HDF5 file structure.
I have HDF5 and want to find out hierarchy or structure inside the file.
Like groups inside file, subgroups inside groups … and dataset inside the subgroups.
How to get this ?


h5dump as command line allows to view the content (see the help to see the various options)
Hdf also provides a viewer HDFView


Thanks for suggestion.

But i am writing script using python.
We can not use h5dump in python as it is a utility.
Can you provide some another solution.


well in my case i’m using h5py
you open a file, and you can use .keys() to iterate see

you can also retrieve the attributes


This wouldn’t be too hard using h5py and their walk function, but I don’t think they have an explicit function for listing the file tree. You could try the ‘nexuformat’ package, which I maintain ( - NeXpy is a GUI wrapper around ’nexusformat’). Although it is designed to read and manipulate HDF5 files written according to the NeXus standard ( ), it will read most HDF5 files without problem since it uses h5py underneath. Some HDF5 features are not supported.

After installation (e.g., pip install nexusformat), type:

import as nx

f = nx.load(‘myhdf5file.h5’)


The file items can then be accessed within the Python script as a dictionary, much like h5py - f[‘entry/data’], etc., with their underlying Numpy arrays accessible as f[‘entry/data’].nxvalue. Large arrays are only loaded when you access them this way.

With regards,