PyKX integration
PyKX can be integrated into KX Delta Platform version 4.8.1 and above. This allows you to use the full functionality of Python in a q session, as documented in code.kx.com.
Currently all Linux versions supported by the KX Delta Platform support PyKX integration. As part of the KX Delta Platform installation, the necessary files for PyKX are installed into the QHOME directory.
PyKX dependencies
Supported python virtual environments
Delta Platform PyKX integration is not currently compatible with Anaconda.
To use PyKX features within Delta Platform, ensure you have a licensed version of PyKX, that is a k4.lic
or kc.lic
file with the required feature flags enabled for PyKX. For more information, refer to prerequisites.
KX Delta Platform PyKX installation
PyKX is automatically installed into KX Delta Platform QHOME upon upgrade to KX Delta Platform 4.8.1 if all dependencies are met.
You need to specify the alias used for the installation if the server is running multiple versions of python or pip. To do that, add the below to the install config profile.
PYKX_EXECUTABLE=python3
PIP_EXECUTABLE=pip3.11
The installer then checks for these executables in the PATH.
PyKX libraries are not automatically loaded into q sessions on start up. These can be initialized by running the following command:
\l pykx.q
or by executing a python statement within a q session using the p)
notation.
Refer to our troubleshooter for any issues with installing or inititializing PyKX.
Upgrading from KX EmbedPy
The KX Delta Platform installer detects any existing installations of KX EmbedPy. Due to significant syntax differences between PyKX and EmbedPy, the installer does not automatically overwrite EmbedPy with PyKX. Before upgrading, it is important to understand the differences listed in Upgrading from EmbedPy. To upgrade to PyKX from EmbedPy, add the below to the install config profile.
OVERWRITE_EMBEDPY=True
You can also manually install from CLI by following the instructions in installation
PyKX KX Analyst integration
PyKX is fully integrated with the KX Analyst component of the KX Delta Platform. This ensures you are able to recognise python files and migrate variables through the Analyst interface. Further information can be found in KX Analyst.
Python simple code execution
The PyKX integration allows execution of Python code within the KX Analyst IDE or from a script. In both the IDE and scripts prefix Python code with p)
Q scripts can load and execute multiline Python code. Prefix the first line of the code with p)
and indent subsequent lines of Python code according to the usual Python indentation rules.
$ cat test.q
a:1 / q code
p)def add1(arg1): # Python code
return arg1+1 # still Python code
Full scripts of Python code can be executed in q, using the .p
file extension. The script is loaded as usual.
Converting Python data to q
Given obj
, a PyKX object representing Python data, we can get the underlying data as foreign or q.
For example:
q)x:.pykx.eval"(1,2,3)"
q)x
{[f;x].pykx.util.pykx[f;x]}[foreign]enlist
q)x`.
foreign
q)x`
1 2 3
Python dictionaries
Python dictionaries convert to q dictionaries, and vice versa.
References
For more details on using PyKX in q, see: