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
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, python
stringas keys and PythonBasic Data Typesandpl.Seriesas values.
Quick Start
Create a Connection
import polars as pl
import kola
q = kola.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",
"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
q.sync("upsert", "table", pl_df)
# pd_df is a Pandas DataFrame, use pl.DateFrame to cast Pandas DataFrame
q.sync("upsert", "table", pl.DataFrame(pd_df))
Async Query
# pl_df is a Polars DataFrame
q.asyn("upsert", "table", pl_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 Distributions
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-1.2.1-cp312-none-win_amd64.whl.
File metadata
- Download URL: kola-1.2.1-cp312-none-win_amd64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39d243d3fa1e9f665aab79a8ecf9155e54a502741e8a5a925b880edfffa58154
|
|
| MD5 |
f33f21499026c251268c08ca5e65ae28
|
|
| BLAKE2b-256 |
74545903466c9d6d23e5ec603c9b39875ac0eebd6d863d645c14773bb19fd710
|
File details
Details for the file kola-1.2.1-cp312-cp312-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: kola-1.2.1-cp312-cp312-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d17b39aac07ee772bff806536b9bf1e04e4ba423c915c9b6683a4cdecd6e4268
|
|
| MD5 |
91b6b57dccb7940ce2b67a12249b8ec8
|
|
| BLAKE2b-256 |
66828333fc292a21b1f520df075363d8d34431ea20c592ebc2b877dae89ff13b
|
File details
Details for the file kola-1.2.1-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-1.2.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06bf5ff950b953d08f7d7af94639c383bf013a2e85e8fb3074463d6da9a00565
|
|
| MD5 |
ade9390a65d57bbaed625f2f05ed28c3
|
|
| BLAKE2b-256 |
13a3a3483afc2f80b84135eb7b9676eb79fbc5d11892f05134894a507a6fa0c2
|
File details
Details for the file kola-1.2.1-cp311-none-win_amd64.whl.
File metadata
- Download URL: kola-1.2.1-cp311-none-win_amd64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d948beb9809b3d84320c0f3ec37c4d91a647ca2a6a1b9272fb78d06cacb9ee73
|
|
| MD5 |
1194e8520a46347d605a9a0fd4cc1181
|
|
| BLAKE2b-256 |
1acac7de334b102562cde82b2216cfd8243db26e85a66cb6dcc81def52de39b0
|
File details
Details for the file kola-1.2.1-cp311-cp311-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: kola-1.2.1-cp311-cp311-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.3 MB
- Tags: CPython 3.11, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aae847e1c49b0e9badfb07610c849527a5778c5f11c769ae356af5cb80e937cd
|
|
| MD5 |
1efa0f37964d52fb84241291c560082a
|
|
| BLAKE2b-256 |
f1e109cb718953d9d6fd7388ef71393e1f7d8eba599aa03c5c582fc581a6d984
|
File details
Details for the file kola-1.2.1-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-1.2.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcf14a43bd347e5fb4e8d8cf8d9eccfb990c7278e712e4e315be65724e3fb76b
|
|
| MD5 |
b18efb629924cf32818ff3dea0668759
|
|
| BLAKE2b-256 |
63cbcd4c6ef0a425585186cdf58927051b8fb9b274a015bcc7b2a03abfdfc9bc
|
File details
Details for the file kola-1.2.1-cp310-none-win_amd64.whl.
File metadata
- Download URL: kola-1.2.1-cp310-none-win_amd64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21178c78977ce838d93dd1dd28c5f79cbd95a815df2ffb104b0b819cd15ee2db
|
|
| MD5 |
e0f3ab72566b09b45ba8606042ba21d1
|
|
| BLAKE2b-256 |
44f7e6124bc9a85786a861970c3c47ac3658d58b05a02a7786e195d1ba2cd3b6
|
File details
Details for the file kola-1.2.1-cp310-cp310-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: kola-1.2.1-cp310-cp310-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe3966ef8e32e00053f24da4629a0c4012ee8fe8714ee49e7049b45f4d1f46db
|
|
| MD5 |
64f4ada8b99a79b6003ffed25094594c
|
|
| BLAKE2b-256 |
01a4dd47f83e8b45192d3b6583c5067455e2d4ce33af829f5d14c213c1f22c10
|
File details
Details for the file kola-1.2.1-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-1.2.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcaff667ba097f4b25b5000c04351e1344197578dad60bde69d436792f3bbd36
|
|
| MD5 |
94e0c7d38b9af92c66260e94ed5c583d
|
|
| BLAKE2b-256 |
4bb6a04776dace0214593309bd8c007b80f830a1dd688c79cc0d2cd07e3684ce
|
File details
Details for the file kola-1.2.1-cp39-none-win_amd64.whl.
File metadata
- Download URL: kola-1.2.1-cp39-none-win_amd64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f32a178e8c2f7302cf26fc72276a702c3d96b64261259d3f925c9edef1c1ec57
|
|
| MD5 |
7a526d23405cd11e9e608b621dcb0ffb
|
|
| BLAKE2b-256 |
454f4aa4241cdbbf47458197513635475fa5318c4a6159a22d4ba018cab05039
|
File details
Details for the file kola-1.2.1-cp39-cp39-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: kola-1.2.1-cp39-cp39-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.4 MB
- Tags: CPython 3.9, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d5c27d30782fd4163d2c2ee8511f0395ecc7d8452192ff1957593b449a529e0
|
|
| MD5 |
9da7464e13c6c31523e0bb302d07ac73
|
|
| BLAKE2b-256 |
e92b329a62ca3daf4352b152bb501f413ffa603e8b02187a77f2461301c86fe9
|
File details
Details for the file kola-1.2.1-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-1.2.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04592c4350c56f2f46644973a70fa30414452ccca267274862b2498d640c515e
|
|
| MD5 |
4f00de9ca1abb3049eb7303784dfe69d
|
|
| BLAKE2b-256 |
0f495f1df97b337ea0262fb815b737d41f42282c1e9c0603f63761f5359fdddf
|
File details
Details for the file kola-1.2.1-cp38-none-win_amd64.whl.
File metadata
- Download URL: kola-1.2.1-cp38-none-win_amd64.whl
- Upload date:
- Size: 4.1 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fde4f97029c3642aea5153617fe6b5fb38b323b37552d006bb0177bcb01a2d9
|
|
| MD5 |
21d31051591b721667842cbc4851f068
|
|
| BLAKE2b-256 |
636cc4b930905cc9b8805c11e6b988d3e380620b7f3fd788168cce40959e3d25
|
File details
Details for the file kola-1.2.1-cp38-cp38-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: kola-1.2.1-cp38-cp38-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 6.4 MB
- Tags: CPython 3.8, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07681867892537a8075dedc983d54945e03400137bd6670dc675591b9b048450
|
|
| MD5 |
360cda538e52ed69d5c0ac72250db948
|
|
| BLAKE2b-256 |
044d0573d9f2c8f4273859b1d840b94d05bf6692b6526c0e50cc5bd7e9a2c551
|
File details
Details for the file kola-1.2.1-cp38-cp38-macosx_11_0_arm64.whl.
File metadata
- Download URL: kola-1.2.1-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.0 MB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14b188935954d61db365ab7a60b4d1929fae2698d2080c2b090eb6278ce925bf
|
|
| MD5 |
c71579c39595e2740dc5e91cb6e06113
|
|
| BLAKE2b-256 |
b276c20bcd6263763a23cd5eb4b1ffdd6aa3d14f6e241f20a450bff433264d38
|