Q IPC publisher for kdb Insights Enterprise databases.¶
Use DBPublisher to publish data directly to a kdb Insights Enterprise database over a Q IPC connection to the TP port.
Supports CSV, Parquet, JSON files, directories, Pandas DataFrames, and pykx Table objects.
Note
Requires pykx. Install with: pip install "kxi[all]"
Example
import pandas as pd
from kxi.publish.dbpublisher import DBPublisher
df = pd.DataFrame({"sym": ["AAPL", "GOOG"], "price": [150.0, 175.0]})
with DBPublisher(host="localhost", port=5010) as pub:
pub.publish(df, table="quotes")
pub.publish("/path/to/trades.csv", table="trades")
Classes:
- DBPublisher – Q IPC publisher for a kdb Insights Enterprise database.
DBPublisher¶
DBPublisher(host, port, user=None, password=None, chunksize=10000, pub_fn='.u.pub')
Q IPC publisher for a kdb Insights Enterprise database.
Connects to a kdb+ database's TP (tickerplant) port over Q IPC and inserts data into named tables. Use as a context manager to ensure the connection is closed after publishing.
Example
import pandas as pd
from kxi.publish.dbpublisher import DBPublisher
df = pd.DataFrame({"sym": ["AAPL", "GOOG"], "price": [150.0, 175.0]})
with DBPublisher(host="localhost", port=5010) as pub:
pub.publish(df, table="quotes")
pub.publish("/path/to/trades.csv", table="trades")
Functions:
- close – Close the Q IPC connection to the kdb Insights database.
- publish – Publish data to a named table on the kdb Insights database.
Connect to a kdb Insights database TP port over Q IPC.
Parameters:
- host (
str) – Hostname or IP address of the kdb Insights TP server. - port (
int) – Port number for the Q IPC connection. - user (
Optional[str]) – Username (not used in current version). - password (
Optional[str]) – Password (not used in current version). - chunksize (
int) – Number of rows to read per chunk when publishing files. Avoids loading entire files into memory. Default:10000. Not supported for columnar JSON (file_format="json"). - pub_fn (
str) – Q function to call for publishing. Default:".u.pub".
Raises:
RuntimeError– pykx is not installed.
close¶
close()
Close the Q IPC connection to the kdb Insights database.
publish¶
publish(data, table, *, file_format=None, type_map=None, **kwargs)
Publish data to a named table on the kdb Insights database.
Parameters:
-
data (
str | Path | DataFrame) – Data source. Accepted types: -
File path string or
pathlib.Path(e.g."/data/trades.csv") - HTTP, S3, or GCS URL (e.g.
"s3://bucket/data.parquet") - Directory path — all direct child files are published
pandas.DataFramepykx.Table- table (
str) – Destination table name in the kdb Insights database. - file_format (
DataFormat | str | None) – File format override:csv,parquet,json, orjson_records. Auto-detected from file extension if not set. - type_map (
dict | None) – Override pandas type casting for specific columns. Maps column names to target types:"timedelta","datetime", or"numeric". Example:{"time": "timedelta", "ts": "datetime"} - *kwargs* – Additional arguments forwarded to the Q publish function.