Skip to content


Install QPacker and work through some examples of using it to build applications

Install QPacker

cd ~/kx-insights/code/

The installer will ask you for an installation directory.

user@instance:~/kx-insights/code$ sh
Installation Directory [default /home/user]

Set your Git username and email:

git config --global "John Smith"
git config --global ""

This completes the successful installation and configuration of QPacker.

C example

Combine q and C code

Examine the ~/kx-insights/examples/qpacker/cloud-c-sample folder.

From the qp.json file you can see that the entry point of the application that is being built is the hello.q script, which has a dependency on clib. The clib dependency has been included as a subfolder of the application, which has its own qp.json file defining its entrypoint and dependencies.

The share object library is built from the underlying clib. Inspect the chained build dependencies as defined in the qp.json files. qp will

  1. Run make in clib to create
  2. Link functions in hello.q to
  3. Create an application that loads the clib library and executes the entry point hello.q, which contains a call to the hello C function.

Run qp build to build the project. You will see something like

user@instance:~/kx-insights/examples/qpacker/cloud-c-sample$ qp build
INFO  | Build   | Starting build for application [default]
INFO  | Build   | Dependency [so]
INFO  | Main    | (18646-4) Finished.
INFO  | Build   | Dependency [clib]
INFO  | Build   | Docker build --build-arg base=alpine:3.9.6 -f /home/user/kx-insights/examples/qpacker/cloud-c-sample/qpbuild/dep/so/Dockerfile.alpine -t sobuilder /home/user/kx-insights/examples/qpacker/cloud-c-sample/qpbuild/dep/so
INFO  | Build   | docker run --rm -v /home/user/kx-insights/examples/qpacker/cloud-c-sample/clib:/opt/qpacker/ -v /home/user/kx-insights/examples/qpacker/cloud-c-sample:/opt/qpbuildroot -v /home/user/kx-insights/examples/qpacker/cloud-c-sample/qpbuild/dep/so:/opt/so/ -w /opt/qpacker -e CFLAGS=-I/opt/so/kx-c-lib/c/c sobuilder qpmake clib
INFO  | Build   | Creating clib.0.20210226.75658.qpk
INFO  | Main    | (18612-3) Finished.
INFO  | Build   | Dependency [q]
INFO  | Main    | (19011-3) Finished.
INFO  | Build   | App [default]
INFO  | Build   | [docker build -t qlocker /home/user/kx-insights/examples/qpacker/cloud-c-sample/qpbuild/dep/q]
INFO  | Build   | Building with docker...
INFO  | Build   | [docker run --env-file /tmp/qp.19047.env.list --rm -v /home/user/kx-insights/examples/qpacker/cloud-c-sample:/opt/kx/data -v /tmp/qp.19047.qpignore:/opt/kx/qpconfig/.qpignore -v /home/user/.qp.licenses:/opt/kx/lic-out -w /opt/kx/data qlocker]
INFO  | Build   | Write loaders for locked q files
INFO  | Build   | Creating cloud-c-sample.0.20210226.75662.qpk
INFO  | Build   | Creating Dockerfile [Dockerfile.default]
INFO  | Build   | [docker build -f Dockerfile.default .]
INFO  | Main    | (18582-2) Finished.

Notice the application has been packaged as an artifact called cloud-c-sample.qpk in the qpbuild/qpk/ folder. It can be used in other projects.

Next run the application: execute qp run. You will see a call is executed to print a hello message via the clib library.

INFO  | Run     | Target [default]
INFO  | Run     | docker run --rm --env-file /home/user/kx-insights/examples/qpacker/cloud-c-sample/qpbuild/.env  -v /home/user/.config/gcloud/:/root/.config/gcloud:ro -it 4bdafcfbde8e98b5f8d431fc3217a90f10f67e7a1756b86ce0c42d3408d83a5d
INFO: Get kdb+ license from KDB_LICENSE_B64 environment variable
INFO: testing and installing kc.lic
INFO: successful
RUN [q startq.q ]
KDB+ 4.0 Cloud Edition 2021.03.12 Copyright (C) 1993-2021 Kx Systems
l64/ 2()core 3735MB root 3b3147e22fc8 EXPIRE 2022.02.23 KXCE #????????

hello from q test
hello from C!
INFO  | Main    | (20510-2) Finished.

Reset the project with qp clean.

Python example

Build and execute an application with a dependency on embedPy

Examine the ~/kx-insights/examples/qpacker/cloud-py-sample folder.

The qp.json file shows an application:

  • The entrypoint is hello.q: dependency on q is implied by the .q extension.
  • A dependency on embedPy is explicitly stated with the depends object.

Build the project using qp build. It builds a Docker image with the necessary dependencies.

Run the application with qp run default.

Basic tick system

An application that consists of a feed, a tickerplant, a realtime database, a historical database and a gateway

Examine the ~/kx-insights/examples/qpacker/basic-tick-example folder.

The entrypoint for each of the processes can be seen in qp.json. The describes the contents of the package.

Run qp build to build the images, following instructions in the README file.

In this example we see how easy it is to configure and run a multiprocess system using QPacker.

QPacker documentation