Q & Embedded Q
pykx.Q
pykx.Q()
See Also
Abstract base class for all interfaces between Python and q.
_register
_register(name=None, path=None)
Obtain the definitions from a q/k script.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
Optional[str]
|
Name of the context to be loaded. If |
None
|
path |
Optional[Union[Path, str]]
|
Path to the script to load. If |
None
|
Returns:
Type | Description |
---|---|
str
|
The attribute name for the newly loaded module. |
sql
sql(query, *args)
Wrapper around the KX Insights Core ANSI SQL interface.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
str
|
The SQL query, using KX Insights Core SQL, documented at https://code.kx.com/insights/core/sql.html |
required |
*args |
Any
|
The arguments for the query, which will be interpolated into the query. Each
argument will be converted into a |
()
|
Returns:
Type | Description |
---|---|
'K'
|
The result of the evaluation of |
Avoid interpolating the table into the query when running over IPC.
It's common to interpolate a pykx.Table
object into the query as '$1'
. This works
well when running embedded within the process, but when the Q
instance is an
IPC connection this will result in the entire table being sent over
the connection, which will negatively impact performance. Instead, when running over
IPC, write the name of the table (as defined in the connected q server) directly into
the query.
Examples:
Query a table by name:
q.sql('select * from trades')
Query a pykx.Table
instance by interpolating it in as the first argument:
q.sql('select * from $1', trades) # where `trades` is a `pykx.Table` object
Query a table using interpolated conditions:
from datetime import date
q.sql('select * from trades where date = $1 and price < $2', date(2022, 3, 31), 32.1)
pykx.EmbeddedQ
pykx.EmbeddedQ()
Bases: Q
Interface for q within the current process; can be called to execute q code.
__call__
__call__(query, *args, wait=None, sync=None)
Run code in the q instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query |
Union[str, bytes, wrappers.CharVector]
|
The code to run in the q instance. |
required |
*args |
Any
|
Arguments to the q query. Each argument will be converted into a |
()
|
wait |
Optional[bool]
|
Keyword argument provided solely for conformity with |
None
|
Returns:
Type | Description |
---|---|
wrappers.K
|
The value obtained by evaluating the |
Raises:
Type | Description |
---|---|
LicensedException
|
Attempted to execute q code outside of licensed mode. |
TypeError
|
Too many arguments were provided - q queries cannot have more than 8 parameters. |