HDFql Reference Manual v2.6.0

3.4Python

HDFql can be used in the Python programming language through a wrapper named “HDFql.py”, which is stored in the directory “python” found under the directory “wrapper”. The following short script illustrates how HDFql can be used in this language.

# import HDFql module (make sure it can be found by the Python interpreter)
import HDFql

# display HDFql version in use
print("HDFql version: %s" % HDFql.VERSION)

# create an HDF5 file named "my_file.h5" and use (i.e. open) it
HDFql.execute("CREATE AND USE FILE my_file.h5") 

# create an HDF5 dataset named "my_dataset" of data type int
HDFql.execute("CREATE DATASET my_dataset AS INT VALUES(10)") 

# select (i.e. read) data from dataset "my_dataset" and populate cursor in use with it 
HDFql.execute("SELECT FROM my_dataset") 

# move cursor in use to the first position within the result set 
HDFql.cursor_first() 

# display content of cursor in use
print("Dataset value: %d" % HDFql.cursor_get_int())

Assuming that the script is stored in a file named “example.py”, it can be launched by executing the following command in a terminal:

python example.py

In case the script does not launch, it is most likely that either (1) a Python interpreter is not installed or (2) the HDFql Python wrapper, the HDFql C shared library, and/or the MPI shared library were not found (these are needed to launch the script). To fix the former issue, download and install a Python interpreter from the website https://www.python.org/downloads. To fix the latter issue:

  • On Windows, add the directories where the files “HDFql.py” (i.e. the wrapper) and “HDFql_dll.dll” are located to the environment variables “PYTHONPATH” and “PATH”, respectively, by executing the following command in a terminal:
    set PYTHONPATH=<hdfql_python_wrapper_directory>;%PYTHONPATH%
    set PATH=<hdfql_lib_directory>;%PATH%
  • On Linux, add the directories where the file “HDFql.py” is located to the environment variable “PYTHONPATH” and the directories where the files “libHDFql.so” and (optionally) “libmpi.so” are located to the environment variable “LD_LIBRARY_PATH” by executing the following command in a terminal:
    • With an HDFql non MPI-based distribution:
      export PYTHONPATH=<hdfql_python_wrapper_directory>:$PYTHONPATH
      export LD_LIBRARY_PATH=<hdfql_lib_directory>:$LD_LIBRARY_PATH
    • With an HDFql MPI-based distribution:
      export PYTHONPATH=<hdfql_python_wrapper_directory>:$PYTHONPATH
      export LD_LIBRARY_PATH=<hdfql_lib_directory>:<mpi_lib_directory>:$LD_LIBRARY_PATH
  • On macOS, add the directories where the file “HDFql.py” is located to the environment variable “PYTHONPATH” and the directories where the files “libHDFql.dylib” and (optionally) “libmpi.dylib” are located to the environment variable “DYLD_LIBRARY_PATH”6 by executing the following command in a terminal:
    • With an HDFql non MPI-based distribution:
      export PYTHONPATH=<hdfql_python_wrapper_directory>:$PYTHONPATH
      export DYLD_LIBRARY_PATH=<hdfql_lib_directory>:$DYLD_LIBRARY_PATH
    • With an HDFql MPI-based distribution:
      export PYTHONPATH=<hdfql_python_wrapper_directory>:$PYTHONPATH
      export DYLD_LIBRARY_PATH=<hdfql_lib_directory>:<mpi_lib_directory>:$DYLD_LIBRARY_PATH

Besides these steps, a scientific computing package named NumPy for Python must be installed when working with user-defined variables (please refer to the function hdfql_variable_register for additional information). This package can be found at https://numpy.org/install, along with instructions on how to install and use it.

Notes

  1. Starting with version 10.11 (i.e. El Capitan), Apple introduced a security feature named System Integrity Protection (SIP) that may prevent setting the environment variable “DYLD_LIBRARY_PATH” and, ultimately, launching the program. To overcome this, SIP should be disabled (please refer to https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html for additional information). ↩