Skip to main content

a Python Polars interface to q

Project description

kola

a Python Polars Interface to q

Basic Data Type Map

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 string as keys.

Quick Start

Create a Connection

import polars as pl
import kola
# Connect to q
conn = kola.Q('localhost', 1800)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kola-2.2.2.tar.gz (59.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kola-2.2.2-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl (4.7 MB view details)

Uploaded PyPymanylinux: glibc 2.28+ x86-64

kola-2.2.2-cp314-cp314-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.14Windows x86-64

kola-2.2.2-cp314-cp314-manylinux_2_28_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.28+ x86-64

kola-2.2.2-cp314-cp314-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

kola-2.2.2-cp314-cp314-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

kola-2.2.2-cp313-cp313-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.13Windows x86-64

kola-2.2.2-cp313-cp313-manylinux_2_28_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

kola-2.2.2-cp313-cp313-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

kola-2.2.2-cp313-cp313-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

kola-2.2.2-cp312-cp312-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.12Windows x86-64

kola-2.2.2-cp312-cp312-manylinux_2_28_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

kola-2.2.2-cp312-cp312-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

kola-2.2.2-cp312-cp312-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

kola-2.2.2-cp311-cp311-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.11Windows x86-64

kola-2.2.2-cp311-cp311-manylinux_2_28_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

kola-2.2.2-cp311-cp311-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

kola-2.2.2-cp311-cp311-macosx_10_12_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

kola-2.2.2-cp310-cp310-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.10Windows x86-64

kola-2.2.2-cp310-cp310-manylinux_2_28_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

File details

Details for the file kola-2.2.2.tar.gz.

File metadata

  • Download URL: kola-2.2.2.tar.gz
  • Upload date:
  • Size: 59.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for kola-2.2.2.tar.gz
Algorithm Hash digest
SHA256 5c9d45fafa761e706b2099201b78c7afbcd2ca8eb6a1f9f326e1cac3df43d4c5
MD5 498d5f7ee7dadf1163a68a30b9a0b576
BLAKE2b-256 58a7efd62531bf082d139627b5747c918e98a6b96e129a470416cf7fd78aa26c

See more details on using hashes here.

File details

Details for the file kola-2.2.2-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-pp311-pypy311_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 211d760e466cbe65ead3e2b0742ad21daedb4bc39af9505b0e9a06fb27ee6c0c
MD5 06aa2eff7e775d18bdf2441017d84278
BLAKE2b-256 2b8b3ef9db521eef0c40c62d3e36169b1b53147527568153c847fc7fe090f5c1

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: kola-2.2.2-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for kola-2.2.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 f5b243ce7d2538f9e86ce8eb162d2eace2dee15b23deed47ab337c27796e4273
MD5 72ae8d90ffd086957da49eff9b1eb097
BLAKE2b-256 0b3881669a3463f213cc362bce2fc25cf4268d8a6f513ca8bd8a183158f425e8

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp314-cp314-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp314-cp314-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c77af42745632a6530a5d2e2ad79be4792f30463c3cd82748bd535328617e0df
MD5 88707b0bb310e7a643c2e753a93b7976
BLAKE2b-256 36124744da1ce0792ed55dc7a85f8830b64552839fdfb3006411d2611bd926e1

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 daaaf1b11d0962f1f9f312698bd6ab019318dcaeae8c902915df5fca9b041aee
MD5 2b2b47c462b620ca32c4b613b63f4c80
BLAKE2b-256 ac7d7b07a75187c02f23d982528d11dec9df23fbe8d000016038b6a7c8d6c5c6

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 438445ee75a19a4f489ee6764f88be62b454ebbe5d4079f248885b6941975d4d
MD5 801923245ee2d67ab277017895387767
BLAKE2b-256 8760c5dea78a8b137fab921ac960441fe025772758a40070f8e8b27c07666e0e

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: kola-2.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for kola-2.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5007b9b76df09350f3936e7bdbc78162428271b47a3efacd8e5adbedd8f05323
MD5 6b44b0c8730e4e7706548ba22e9bf952
BLAKE2b-256 e3b3b6bca7639da8933c0751b54e4b559e2b18b94d8edc2cbe44356e49e1888d

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e526e4ec99a6df9c714c071342878db65b11ac74e4b52c5b71692ca2c0bbf56e
MD5 d37b558c5e7f29e3140746ad6010d52a
BLAKE2b-256 73667514f4342c85c77b2f4046a282110ed56c21bf464b0987f51727163cac88

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b39e6352bccfd360c7daad59cfa74e456977268991ef00ad9d65f8e1a9ec1c16
MD5 ab18381b8c43d43827be5f1d87e5ebdc
BLAKE2b-256 6082a6aa5189d3b7b8426475152e0c5c380b7022d6d4f4658d752ae8c9b730a1

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5644caab9286f296ffb3ac5977e8a67b26eab077afb04a4662e1c3adc0710925
MD5 754ea843fe4e87224c32364096524deb
BLAKE2b-256 05894a1399474904cadeffe52f2f3b4ebb254d4d9ca7078046e5bf781380c909

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: kola-2.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for kola-2.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9d9f0cd19d70ea36da0b6d2cf58af5ee73c5589417133b1bbefe74caafcbf9e9
MD5 d497f1d5f7807d27332e150aa12a441e
BLAKE2b-256 c3f307e06e212a2f6f84f82498f8b086298f7214f530ba2c368e5980d4a7eb2a

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 60d8cad76b4c92981574bc7901f507dfa8862aa4717af9d7be3233e42bc0933f
MD5 b40fc3422b616b33117cbca1bb709ac0
BLAKE2b-256 8a3f2693e54ea042ca30d35035c2a7438f1ce12a229d2813af360ba3addc6f35

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72604854c15737d0e1e2e4868fc9a3e084f688db707005315c5259076e9c3e72
MD5 4ba84bbd64137617611187efd7d39e54
BLAKE2b-256 984c0bb271ee1d1e20a0e75105a644874b43be2e1e9aba2fb25689f293f86a7c

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 827df9825bee1f99935c4124dbe92e1aab63d27aeda3ad8f1e5e852d71f13683
MD5 b503b8753916d848ec5999665caf73f9
BLAKE2b-256 4656ed90780bc562d2b5db6dd6b08e94d6669239bd59dee8b5e30f9fc075620b

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: kola-2.2.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for kola-2.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f557f6e18949017b6bb2d95d3ca81eff2eda4fe8c3083a609a48a605547998cd
MD5 5aefc166b9c28bd574722ce246250f36
BLAKE2b-256 34096f5444b23c6f5011ddb3f6f0725244d112969d4c369d300492cce0bee059

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 780ee455e21373676e0f557d6c367ccbb0b342091a5d0de23f7fc8f33baeb292
MD5 0a915ffdd343ff6812504f69c66daf80
BLAKE2b-256 af73c95d1e5c568725abb98a6496e88817e3b29a33544ef2a867cdd97f613908

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ad46fe7a688ac0e52cd4157c74dadec2fe8f832cba767e3a5d2f3fc9844cbacf
MD5 012057c917499d741be146112b055777
BLAKE2b-256 9440c4d666482ddb41ea6036b3066d3284e4a74f82c1f2d555a7f667d0df12b4

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e45a219593fc86fda33323dbbe6895606017b026e861f78687322c2bbf321fdf
MD5 81978eee205e7c9b4f7ff6cc1033fd86
BLAKE2b-256 f3d075533bcdbc5d2cb831b5cbc5e1e85c4f048ba6efe133a4fef6e69cddd231

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: kola-2.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for kola-2.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e5ab5663339a5a026a3478f75e2634050794242525055fefc95a0bb57f9f3082
MD5 4839f14ee9e9a81eb0ebfc618dc60f99
BLAKE2b-256 339b6bdd460f8e61ee740c36b7763f26e4831e7371d8f60c4258523424d50f63

See more details on using hashes here.

File details

Details for the file kola-2.2.2-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for kola-2.2.2-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 315395f017b6bf06c79ae79d087b93f3e7e036aad975286ec8fb9102fcd19a3b
MD5 04d4ab7ec0527c371cfdffa989e3f5ca
BLAKE2b-256 73a059649950ba84de679f8ff99bbf78edc1a04ab00470bbcddbb2a95df59781

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page