Showing results for 
Search instead for 
Did you mean: 

Re: [personal kdb+] KDB embedQ use array from Q in Python

New Contributor III
New Contributor III
Hi Simon,

Assigning q objects to be accessible from functions defined in the Python side of the API requires you to set the objects. In the case you're describing where you want to run 


You would need to run this in the following steps:

// Define the q table
// set the q table converted to a python dictionary to python variable tbl1
// Print from the python side of the interface

With regards to calling the class with the q objects you would either need to do the sets from q side to python as above .i.e

p)teCalc.addObservations(tbl1, tbl2)

or alternatively 'get' the python callable object and assign it to a q callable function and run directly on the q data without a set

// Load the script containing the required class
\l myclass.p
// Retrieve the class
// Access the relevant function
// Run on the relevant q data and return result to q (denoted by trailing `)

It should be noted that when embedPy converts q tables to Python it does so as a list of dictionaries (this is the accurate representation of what a q table is but may be counter intuitive) as such if you need the data to be a pandas dataframe for you use case you may need to do the conversion manually. This is done using 2 functions .ml.tab2df/.ml.df2tab which are both available within the Kx Machine learning toolkit here.

More information on embedPy is available at the below links which outline in detail all of the above

All the best,



Hi Conor - this is a really good explanation - thank you for taking the time. 

This is really great functionality. I'll have a go both ways and see which is faster. My money is on importing the class being the faster one - I will post results when I have them. 

I hope it's ok - I also posted your response to Stack Overflow.

Thanks again.