Skip to main content

Pure Python asyncio connector to KDB

Project description

aiokdb

Python asyncio connector to KDB. Pure python, so does not depend on the k.h bindings or kdb shared objects, or numpy/pandas.

The unit tests will use a real KDB binary to test against if you have a QHOME containing a working interpreter.

The layout of the repository, documentation and code borrows heavily from aioredis-py

Peer review & motivation

qPython is a widely used library for this task and it maps objects to Pandas Dataframes which might be more suitable for the majority of applications.

This library takes a different approach and aims to replicate using the KDB C-library functions. It was built working from the publically documented Serialization Examples and C API for kdb+ pages. Users might also need to be familiar with k.h.

A simple example:

from aiokdb import khpu
# run ./q -p 12345 &

h = khpu("localhost", 12345, "kdb:pass")
result = h.k("2.0+3.0", None) # None can be used where C expects (K)0

# if the remote returns a Q Exception, this gets raised, unless k(..., raise=False)
assert result.f() == 5.0

The result object is a K-like Python object (a KObj), having the usual signed integer type available as result.type. Accessors for the primitive types are prefixed with an a and check at runtime that the accessor is appropriate for the stored type (.aI(), .aJ(), .aH() etc.). Atoms store their value to a bytes object irrespective of the type, and encode/decode on demand. Atomic values can be set with (.i(3), .j(12), .ss("hello")).

Arrays are implemented with subtypes that use Python's native arrays module for efficient array types. The MutableSequence arrays are returned using the usual array accessor functions kI, kB, kS etc.

Serialisation is handled by b9 which returns a python bytes, and d9 which takes a bytes and returns a K-object.

  • Atoms are created by ka, kb, ku, kg, kh, ki, kj, ke, kf, kc, ks, kt, kd, kz, ktj
  • Lists with ktn and knk
  • Dictionaries with xd and tables with xt.

Python manages garbage colleciton of our objects, so none of the refcounting primitives exist, ie. k.r and functions r1, r0 and m9, setm have no equivelent.

Tests

  • Formatting with ruff check .
  • Formatting with black .
  • imports isort --check --profile black .
  • Check type annotations with mypy --strict .
  • Run pytest . in the root directory

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

aiokdb-0.0.8.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

aiokdb-0.0.8-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file aiokdb-0.0.8.tar.gz.

File metadata

  • Download URL: aiokdb-0.0.8.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for aiokdb-0.0.8.tar.gz
Algorithm Hash digest
SHA256 93efe5c888b466879c9ae3a4dd23197e77e9dc802b6d8213732f460dffa74e91
MD5 76fa6cb7c524169ae5de08a0fa27f6ce
BLAKE2b-256 5595d22ce99e6dd699bda6e8e3ee561f0302e15ef71573526adc39ad54389e48

See more details on using hashes here.

File details

Details for the file aiokdb-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: aiokdb-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for aiokdb-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 fae3dbd1c29fe2dc055271041a5625e2b7cb2b561a37adfdc148713462c5cd55
MD5 3b726b50e6ff5e8d6c4052da75e7d5c1
BLAKE2b-256 15098084098222df658c43c9dfbcee9cc47645fcf918f3971e41d608b686bb14

See more details on using hashes here.

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