Python API
The Python API for package interactions provides you with the ability to list and load the contents of a package.
There are two interfaces available under the kxi.packages namespace, packages and udfs, which allow you to interact with these entities independently.
Installation
This package can be installed from the KX Nexus using the following command to retrieve the latest version of the functionality:
pip install --extra-index-url https://$KXI_PYPI_USER:$KXI_PYPI_PASS@nexus.dl.kx.com/repository/kxi-pypi-public/simple/ kxi.packages
To retrieve a specific version of the kxi.packages functionality install using the following:
pakx_version=x.y.z
pip install --extra-index-url https://$KXI_PYPI_USER:$KXI_PYPI_PASS@nexus.dl.kx.com/repository/kxi-pypi-public/simple/ kxi.packages==$pakx_version
Quickstart Example
The below example assumes the following pre-requisites:
- You have installed the
kxi.packagesPython library following the instructions here. - You have already followed the quickstart guide presented for the CLI here and have a local package
qpackage-1.0.0.kxiinstalled.
Running the example:
-
Start your Python process
$ python -
Import and initialise the
kxi.packageslibrary>>> import pykx as kx >>> import kxi.packages as pakx >>> pakx.init() -
Set the
KX_PACKAGE_PATHenvironment to the folder containing your packages in this instance>>> pakx.setup_env.set_package_path("test/test-packages") -
List all packages available on the current local installation
>>> pakx.packages.list() name versions 0 qpackage 1.0.0 -
List all UDFs associated with the installed packages
>>> pakx.udfs.search(package_name="qpackage") name function language ... package version 0 sp_map .test.sp.map q ... qpackage 1.0.0 -
Load the package contents
>>> pakx.packages.load('qpackage', '1.0.0') >>> kx.q.test <pykx.ctx.QContext of .test with [variable, sp]> -
Retrieve the UDF as a named function
>>> test_udf = pakx.udfs.load('sp_map', 'qpackage', '1.0.0') >>> test_udf pykx.Lambda(pykx.q(' {[table;params] select from table where x<10 } '))