PyQ provides seamless integration of Python and Q code. It brings Python and Q interpretors in the same process and allows code written in either of the languages to operate on the same data. In PyQ, Python and Q objects live in the same memory space and share the same data.


First, make sure that PyQ is installed and up-to-date.

Start interactive session:

$ pyq
>>> from pyq import q
>>> from datetime import date

Create an empty table:

>>> = q('([]date:();sym:();qty:())')

Insert sample data:

>>> q.insert('trade', (date(2006,10,6), 'IBM', 200))
>>> q.insert('trade', (date(2006,10,6), 'MSFT', 100))

Display the result:

date       sym  qty
2006.10.06 IBM  200
2006.10.06 MSFT 100

Define a parameterized query:

>>> query = q('{[s;d]select from trade where sym=s,date=d}')

Run a query:

>>> query('IBM', date(2006,10,6))

Pretty print the result:

>>> query('IBM', date(2006,10,6)).show()
date       sym qty
2006.10.06 IBM 200

Indices and tables