Skip to main content

jetblack-ksql-dbapi

A vanilla and asyncio ksql DBAPI interface for Python >= 3.12.

Status

This is work in progress.

Installation

The package uses either httpx or httpx2. This can either be installed separately or specified.

pip install jetblack-ksql-dbapi[httpx2]

Usage

There is a docker compose file in the scripts folder which will bring up a local instance of ksql.

Here is an example using the async client connecting to a local instance of ksql.

import asyncio

import jetblack_ksql_dbapi.aio as ksql
from jetblack_ksql_dbapi.aio import Connection


async def main() -> None:

    conn = ksql.connect("http://localhost:8088")

    cur = conn.cursor()

    # Drop the tables if they exist.
    await cur.execute(
        "DROP TABLE IF EXISTS user_view DELETE TOPIC;"
    )
    await cur.execute(
        "DROP TABLE IF EXISTS user DELETE TOPIC;"
    )

    # Create the tables.
    await cur.execute(
        """\
CREATE TABLE user
(
    user_id BIGINT  PRIMARY KEY,
    username        STRING,
    created         TIMESTAMP,
    age             DECIMAL(3, 0)
) WITH (
    kafka_topic='user',
    value_format='json',
    key_format='json',
    partitions=1
);
"""
    )

    await cur.execute(
        """\
CREATE TABLE user_view AS SELECT * FROM user;
"""
    )

    # Insert some data.
    await cur.executemany(
        """\
INSERT INTO user(user_id, username, created, age)
VALUES (?, ?, ?, ?);
""",
        (
            (1, 'tom', '2026-07-28T12:03:24', 42),
            (2, 'dick', '2026-07-28T12:03:24', 42),
            (3, 'harry', '2026-07-28T12:03:24', 42)
        )
    )

    await cur.execute(
        "SELECT * FROM user_view;"
    )
    async for row in cur:
        print(row)


if __name__ == "__main__":
    asyncio.run(main())

Download files

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

Source Distribution

jetblack_ksql_dbapi-0.1.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

jetblack_ksql_dbapi-0.1.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file jetblack_ksql_dbapi-0.1.0.tar.gz.

File metadata

  • Download URL: jetblack_ksql_dbapi-0.1.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for jetblack_ksql_dbapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d9817e27b4cf9578cce24d176c64f86ff8ee3294ed6db2c3d3d40fb8036ad0a
MD5 9ba754585bff84b2e1b61f038ee2df4d
BLAKE2b-256 ecb1e19631c03441f088cb2e48ee586b86c2b46824e4fb123d914a1dbbff52e1

See more details on using hashes here.

File details

Details for the file jetblack_ksql_dbapi-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for jetblack_ksql_dbapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 232fc910b1444409ca3c092e47d3e9cf0f9dac271fc8ff731a85267c6d44bfa4
MD5 f30cbc4c4e8d105d62fc2e391a2f2326
BLAKE2b-256 a35f4bb709ee9ebcb7ada248b8549e5c7b1257103c9b8a4b633ddc5fd0ddf271

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 Sentry Error logging StatusPage Status page