a Python Polars interface to kdb+/q
Project description
kola
a Python Polars Interface to kdb+/q
Basic Data Type Map
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
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, python
string
as keys and PythonBasic Data Types
andpl.Series
as values.
Quick Start
Create a Connection
import polars as pl
from kola import Q
q = Q('localhost', 1800)
Connect(Optional)
Automatically connect when querying q process
q.connect()
Disconnect
Automatically disconnect if any IO error
q.disconnect()
String Query
q.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
q.sync(
".gw.query",
"trade",
{
"date": date(2023, 11, 21),
"syms": pl.Series("", ["7203.T", "2226.T"], pl.Categorical),
# 09:00
"startTime": time(9),
# 11:30
"endTime": time(11, 30),
},
)
Send DataFrame
# pl_df is a Polars DataFrame
q.sync("upsert", "alpha", pl_df)
# pd_df is a Pandas DataFrame, use pl.DateFrame to cast Pandas DataFrame
q.sync("upsert", "alpha", pl.DataFrame(pd_df))
Async Query
# pl_df is a Polars DataFrame
q.asyn("upsert", "alpha", pl_df)
Polars Documentations
Refer to
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for kola-0.5.1-cp312-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7ca29d5f3ebab3afc4fb3eccf4e8bea44014ea4ba5da7937a6d02ac89693da9 |
|
MD5 | 57c34d26229998620accb9153d567d66 |
|
BLAKE2b-256 | 9e42d55fdca208b2e1d5a3882cc7bad627b1461321d8f9a215af7f7dbac0d186 |
Hashes for kola-0.5.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4033a90ca1e84bfbd9eaa94892607c79fc2fd3b17d06e20e6e9e6393bbcc7f6 |
|
MD5 | 997d1d657d0f9b327a651aa68b869f3f |
|
BLAKE2b-256 | 56f6db8004013848d8305a55706d6dc98411155cace1d4a70be6a30351e30759 |
Hashes for kola-0.5.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74a02d0f9f511b081ddb94f2d0629bcfe6866c3bdd594181d38ee5194ee0731a |
|
MD5 | 8b9e5cfb30ec9a47ee5fa4048446aacb |
|
BLAKE2b-256 | 15f30ec87ed741711645079c3ba67dc3bbedd46e61ff9a158b9410bf307e74a1 |
Hashes for kola-0.5.1-cp311-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d1b62a1875512f08712ce8aab8cdd0ba2c437fe7804b35160f0af41b29152f1 |
|
MD5 | 93573c3c0cccdf246d12cf5d1430c772 |
|
BLAKE2b-256 | 0e222d7347b8966565dbdf2921f1a9f91d0a67e8578538d4a56948ab974db715 |
Hashes for kola-0.5.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4fd88ad91287181447e825d694d21efec1770fc788d7b528e467688b68f6d7b |
|
MD5 | b11a4f3f6273916f47a4c8918847841a |
|
BLAKE2b-256 | 033a2ee59a60798dd0112e151f24e1c003a71997b98b0c3951b54c3bf71cc44e |
Hashes for kola-0.5.1-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 671f2ebc0b7cbbe13ffeb47708d61abfd7ca7d99aeb2acad9848e33727223007 |
|
MD5 | d30635aabe57e3965de879024597c5f8 |
|
BLAKE2b-256 | 31a4b08f8f1e2d4fe4f273587600980c0f3d2075e07601ee4bf597d779239fef |
Hashes for kola-0.5.1-cp310-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 445253be18a80dc9049c9b380f34c59a93b45d49da51422d8a69ff0ae65e3138 |
|
MD5 | 2d6d2c9a24fe0981f6edc8a172c118a3 |
|
BLAKE2b-256 | 85f4796409208fd4e11418ad9be16c8e55f53a7705c43ff6e7cb6fee83f9d64e |
Hashes for kola-0.5.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cb449e2cf16dcab943d21ce73bc2ffdd0a37ef1eab7155a144c7c96ecd1b43a |
|
MD5 | a81388186ab11fc87a6f78338f5065e9 |
|
BLAKE2b-256 | ba190ba9ef5867fd1085ba3ea43dda2459b1bb537c4b96e0c84f7ef639a8a97b |
Hashes for kola-0.5.1-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ff453dd4978b601be82e55c961903aa7266b7db481daeb309d8e5cbfa37ba4f |
|
MD5 | dbf7ddcfdc4f022878bc7adea34431c0 |
|
BLAKE2b-256 | 948ea0f5bf57cb38a4713715c64d1ea918d71b4976d994ff5eb9662b2aadabb9 |
Hashes for kola-0.5.1-cp39-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6104e19b9c171c8a19aa4dbd6dcd006d76c97f938374448c0c35586d3e0b1de |
|
MD5 | 6d3f08c83cbcd9ab08b5b980640c182a |
|
BLAKE2b-256 | 2881205b52ec88d2000e96c4ce52426b6cb5cc0716f10b5089431033ef893b71 |
Hashes for kola-0.5.1-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 267e871d83291b19a1584375259d17816a2ad7155bd01a6e1c1e9baf68d1f2b9 |
|
MD5 | 775a1be147820727a060c9e0360e787d |
|
BLAKE2b-256 | 092f241ca534ff42e41387782803477a551cf90d940b8d54ca5a3f9465fe7505 |
Hashes for kola-0.5.1-cp39-cp39-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bec2073e011aef00cd7f8832648ac589ba18e44fb74c5c7491abb7c2068bffcf |
|
MD5 | be1a83e58dbcfd789c0229d3238053ec |
|
BLAKE2b-256 | b5e8de8b762f247d897e0af1d64d27aeb6889eeb8c7bd9f72ff6b9642d4b1926 |
Hashes for kola-0.5.1-cp38-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9be04f5844e64e3283477cdc87de059c3d5ee7b5370a4b6223701f44639341c4 |
|
MD5 | 45f87b557f00123a95e4412b16bc09c8 |
|
BLAKE2b-256 | c0e954039dcdd1a5536bf65d4ef5018812ca4995c140d7e6cf4f5f39be08230c |
Hashes for kola-0.5.1-cp38-cp38-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff2bf9741b9328b4abd4982b1e1aeb2befb326963e66e25e27080b73b7fff9b1 |
|
MD5 | 2cecd61fe3d2a9bc6f9f58138b1bae24 |
|
BLAKE2b-256 | 7378f9b44ecbd29751bad7bbef51dbbeba5a1486dc602dbb4e56bcc31bf047b4 |
Hashes for kola-0.5.1-cp38-cp38-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f03d9c27921f40112878bf274cba30e734c8e806962968109a833368e20cffc7 |
|
MD5 | 8fefbfab1c8534d1083c5873fc899f4f |
|
BLAKE2b-256 | c99623094787a56c5e220e14a0c8674a3b94e95cf1f5427dacdca9420122306d |