Search code examples
pythonhdf5pytablesh5pyhdfstore

How to find HDF5 file groups/keys within Python?


Lets's say someone gave me a random HDF5 document. I would like to write a function that checks what are the groups/"keys" used.

Take pandas HDFStore(). For many methods which retrieve HDF5 data, one requires to know the key, e.g. pandas.HDFStore.get()

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.HDFStore.get.html

What is the most efficient way to check the identity of keys if not a priori known?


Solution

  • You probably want to use the h5py package:

    import h5py
    
    with h5py.File("myfile.h5") as f:
        print(f.keys())  # works like a dict