a Python Polars interface to j* and q
Project description
kola
a Python Polars Interface to j* and q
Basic Data Type Map
j*
Deserialization
Atom
| j type | n | size | python type | note |
|---|---|---|---|---|
boolean |
1 | 1 | bool |
|
u8 |
4 | 1 | int |
|
i16 |
5 | 2 | int |
|
i32 |
6 | 4 | int |
|
i64 |
7 | 8 | int |
|
f32 |
8 | 4 | float |
|
f64 |
9 | 8 | float |
|
string |
10 | 1 | str |
|
symbol |
11 | * | str |
|
timestamp |
12 | 8 | datetime |
|
date |
14 | 4 | date |
0001.01.01 - 9999.12.31 |
datetime |
15 | 8 | datetime |
|
duration |
16 | 8 | timedelta |
|
time |
19 | 4 | time |
00:00:00.000 - 23:59:59.999 |
Composite Data Type
| k type | n | size | python type |
|---|---|---|---|
series |
1-15 | - | pl.Series |
list |
90 | - | Tuple |
dictionary |
91 | * | dict |
dataframe |
92 | * | pl.DataFrame |
Serialization
Basic Data Type
| python type | j type | note |
|---|---|---|
bool |
boolean |
|
int |
i64 |
|
float |
f64 |
|
str |
symbol |
|
bytes |
string |
|
date |
date |
0001.01.01 - 9999.12.31 |
datetime |
datetime |
|
timedelta |
duration |
|
time |
time |
00:00:00.000 - 23:59:59.999 |
Dictionary, Series and DataFrame
| python type | j type |
|---|---|
dict |
dict |
pl.Series |
series |
pl.DataFrame |
dataframe |
for dictionary, requires
stringas keys.
q
Deserialization
Atom
| k type | n | size | python type | note |
|---|---|---|---|---|
boolean |
1 | 1 | bool |
|
guid |
2 | 16 | str |
|
byte |
4 | 1 | int |
|
short |
5 | 2 | int |
|
int |
6 | 4 | int |
|
long |
7 | 8 | int |
|
real |
8 | 4 | float |
|
float |
9 | 8 | float |
|
char |
10 | 1 | str |
|
string |
10 | 1 | str |
|
symbol |
11 | * | str |
|
timestamp |
12 | 8 | datetime |
|
month |
13 | 4 | - |
|
date |
14 | 4 | date |
0001.01.01 - 9999.12.31 |
datetime |
15 | 8 | datetime |
|
timespan |
16 | 8 | timedelta |
|
minute |
17 | 4 | time |
00:00 - 23:59 |
second |
18 | 4 | time |
00:00:00 - 23:59:59 |
time |
19 | 4 | time |
00:00:00.000 - 23:59:59.999 |
Composite Data Type
| k type | n | size | python type |
|---|---|---|---|
boolean list |
1 | 1 | pl.Boolean |
guid list |
2 | 16 | pl.List(pl.Binary(16)) |
byte list |
4 | 1 | pl.Uint8 |
short list |
5 | 2 | pl.Int16 |
int list |
6 | 4 | pl.Int32 |
long list |
7 | 8 | pl.Int64 |
real list |
8 | 4 | pl.Float32 |
float list |
9 | 8 | pl.Float64 |
char list |
10 | 1 | pl.Utf8 |
string list |
10 | 1 | pl.Utf8 |
symbol list |
11 | * | pl.Categorical |
timestamp list |
12 | 8 | pl.Datetime |
month list |
13 | 4 | - |
date list |
14 | 4 | pl.Date |
datetime list |
15 | 8 | pl.Datetime |
timespan list |
16 | 8 | pl.Duration |
minute list |
17 | 4 | pl.Time |
second list |
18 | 4 | pl.Time |
time list |
19 | 4 | pl.Time |
table |
98 | * | pl.DataFrame |
dictionary |
99 | * | - |
keyed table |
99 | * | pl.DataFrame |
performance is impacted by converting guid to string, deserialize the uuid to 16 fixed binary list, use .hex() to convert binary to string if required
real/float 0n is mapped to Polars null not NaN
short/int/long 0Nh/i/j, 0Wh/i/j and -0Wh/i/j are mapped to null
df.with_columns([
(pl.col("uuid").apply(lambda u: u.hex()))
])
Serialization
Basic Data Type
| python type | k type | note |
|---|---|---|
bool |
boolean |
|
int |
long |
|
float |
float |
|
str |
symbol |
|
bytes |
string |
|
datetime |
timestamp |
|
date |
date |
0001.01.01 - 9999.12.31 |
datetime |
datetime |
|
timedelta |
timespan |
|
time |
time |
00:00:00.000 - 23:59:59.999 |
Dictionary, Series and DataFrame
| python type | k type |
|---|---|
dict |
dict |
pl.Boolean |
boolean |
pl.List(pl.Binary(16)) |
guid |
pl.Uint8 |
byte |
pl.Int16 |
short |
pl.Int32 |
int |
pl.Int64 |
long |
pl.Float32 |
real |
pl.Float64 |
float |
pl.Utf8 |
char |
pl.Categorical |
symbol |
pl.Datetime |
timestamp |
pl.Date |
date |
pl.Datetime |
datetime |
pl.Duration |
timespan |
pl.Time |
time |
pl.DataFrame |
table |
Limited Support for dictionary as arguments, requires
stringas keys.
Quick Start
Create a Connection
import polars as pl
import kola
# Connect to j*, J and Q both work with j*
conn = kola.J('localhost', 1800)
# Connect to q
conn = kola.Q('localhost', 1800)
# with retries for IO Errors, 1s, 2s, 4s ...
conn = kola.J('localhost', 1800, retries=3)
# with read timeout error, 2s, "Resource temporarily unavailable"
conn = kola.J('localhost', 1800, retries=3, timeout=2)
Connect(Optional)
Automatically connect when querying q process
conn.connect()
Disconnect
Automatically disconnect if any IO error
conn.disconnect()
String Query
conn.sync("select from trade where date=last date")
Functional Query
For functional query, kola supports Python Basic Data Type, pl.Series, pl.DataFrame and Python Dictionary with string keys and Python Basic Data Type and pl.Series values.
from datetime import date, time
conn.sync(
".gw.query",
"table",
{
"date": date(2023, 11, 21),
"syms": pl.Series("", ["sym0", "sym1"], pl.Categorical),
# 09:00
"startTime": time(9),
# 11:30
"endTime": time(11, 30),
},
)
Send DataFrame
# pl_df is a Polars DataFrame
conn.sync("upsert", "table", pl_df)
# pd_df is a Pandas DataFrame, use pl.DateFrame to cast Pandas DataFrame
conn.sync("upsert", "table", pl.DataFrame(pd_df))
Async Query
# pl_df is a Polars DataFrame
conn.asyn("upsert", "table", pl_df)
Subscribe
from kola import QType
conn.sync(".u.sub", pl.Series("", ["table1", "table2"], QType.Symbol), "")
# specify symbol filter
conn.sync(
".u.sub",
pl.Series("", ["table1", "table2"], QType.Symbol),
pl.Series("", ["sym1", "sym2"], QType.Symbol),
)
while true:
# ("upd", "table", pl.Dataframe)
upd = conn.receive()
print(upd)
Generate IPC for q
import polars as pl
from kola import serialize_as_ipc_bytes6
df = pl.DataFrame(
{
"sym": pl.Series("sym", ["a", "b", "c"], pl.Categorical),
"price": [1, 2, 3],
}
)
# without compression
buffer = serialize_as_ipc_bytes6("sync", False, ["upd", "table", df])
# with compression
buffer = serialize_as_ipc_bytes6("sync", True, ["upd", "table", df])
Polars Documentations
Refer to
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kola-2.2.0.tar.gz.
File metadata
- Download URL: kola-2.2.0.tar.gz
- Upload date:
- Size: 66.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7b5b428ad48dda6f901de764e3b82b5e5339e1b5862405caa1e7324793f7446
|
|
| MD5 |
54cba777142845493ce67e4bed66504f
|
|
| BLAKE2b-256 |
67b1ef9a8f61ad213739e1558ddd887bd9254f2234f22b5d340f1207b0030f4a
|
File details
Details for the file kola-2.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2c61e30fe14f88ec02b3c571eb565b5683fc02382deb01962e9d3fad214704f
|
|
| MD5 |
ccd47cdecd27bdf03e6621cb935994ed
|
|
| BLAKE2b-256 |
598293c8e68ceba05463287f532418de41fd7b10d8f684ade4d903be1b551127
|
File details
Details for the file kola-2.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23480f4f1a1113cc4b63b409e3a239a71a802ed57f52e67db4699c32e0eedf2e
|
|
| MD5 |
d6b119c7255552cfb561df5811267940
|
|
| BLAKE2b-256 |
77b8613103af7bf0a1cf04290e39346306b2a8da12ce1f26ec6feec60660de9c
|
File details
Details for the file kola-2.2.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: kola-2.2.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
188d71d19682c1749c956838d8b9f11e8a1501efa0030f917c8fb6f34f779255
|
|
| MD5 |
86e277e7ea0741af5239fea8850fd5de
|
|
| BLAKE2b-256 |
e39cb58c64fcdfd56e46fa915591835ad13433ddfc7ea4ea6962968ff9d7e63c
|
File details
Details for the file kola-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4840ea4aaf0faa5183b1892e3965cfc5705c15c2fa274e62ceb1692277db93a7
|
|
| MD5 |
73a3174109b7cf5600d74d80597577bd
|
|
| BLAKE2b-256 |
210dc3bc004ac1ac4624fe6c45e006510d4a968040af3d4185eecbbdfcf3f566
|
File details
Details for the file kola-2.2.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-2.2.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e7fb7101ca99c6fb5884c82e4ee506a466537515f983cb1678ec26b3ac93551
|
|
| MD5 |
1068a714f7092e1970b02dfcc95849c9
|
|
| BLAKE2b-256 |
8c32225753026501431f33b72a2d403cd14ea7d86ec5eaa9ecba4ffbb16ab494
|
File details
Details for the file kola-2.2.0-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6b8740ae2e21d1608610f318f9aff29ebc3edd9783a861896aca84310e21382
|
|
| MD5 |
f4bdb1bc29071d549166042276779cdf
|
|
| BLAKE2b-256 |
cbc33cec9c09d287eada436535a1a41c67bcd99a0e74b30b2a286303217bc169
|
File details
Details for the file kola-2.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: kola-2.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df1ec306a55aa62a774bdca4a6102c46ea82587fd95fa385cecdf87570b9c0e5
|
|
| MD5 |
4479cb211b2a8baeeb31ff03c2e7da86
|
|
| BLAKE2b-256 |
bec463beb0b1f0874f7b5f474930450f0d5b67227f41a1d86ecd5457c5304244
|
File details
Details for the file kola-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d8f876687a2d4d23134a0d667cafee140c1ab0d00ad3fc24ef56235411568dc
|
|
| MD5 |
101df5e107d6bdabe7e6cf8dd7675f57
|
|
| BLAKE2b-256 |
b7e20542486174771f61da9d9f3b5476c27f365e3bb71a38c769340122d1ff92
|
File details
Details for the file kola-2.2.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-2.2.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2deb4fe2e6ded4369155afe4ea05e99efd46cab95fe322adc2d6a3ca90bd2ed6
|
|
| MD5 |
eca5a6092537d74e0fc7a82e5f4be584
|
|
| BLAKE2b-256 |
4d5db05f0b22ffe8f2d18518965c389a3c4d6d9e37177733e7f9942639f0330c
|
File details
Details for the file kola-2.2.0-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5728a0cc67750abbbb6762c982e1c52563c564edcfcd9c0da4a5ddd08ffe6b3
|
|
| MD5 |
355b47578876c0118044fafa0fd02dd1
|
|
| BLAKE2b-256 |
03cb2036140a658504f6184c66e5887641fc697b46c82481bce6c8dbf6f69065
|
File details
Details for the file kola-2.2.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: kola-2.2.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c365cc4fe0fd64d6d132ad855bafaa8c1f210cc7824b3dd7037b587448be2fa6
|
|
| MD5 |
c8f0049777619b6fc64bb26368b8e089
|
|
| BLAKE2b-256 |
8fad4f64ba23ed3f52673ddf0e6722a4064e9a1bf2a3968ed3d62c6519d0b6a6
|
File details
Details for the file kola-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f35934c287c2292876109272b724d9427b504927a05c964bd870415d6b2fde7
|
|
| MD5 |
91d6cc53daf590b6dd207c8d76357d50
|
|
| BLAKE2b-256 |
8966c2fb97870c1bf5e85f3b302248062083561c1c59bb04aee6e741b8a74c5f
|
File details
Details for the file kola-2.2.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-2.2.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abeef6b0b0256050b6258fee543fcde37b8efbbed2bc124d6a0d2e5ed225d388
|
|
| MD5 |
e10266f9fc42ad8411b3eff2d1b64957
|
|
| BLAKE2b-256 |
8e74e944bdc40f3348ef048ebeede4c6b7aeeeba631543e53104edd0b097eff4
|
File details
Details for the file kola-2.2.0-cp311-cp311-macosx_10_12_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39eeca650f05557d219ba6b82130e191ccd0eb6bda6c229eaa6ca864a13065c1
|
|
| MD5 |
08a2b79ccd1684c794443e6dbcdcfd22
|
|
| BLAKE2b-256 |
94d2fa43e7efd02a1f865cd8bb14179ff3ba894da3eec99d397835982b76e5fe
|
File details
Details for the file kola-2.2.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: kola-2.2.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 2.7 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5119ccea53762e2f772a06fbc314f717f47ff21c73adb6b25fae01872a13df70
|
|
| MD5 |
2d876aadc22c57eac7e5bc935d4f4f37
|
|
| BLAKE2b-256 |
ffb576a2baa060777edd705e2c246ef46bdc4920cfeb9b1f2f922ddf88297748
|
File details
Details for the file kola-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: kola-2.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 5.4 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6fb5e2c6b9c6557085e28c53dfad8af6e951ca0f771e7a0846b9ea1ce79a8efc
|
|
| MD5 |
9de6aa5448165c4dbbb6ec84165cbde3
|
|
| BLAKE2b-256 |
2cf217c4ced1c23f21bfafd9b28c6a219f24f0bf44879ff2a7887030a5be1aed
|