A lightweight Python driver for the Apache Flink SQL Gateway, implementing PEP 249 (DB-API 2.0).
Project description
py-flink-sql-gateway
A lightweight Python driver for the Apache Flink SQL Gateway, implementing PEP 249 (DB-API 2.0).
Installation
pip install py-flink-sql-gateway
Quick start
from flink_gateway import connect
with connect("http://localhost:8083") as conn:
# Create a streaming source
with conn.cursor() as cur:
cur.execute("""
CREATE TABLE orders (
id INT NOT NULL,
item STRING NOT NULL,
created_at TIMESTAMP(6) NOT NULL,
customer ROW<
first_name STRING NOT NULL,
last_name STRING NOT NULL,
age INT NOT NULL
> NOT NULL,
notes STRING
) WITH (
'connector' = 'datagen',
'rows-per-second' = '5',
'fields.id.kind' = 'sequence',
'fields.id.start' = '1',
'fields.id.end' = '100',
'fields.item.length' = '12',
'fields.customer.first_name.length' = '8',
'fields.customer.last_name.length' = '10',
'fields.customer.age.min' = '21',
'fields.customer.age.max' = '65',
'fields.notes.length' = '12'
)
""")
# Query and iterate
with conn.cursor() as cur:
cur.execute("""
SELECT id, item, created_at, customer, notes AS note
FROM orders
""")
for i, row in enumerate(cur):
id_, item, created_at, customer, note = row
print(
f"{id_}\t{item}\t{created_at.isoformat()}\t"
f"{customer['first_name']} {customer['last_name']} ({customer['age']})\t"
f"{note or ''}"
)
if i >= 4:
break
Tip:
ROWandMAPtypes arrive as Pythondict,ARRAYarrives aslist. Binary data is passed through as-is.
Connection options
# Pass Flink session properties
with connect("http://localhost:8083", properties={"pipeline.name": "my-job"}) as conn:
...
# Set a query timeout (default: 300s)
with conn.cursor(query_timeout=60.0) as cur:
cur.execute("SELECT ...")
Low-level REST access
If you need features beyond DB-API, use the exported client directly:
from flink_gateway import FlinkSqlGatewayClient
with FlinkSqlGatewayClient("http://localhost:8083") as client:
status = client.get_operation_status("session-handle", "operation-handle")
print("current status:", status)
Type mapping
Python uses None for SQL NULLs natively — no wrapper types needed.
| Flink Type | Python Type |
|---|---|
| TINYINT / SMALLINT / INT | int |
| BIGINT / INTERVAL | int |
| FLOAT / DOUBLE | float |
| BOOLEAN | bool |
| CHAR / VARCHAR / STRING | str |
| DECIMAL | decimal.Decimal |
| DATE | datetime.date |
| TIME | datetime.time |
| TIMESTAMP / TIMESTAMP_LTZ | datetime.datetime |
| BINARY / VARBINARY | raw (passthrough) |
| ROW | dict |
| MAP | dict |
| ARRAY | list |
Nested complex types (e.g. MAP<STRING, ROW<..., MAP<STRING, ROW<TIMESTAMP>>>>) are recursively decoded to the correct Python types.
Development & tests
Requires Python 3.11+ and uv.
# Install dependencies
uv sync --group dev
# Set up pre-commit hooks (runs on every push)
pre-commit install --hook-type pre-push
# Run unit tests (no Docker needed)
uv run pytest tests/test_client.py tests/test_dbapi.py -v
# Run integration tests (requires Docker)
uv run pytest tests/test_integration.py -v -s -m integration
# Run all pre-commit checks manually
pre-commit run --all-files
Integration tests spin up a Flink cluster (JobManager + TaskManager + SQL Gateway) via testcontainers-python.
License
MIT
Project details
Release history Release notifications | RSS feed
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 py_flink_sql_gateway-0.1.1.tar.gz.
File metadata
- Download URL: py_flink_sql_gateway-0.1.1.tar.gz
- Upload date:
- Size: 42.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0470d8579c2c7519402d5dbb1554950f285ef09ac7bcd5bc1b31275da26d4858
|
|
| MD5 |
d16afccf839450af49925b16b2221631
|
|
| BLAKE2b-256 |
02870677ee028d559e66bf2e33582a247147f6bc6cb9edda22183670142fa4cb
|
Provenance
The following attestation bundles were made for py_flink_sql_gateway-0.1.1.tar.gz:
Publisher:
publish.yml on exness/py-flink-sql-gateway
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_flink_sql_gateway-0.1.1.tar.gz -
Subject digest:
0470d8579c2c7519402d5dbb1554950f285ef09ac7bcd5bc1b31275da26d4858 - Sigstore transparency entry: 1026849402
- Sigstore integration time:
-
Permalink:
exness/py-flink-sql-gateway@4844a4762b66267967975da67797de8d2dbc791e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/exness
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4844a4762b66267967975da67797de8d2dbc791e -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_flink_sql_gateway-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py_flink_sql_gateway-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88c74123434ee6ac7d03b5d0c64647822ea24b7519e678b757ba13c76ecd18a2
|
|
| MD5 |
edc4c4aff280d195519f4c4ccd68ae94
|
|
| BLAKE2b-256 |
9ffc47eee5c32454017c7dcadcec2df0ee86bf8c95c02fd40966a8ea097bc772
|
Provenance
The following attestation bundles were made for py_flink_sql_gateway-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on exness/py-flink-sql-gateway
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_flink_sql_gateway-0.1.1-py3-none-any.whl -
Subject digest:
88c74123434ee6ac7d03b5d0c64647822ea24b7519e678b757ba13c76ecd18a2 - Sigstore transparency entry: 1026849443
- Sigstore integration time:
-
Permalink:
exness/py-flink-sql-gateway@4844a4762b66267967975da67797de8d2dbc791e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/exness
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4844a4762b66267967975da67797de8d2dbc791e -
Trigger Event:
push
-
Statement type: