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
paramstyleglobal. - 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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jetblack_ksql_dbapi-0.2.1.tar.gz.
File metadata
- Download URL: jetblack_ksql_dbapi-0.2.1.tar.gz
- Upload date:
- Size: 28.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42942fd54642da1e4f5a5d21aebda22e544019d5048d5ad7a09b37202aad47b9
|
|
| MD5 |
e8a43ef890f03b5c2b25553fe8565ebe
|
|
| BLAKE2b-256 |
340cd08f73c807d1541d2d06d583b518ecbdfb654b5e835ffa302a86a1cac7f7
|
File details
Details for the file jetblack_ksql_dbapi-0.2.1-py3-none-any.whl.
File metadata
- Download URL: jetblack_ksql_dbapi-0.2.1-py3-none-any.whl
- Upload date:
- Size: 34.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4611f6b141fea04c1cab96dc56bfd7b1775f122c754fd6bc40f02df66860e19
|
|
| MD5 |
afdedc64741218602d8ae984c46715ef
|
|
| BLAKE2b-256 |
4612cb69172683b25973ce07565090d65a390edce8a45362b9097abccde5f886
|