How to find HDF5 file groups/keys within Python?

h5py, hdf5, hdfstore, pytables, python

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

Problem

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?

Original source