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
andknk
- Dictionaries with
xd
and tables withxt
.
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
Run pytest
in the root directory.
Formatting with black .
Check type annotations with mypy --strict .
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 Distribution
Built Distribution
File details
Details for the file aiokdb-0.0.2.tar.gz
.
File metadata
- Download URL: aiokdb-0.0.2.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a8432affebf4bb08a0d1fb57f4c11231de687a3fe0d7fbde093280e411d41d8 |
|
MD5 | 3a30d4075ac033d644dc1d3a877ee17b |
|
BLAKE2b-256 | a638ec1f907e286b9228d66c3e7080004385730caeaf7c1597ecc9a9145a4db6 |
File details
Details for the file aiokdb-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: aiokdb-0.0.2-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42f73e1d6bae635a337b04cf223018245d2aa9848846df47c5f7f26af1e55360 |
|
MD5 | 0af4e50728dc64e06df82e0e29b2f510 |
|
BLAKE2b-256 | eac09423429dfc78ce29b43b7f13dbd8da88badc9b16d753c1ed55c9b71ddf88 |