Skip to content

Python API

The Python API for package interactions provides users with the ability to list and load the contents of a package. Users are presented with two interfaces under the kxi.packages namespace, packages and udfs, which allow users 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 following example assumes the following pre-requisites

  1. A user has installed the kxi.packages Python library following the instructions here
  2. A user has followed the quickstart guide presented for the CLI here and as such has a local package qpackage-1.0.0.kxi installed.

  3. Start your Python process, import an initialise the kxi.packages library

$ python
>>> import pykx as kx
>>> import kxi.packages as pakx
>>> pakx.init()
  • 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
variable| 1b
sp      | ``map!(::;{[table;params]
  select from table where x<10
  })
  • Retrieve the UDF as a named function
>>> test_udf = pakx.udfs.load('sp_map', 'qpackage', '1.0.0')
>>> test_udf
{[table;params]
  select from table where x<10
  }