KDB-X Python Install
This page explains how to setup Python for KDB-X.
Prerequisites
Before you start, make sure you have:
- Python (we support versions 3.8 - 3.13)
- pip
- Installed KDB-X
Recommended
Supported environments
- Linux (
manylinux_2_17_x86_64,linux-arm64) - macOS (
macosx_10_10_arm) - Windows (
win_amd64)
1. Install KDB-X Python
You can install KDB-X Python from two sources:
-
Ensure you have a recent version of pip:
pip install --upgrade pip -
Then install the latest version with the following command:
pip install --upgrade --pre pykx
-
For Linux x86 and ARM-based architectures, run this command:
conda install kx/label/beta::pykx -
Type
Ywhen prompted to accept the installation.
2. Install a KDB-X license
To use all features, you must have a KDB-X license. If you have already installed KDB-X, the system should automatically detect the license. Otherwise, it prompts you to install one, as detailed below.
Install license in Python
Follow the steps below:
-
Start your Python session:
$ python -
Import the library. When prompted to accept the installation, type
Yor pressEnter:>>> import pykx as kx Thank you for installing KDB-X Python! We have been unable to locate your license for KDB-X Python. Running KDB-X Python in unlicensed mode has reduced functionality. Would you like to install a license? [Y/n]: -
Indicate whether you have access to an existing enabled license or not, type
Nor pressEnterto continue with accessing a new license:Do you have access to an existing license for KDB-X Python that you would like to use? [N/y]: -
Choose whether you wish to install a personal or commercial license, type
Yor pressEnterto choose a personal license:Is the intended use of this software for: [1] Personal use (Default) [2] Commercial use Enter your choice here [1/2]: -
When asked if you would like to apply for a license, type
Yor pressEnter. Select Personal license. -
Complete the form to receive your welcome email.
-
Choose the desired method to activate your license by typing
1,2, or3as appropriate:Select the method you wish to use to activate your license: [1] Download the license file provided in your welcome email and input the file path (Default) [2] Input the activation key (base64 encoded string) provided in your welcome email [3] Proceed with unlicensed mode Enter your choice here [1/2/3]: -
Depending on your choice (1, 2, or 3), complete the installation by following the final step as below:
Personal license
Provide the download location of your license (for example, `~/path/to/kc.lic`).Provide your activation key (base64 encoded string) provided with your welcome email.No further actions needed. -
Validate the correct installation of your license:
>>> kx.q.til(10) pykx.LongVector(pykx.q('0 1 2 3 4 5 6 7 8 9'))
3. Verify KDB-X Python installation
To verify if you successfully installed KDB-X Python on your system, run:
python -c"import pykx as kx;print(kx.__version__)"
This command should display the installed version.
Dependencies
Required and optional KDB-X Python dependencies:
KDB-X Python depends on the following third-party Python packages:
-
pandas>=1.2, <2.0; python_version=='3.8' -
pandas>=1.2, <=2.2.3; python_version>'3.8' -
numpy~=1.22; python_version<'3.11' -
numpy~=1.23, <2.3.0; python_version=='3.11' -
numpy~=1.26, <2.3.0; python_version=='3.12' -
pytz>=2022.1 -
toml~=0.10.2 -
dill>=0.2.0 -
requests>=2.25.0
Note
All are installed automatically by pip when you install KDB-X Python.
Here's a breakdown of how these libraries are used:
-
NumPy: converts data from KDB-X Python objects to NumPy equivalent Array/Recarray style objects; direct calls to
NumPyfunctions such as numpy.max with KDB-X Python objects relies on the NumPy Python API. -
Pandas: converts KDB-X Python data to Pandas Series/DataFrame equivalent objects or to PyArrow data formats. Pandas is used as an intermediary data format.
-
pytz: converts data with timezone information to KDB-X Python objects to ensure that the offsets are accurately applied.
-
toml: for configuration parsing and management, with
.pykx-configas outlined in configuration. -
dill: use in the serialization and deserialization of Python objects when interfacing between KDB-X and Python processes using remote functions or real-time capture functionality.
Optional Python dependencies:
-
pyarrow >=3.0.0, <19.0.0: installpyarrowextra, for examplepip install pykx[pyarrow]. -
find-libpython ~=0.2: installdebugextra, for examplepip install pykx [debug]. -
ast2json ~=0.3: install withdashboardsextra, for examplepip install pykx [dashboards]. -
dill >=0.2: install via pip, withremoteextra, for examplepip install pykx [remote]. -
beautifulsoup4 >=4.10.0: install withhelpextra, for examplepip install pykx [help]. -
markdown2 >=2.5.0: install withhelpextra, for examplepip install pykx [help]. -
psutil >=5.0.0: install via pip, withstreamingextra, for examplepip install pykx [streaming]. -
torch >2.1: install via pip, withtorchextra, for examplepip install pykx[torch].
Here's a breakdown of how KDB-X uses these libraries:
-
PyArrow: converts KDB-X Python objects to and from their PyArrow equivalent table/array objects.
-
find-libpython: provides the
libpython.{so|dll|dylib}file required by Python under q. -
ast2json: required for KX Dashboards Direct integration.
-
psutil: facilitates the stopping and killing of a q process on a specified port allowing for orphaned q processes to be stopped, functionality defined here.
-
torch: required for conversions between
torch.Tensorobjects and their Python equivalents.
Optional non-Python dependencies:
-
libsslfor TLS on IPC connections. -
libpthreadon Linux/MacOS when using thePYKX_THREADINGenvironment variable.
Make KDB-X Python available within KDB-X
To access KDB-X Python from within a KDB-X process, you must install the KDB-X Python under q integration.
After installing KDB-X Python, run the following command:
python -c "import pykx as kx; kx.install_into_QHOME()"
-
If the
$QHOMEenvironment variable is set, the command uses that location. -
If not, it defaults to
~/.kx(if found).
With the above step completed, you can use KDB-X Python from within a KDB-X process by calling \l pykx.q:
q)\l pykx.q
q)np:.pykx.import`numpy
q)np[`:arange][6]`
0 1 2 3 4 5
Next steps
That's it! You can now start using KDB-X Python in your Python projects by visiting our tutorial.