Use of hdf5 library in Python with ctypes
<p>I would like to use <code>hdf5</code> library directly from <code>Python</code> with <code>ctypes</code>. I know that <code>h5py</code> and <code>PyTables</code> do the job perfectly. The reason I want to do this: I need to work with <code>hdf5</code> files with a <code>Python</code> interpreter where I can not install any package.</p>

<p>I am looking for an example that creates a file and write a list of doubles. </p>

<p>So far, I have written</p>

<pre><code>from ctypes import *
hdf5Lib=r'/usr/local/lib/libhdf5.dylib'
lib=cdll.LoadLibrary(hdf5Lib)
major = c_uint()
minor = c_uint()
release = c_uint()
lib.H5get_libversion(byref(major), byref(minor), byref(release))
H5Fopen=lib.H5Fopen
...
</code></pre>

<p>I don't know how to call H5Fopen. Should I use <code>H5Fopen.argtypes</code>? Any advice is welcome is to open the hdf5 file, create a dataset that of doubles, write the data and close the file.</p>

<p>You shouldn't need to define argtypes as <code>H5Fopen</code> doesn't appear to take arguments. Just call like a regular function:</p>

<pre><code>herr_t = lib.H5Fopen()
</code></pre>

<p><strong>Edit:</strong> for the version with args try:</p>

<pre><code>lib.H5Fopen.restype = c_int
lib.H5Fopen.argtypes = (c_char_p, c_uint, c_int)
herr_t = lib.H5open(name, flags, fapl_id)
</code></pre>

<p>Just pass a string for the name and ints for the other two.</p>

python ctypes hdf5