KxSystems / pyq

PyQ — Python for kdb+
http://code.kx.com/q/interfaces
Apache License 2.0
190 stars 49 forks source link

adding document for ipc #42

Closed co-dh closed 6 years ago

co-dh commented 6 years ago

Please add some document on how to use ipc. I figured it out by seach hopen in the repo

>>> h = q.hopen('::9900')
>>>  h(q('"1 + 1"'))
K('3')
>>>  h((q('+'), 1, 2)))
K('3')
abalkin commented 6 years ago

cc: @StephenTaylor-Kx

ghost commented 6 years ago

Care to make that a PR?

abalkin commented 6 years ago

I guess this should be a PR for KxSystems/docs.

@co-dh - your example looks good and I think is worthwhile to be included in the docs together with some prose. Note that in Python 3, instead of h(q('"1 + 1"')), you can simply do h(b'1+1'). I would also include a more practical example of inserting data to a table on the server:

>>> h = q.hopen('::9900')
>>> h(b'trades:flip`size`price!()')
k('::')
>>> h(('.q.upsert', 'trades', (10, 50.3)))
k('`trades')
>>> h(('.q.upsert', 'trades', (20, 55.3)))
k('`trades')
>>> h('trades').show()
size price
----------
10   50.3
20   55.3
ghost commented 6 years ago

Looking forward to seeing the PR.

Dump123 commented 6 years ago

I'm looking forward to you both adding documentation. Seems a tough one.

abalkin commented 6 years ago

Closing. Documentation issues should be reported to KxSystems/docs.

dirwin15 commented 5 years ago

Just curious if this had been raised to KxSystems/docs? Can't find any documentation on it.

I am currently seeing that any non-numeric values are all getting passed as symbols across the handle, is the expectation that the function should handle the types when passing parameters? example function below.

h(('runFunc',('tradeData'),('2018.07.26,10055285,ORD_ID')))

sashkab commented 5 years ago

@dirwin15 If you pass argument as Python string, it will be casted into symbol, which is expected. If you would like to pass arguments with a different type, you should either pass their Python equivalent (i.e for date — use datetime.date, for int pass int.

>>> from datetime import date
>>> from pyq import kp, K
>>> K.date(date(2018, 10, 31))
k('2018.10.31')
>>> K.string("string")
k('"string"')
>>> kp("string")
k('"string"')
>>> K.int(123)
k('123i')
>>> K.float(3.14159)
k('3.14159')

So you might want to modify your call in order to receive expected types:

h(('runFunc',('tradeData'),(K.date(date(2018, 7, 26)), K.long(10055285), K.string('ORD_ID'))))

Documentation is available at code.kx.com