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 as an extra.

pip install jetblack-ksql-dbapi[httpx2]

Usage

In the source repo 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.
  • rowcount can be supported if we detect pull/push queries.

Metadata

Release files for jetblack-ksql-dbapi 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jetblack-ksql-dbapi 0.2.1
File Size Uploaded
jetblack_ksql_dbapi-0.2.1.tar.gz 28.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jetblack-ksql-dbapi 0.2.1
File Interpreter ABI Platform
jetblack_ksql_dbapi-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 62.5 kB

Release files / jetblack_ksql_dbapi-0.2.1.tar.gz

Download URL jetblack_ksql_dbapi-0.2.1.tar.gz
Size 28.3 kB
Tags Source
SHA-256 checksum
How to use checksums
42942fd54642da1e4f5a5d21aebda22e544019d5048d5ad7a09b37202aad47b9
BLAKE2b-256 checksum
How to use checksums
340cd08f73c807d1541d2d06d583b518ecbdfb654b5e835ffa302a86a1cac7f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / jetblack_ksql_dbapi-0.2.1-py3-none-any.whl

Download URL jetblack_ksql_dbapi-0.2.1-py3-none-any.whl
Size 34.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4611f6b141fea04c1cab96dc56bfd7b1775f122c754fd6bc40f02df66860e19
BLAKE2b-256 checksum
How to use checksums
4612cb69172683b25973ce07565090d65a390edce8a45362b9097abccde5f886
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page