Loading KDB-X Modules
This page documents how to load KDB-X q modules into Python with kx.use, the QModule objects returned, and the SearchPath used to locate them.
pykx.module
Loading KDB-X modules.
When pykx.use is called KDB-X will attempt to load a module with the given name.
QModule
QModule(name, qns, qkeys, qdict)
A loaded KDB-X q Module.
Example loading the pq module and the pq.t submodule within KDB-X Python.
>>> import pykx as kx
>>> pq = kx.use('kx.pq')
>>> pq
pykx.QModule(pykx.q('
pq| pykx.Lambda
op| pykx.Lambda
rd| pykx.Lambda
'))
>>> pq.t = kx.use('kx.pq.t')
>>> pq
pykx.QModule(pykx.q('
pq| pykx.Lambda
op| pykx.Lambda
rd| pykx.Lambda
t | pykx.QModule(pykx.q('
mkT| pykx.Lambda
mkP| pykx.Lambda
tt | pykx.Lambda
mt | pykx.Lambda
fv | pykx.Lambda
'))
'))
use
use(module_name, export_argument=None)
Function for loading KDB-X modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_name |
str
|
The name of the KDB-X module to load as a string. |
required |
export_argument |
object
|
Optional argument to pass to the module export function. Default None. |
None
|
Returns:
| Type | Description |
|---|---|
QModule
|
A loaded QModule instance. |
Examples:
Example loading the pq module and the pq.t submodule within KDB-X Python.
>>> import pykx as kx
>>> from pathlib import Path
>>> pq = kx.module.use('kx.pq')
>>> pq.t = kx.module.use('kx.pq.t')
>>> tab = pq.pq(Path('../types.parquet'))
>>> tab
pykx.VirtualTable(pykx.q('`T!`f`m`t!(k){[f;t;c;b;a;v]g:$[s:-1h=@b;0;#b];(bf;b1):$[g;df[t;0,0b;b];(::;()..'))
>>> tab.select()
pykx.Table(pykx.q('
col0 col1 col2
---------------
1 1 "asd"
1 2 "bsd"
0 3 "csd"
1 4 "asd"
0 5 "bsd"
0 6 "csd"
1 7 "asd"
0 8 "bsd"
0 9 "csd"
'))
SearchPath
SearchPath(
entry=None, *, add=False, remove=False, prepend=False, strict=False, allow_duplicates=False
)
Manage the module SearchPath.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry |
Optional[str]
|
The path string to add or remove. If omitted, the current SearchPath is returned. |
None
|
add |
bool
|
If True, add the entry to the SearchPath. Default False. |
False
|
remove |
bool
|
If True, remove all occurrences of the entry from the SearchPath. Default False. |
False
|
prepend |
bool
|
If True, insert the entry at the front rather than the end. Default False. |
False
|
strict |
bool
|
If True, raise a ValueError when attempting to remove an entry that is not present. Default False. |
False
|
allow_duplicates |
bool
|
If True, allow the same entry to appear more than once in the SearchPath. Default False. |
False
|
Examples:
Retrieve the current SearchPath:
>>> kx.module.SearchPath()
[]
Append and prepend entries:
>>> kx.module.SearchPath("/home/user/.kx/mod", add=True)
>>> kx.module.SearchPath("/home/user/mod", add=True)
>>> kx.module.SearchPath("/other/mod", add=True, prepend=True)
>>> kx.module.SearchPath()
['/other/mod', '/home/user/.kx/mod', '/home/user/mod']
Remove an entry:
>>> kx.module.SearchPath("/other/mod", remove=True)
>>> kx.module.SearchPath()
['/home/user/.kx/mod', '/home/user/mod']