KDB: How to use KDB Function in Python?

1.7k Views Asked by At

I want to execute a KDB function within a Python Script. The KDB function is contained in a separate Q file though. So how can I read in this Q file and then query a function from within that Q file in Python?

2

There are 2 best solutions below

0
R. Laidler On BEST ANSWER

You can use PyQ to call q into Python; a quick start guide is linked here . You can follow the instructions for installation and prompting q according to this link, then load in your script via the method shown in the example below.

Note: You should use the executable pyq rather than python to start.

$ pyq
>>> from pyq import q
>>> q()
q) \l /path/to/script.q
q) \
>>> x = q.f(arg1, arg2)
>>> x.show()

Hope that helps!

0
SanMu On

Depending on what exactly you are trying to accomplish, qPython might be an alternative... It allows you to connect/subscribe to a kdb server from within a python script, run q code, queries, etc...

https://pypi.org/project/qPython/