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 https://www.h5py.org/
you open a file, and you can use .keys() to iterate see http://docs.h5py.org/en/latest/high/group.html

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 (http://nexpy.github.io/nexpy/ - NeXpy is a GUI wrapper around ’nexusformat’). Although it is designed to read and manipulate HDF5 files written according to the NeXus standard (https://www.nexusformat.org ), 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 nexusformat.nexus as nx

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

print(f.tree)

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,

Ray