Skip to main content

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

Quick Start

Create a Connection

import polars as pl
import kola
q = kola.Q('localhost', 1800)

# with retries for IO Errors, 1s, 2s, 4s ...
q = kola.Q('localhost', 1800, retries=3)

# with read timeout error, 2s, "Resource temporarily unavailable"
q = kola.Q('localhost', 1800, retries=3, timeout=2)

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")

Lambda Query

When the first string starts with { and ends with }, it is treated as a lambda.

d = {"a": 1, "b": 2}
q.sync("{key x}", d)

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)

Subscribe

from kola import QType

q.sync(".u.sub", pl.Series("", ["table1", "table2"], QType.Symbol), "")

# specify symbol filter
q.sync(
    ".u.sub",
    pl.Series("", ["table1", "table2"], QType.Symbol),
    pl.Series("", ["sym1", "sym2"], QType.Symbol),
)

while true:
    # ("upd", "table", pl.Dataframe)
    upd = self.q.receive()
    print(upd)

Generate IPC

import polars as pl
from kola import generate_ipc

df = pl.DataFrame(
    {
        "sym": pl.Series("sym", ["a", "b", "c"], pl.Categorical),
        "price": [1, 2, 3],
    }
)
# without compression
buffer = generate_ipc("sync", False, ["upd", "table", df])

# with compression
buffer = generate_ipc("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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

kola-1.5.2-cp313-none-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.13 Windows x86-64

kola-1.5.2-cp313-cp313-manylinux_2_31_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.13 manylinux: glibc 2.31+ x86-64

kola-1.5.2-cp313-cp313-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

kola-1.5.2-cp312-none-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.12 Windows x86-64

kola-1.5.2-cp312-cp312-manylinux_2_31_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.12 manylinux: glibc 2.31+ x86-64

kola-1.5.2-cp312-cp312-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

kola-1.5.2-cp311-none-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.11 Windows x86-64

kola-1.5.2-cp311-cp311-manylinux_2_31_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.31+ x86-64

kola-1.5.2-cp311-cp311-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

kola-1.5.2-cp310-none-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.10 Windows x86-64

kola-1.5.2-cp310-cp310-manylinux_2_31_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.31+ x86-64

kola-1.5.2-cp310-cp310-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

kola-1.5.2-cp39-none-win_amd64.whl (4.9 MB view details)

Uploaded CPython 3.9 Windows x86-64

kola-1.5.2-cp39-cp39-manylinux_2_31_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.31+ x86-64

kola-1.5.2-cp39-cp39-macosx_11_0_arm64.whl (4.6 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

File details

Details for the file kola-1.5.2-cp313-none-win_amd64.whl.

File metadata

  • Download URL: kola-1.5.2-cp313-none-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for kola-1.5.2-cp313-none-win_amd64.whl
Algorithm Hash digest
SHA256 483af56f1342b2c9150dfe9ff2e254196ddd90114b8e05fa48ffa7971610603f
MD5 519de885001468faa0784160adc49541
BLAKE2b-256 2f76508f97baf8ffce2489fc7de062fbab1ab51c29bdd5f54d5f64b1aa264bae

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp313-none-win_amd64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp313-cp313-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for kola-1.5.2-cp313-cp313-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 38739f6bed86fab8f40703be9e9d9389ba00397e85ea45adab67859b00b6c1b6
MD5 0c236cc95d3446b8c91743ff68428ef5
BLAKE2b-256 6dfe59440a3eff3d3f57f5ee0fd3d8e9acf03428e93b1f499cdfe2b24f480714

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp313-cp313-manylinux_2_31_x86_64.whl:

Publisher: release-python-linux.yml on jshinonome/kola

Attestations:

File details

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

File metadata

File hashes

Hashes for kola-1.5.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a81915132f2ecc405994a74139534f0b781c7a096fe928055e2092726b67d60
MD5 72cf71e6ab674a49fb94121a7e28d2e7
BLAKE2b-256 3f888c6754e1b1d080bc31ad709e389945ad829b158c2be13135faa6054ec05d

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp312-none-win_amd64.whl.

File metadata

  • Download URL: kola-1.5.2-cp312-none-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for kola-1.5.2-cp312-none-win_amd64.whl
Algorithm Hash digest
SHA256 4d5e4f462ee7f2c7bc7dc42d94e72401d3239920d588e48d74db9f86d29499f0
MD5 d1c58e3af1693f02b3b784b89753231a
BLAKE2b-256 afb888c17ecc3f426c70ab55a06305996d1dc98c39fbc2f89a1e9e19e167bac0

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp312-none-win_amd64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp312-cp312-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for kola-1.5.2-cp312-cp312-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 7f239df39b34b5ff60cabbe38dae1412acbf8faa2e60563f49161fc19fc60054
MD5 568599f2e5ce29aecd1063e2dc7414f0
BLAKE2b-256 5c20c329e927b5bd1ab9435ee6c732e3f0981f072042d06dcaa5304670699673

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp312-cp312-manylinux_2_31_x86_64.whl:

Publisher: release-python-linux.yml on jshinonome/kola

Attestations:

File details

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

File metadata

File hashes

Hashes for kola-1.5.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 41321fb42c7480e1f9d4755385e9de78c1dd664df2c9bd0ccc180cfcdb0c794a
MD5 25bff077d82eb6683665c4ebf2a60fc3
BLAKE2b-256 3753d56eedc83de7acec3e3f1592b1c0a176260b12c605c0c1b2b642680901d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp311-none-win_amd64.whl.

File metadata

  • Download URL: kola-1.5.2-cp311-none-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for kola-1.5.2-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 7fd5d0d65f3ac8162894c9d63cff064371131d8278f0a1b5fb097dd5da41d229
MD5 13c9c496a2242ca72a7f192c09366ad4
BLAKE2b-256 ae4792447308ab5fcbb120de1e6f95bda03d01513b1428316ed3e80720e75168

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp311-none-win_amd64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp311-cp311-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for kola-1.5.2-cp311-cp311-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 d1be6ca7a7d43e6c5e31197662f2acc51bb740d685faf3677f8212fe381fbeb2
MD5 cde41fa5ee166328bbecfb78c755c339
BLAKE2b-256 ede858eb3854423385c5df0dda8f6bf2a543bb0bc11161d93c44604d7509774a

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp311-cp311-manylinux_2_31_x86_64.whl:

Publisher: release-python-linux.yml on jshinonome/kola

Attestations:

File details

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

File metadata

File hashes

Hashes for kola-1.5.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63d70d2d2fddef2fb227f62756f67e29a3e105c1a3c7e843f818ecf10fb5fc21
MD5 4100996b567b2a23b8e42e07ad9812ae
BLAKE2b-256 7dbe53bda0264d037da4a993f6157ac4e1de7e2ac578fdb19b37e21bba15ef53

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp310-none-win_amd64.whl.

File metadata

  • Download URL: kola-1.5.2-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for kola-1.5.2-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 266b37b43f7a95dfd51a4fd05b6c07102fb2093e1687bda5934455f37834656e
MD5 4965856547714b97349ae4d713a1df9a
BLAKE2b-256 391770d2b2c19396da8684e257e3e8b407a3470337403c4870d8b9c491e217a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp310-none-win_amd64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp310-cp310-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for kola-1.5.2-cp310-cp310-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 b23b777cfab3988d3b3535a47f74ff68166d0dd7a2706260380fb521b09e180e
MD5 ff415b5f77be0cb58e6185e731a73cda
BLAKE2b-256 ef7a027f38a43485cd184bae2aecbdbe230b986584b1080de6c345337c238eb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp310-cp310-manylinux_2_31_x86_64.whl:

Publisher: release-python-linux.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kola-1.5.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9c631094747490a09a5129496e7b3d59c0cba9b47392d46ec7e51d86749f37bc
MD5 69fe2e18c1b74e4f406e0af5dbb0adcd
BLAKE2b-256 d23cd1d05fb95a719e6999562a008752f3e90c0497e6bf7baacda8489acd353f

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp39-none-win_amd64.whl.

File metadata

  • Download URL: kola-1.5.2-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for kola-1.5.2-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 0864f26c166a1f2d123f2ccbe577c4f37b87695147a95a70318760d179cfb090
MD5 41b9749847132e16b39ef4c63472e932
BLAKE2b-256 e70de66b990778507133341447f965d78799da2eaf29beec42f19daef9e07a39

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp39-none-win_amd64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp39-cp39-manylinux_2_31_x86_64.whl.

File metadata

File hashes

Hashes for kola-1.5.2-cp39-cp39-manylinux_2_31_x86_64.whl
Algorithm Hash digest
SHA256 5f9d337d57005d251727cde904bedbe831078bfe0bcf0e0a5a9ebf7dd19f9980
MD5 1588dc94ceab1e0fffcd44bf53490237
BLAKE2b-256 68b79fa91a5e88ad2266c56c1ba24e7b2d02bc07cda8e6dd4345039ec10f3bcd

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp39-cp39-manylinux_2_31_x86_64.whl:

Publisher: release-python-linux.yml on jshinonome/kola

Attestations:

File details

Details for the file kola-1.5.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for kola-1.5.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 981ba0be9377312225b84339a48b4199ebc739e97e32f05f0ddc4c1fc7eef17c
MD5 d101c5514e73fa52ddc502f707b65aed
BLAKE2b-256 73fbfb303c3cb7b7763e783920e6b5ec640c4c1ca98c7b8e6a86538cd623e9cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for kola-1.5.2-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: release-python-other-os.yml on jshinonome/kola

Attestations:

Supported by

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