Probably we can check if the .mat file is supported by looking at the starting bytes of the file, see: ~~~ def is_hdf5(file_path): with open(file_path, 'rb') as f: signature = f.read(8) return signature == b'\x89HDF\r\n\x1a\n' ~~~ Based on https://docs.hdfgroup.org/hdf5/v1_14/_f_m_t3.html#Superblock, it seems that this indeed a way to quickly check if a given file is hdf5 .