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

from jetblack_ksql_dbapi.aio import connect


async def main() -> None:

    conn = 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())

Things to do

  • Figure out what to do with the paramstyle global.
  • How to handle timeouts.
  • Do something useful with the output of commands like SHOW TABLES;
  • Handle multiple commands.
  • Tidy up cursors with multiple executions.

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.2.0.tar.gz (21.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.2.0-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jetblack_ksql_dbapi-0.2.0.tar.gz
  • Upload date:
  • Size: 21.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.2.0.tar.gz
Algorithm Hash digest
SHA256 ef5b748f0b3cbc7a4491a7f4d4658ed68f98d7de288af6f5a372a8f698f4ab76
MD5 ce75d0aa4e319d20c3ecbd3324a60aa0
BLAKE2b-256 1d42bd376bb4f6b0110b01992834bd9ed73427d521f73a4f22fb11e46f103f15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for jetblack_ksql_dbapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a9196f99a5ca265a688f9af5159fd2cee3b894958bbb6e7b408730504a18cc6
MD5 fa2267453db224907f3d4bc4cc9f4393
BLAKE2b-256 bddcf72f8e1c44cb048ace61851877d62614c95ac3aee44d4e5fcc0a66f90f1d

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