1"""Create an HDF5 file in memory and retrieve the raw bytes
2
3This could be used, for instance, in a server producing small HDF5
4files on demand.
5"""
6import io
7import h5py
8
9bio = io.BytesIO()
10with h5py.File(bio, 'w') as f:
11    f['dataset'] = range(10)
12
13data = bio.getvalue() # data is a regular Python bytes object.
14print("Total size:", len(data))
15print("First bytes:", data[:10])
16