thunderduck-sqlalchemy 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,153 @@
1
+ Metadata-Version: 2.3
2
+ Name: thunderduck-sqlalchemy
3
+ Version: 0.1.0
4
+ Summary: SQLAlchemy dialect and DBAPI for thunderduck.io — query your lakehouse from Superset, Airflow, pandas and friends.
5
+ Keywords: sqlalchemy,duckdb,iceberg,lakehouse,thunderduck,superset
6
+ Author: YILDIRIM ADIGUZEL
7
+ Author-email: YILDIRIM ADIGUZEL <yadiguzel@gmail.com>
8
+ License: Apache-2.0
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Database
15
+ Classifier: Topic :: Database :: Front-Ends
16
+ Requires-Dist: httpx>=0.27.0
17
+ Requires-Dist: sqlalchemy>=1.4
18
+ Requires-Python: >=3.10
19
+ Project-URL: Homepage, https://thunderduck.io
20
+ Project-URL: Source, https://github.com/212data/thunderduck
21
+ Description-Content-Type: text/markdown
22
+
23
+ # thunderduck-sqlalchemy
24
+
25
+ A SQLAlchemy dialect and PEP 249 DBAPI for [thunderduck](https://thunderduck.io).
26
+ Query your lakehouse from anything that speaks SQLAlchemy — Superset, Airflow,
27
+ Dagster, Redash, pandas, Jupyter, Streamlit.
28
+
29
+ ```bash
30
+ pip install thunderduck-sqlalchemy
31
+ ```
32
+
33
+ Works with SQLAlchemy 1.4 and 2.x, on Python 3.10+ — so it installs cleanly
34
+ into Apache Superset (which pins SQLAlchemy 1.4) as well as modern Airflow,
35
+ Dagster and pandas environments.
36
+
37
+ ## Connect
38
+
39
+ Create an API token in the thunderduck console (**Settings → API Tokens**; it
40
+ starts with `tdk_` and is shown once), then:
41
+
42
+ ```python
43
+ from sqlalchemy import create_engine, text
44
+ from sqlalchemy.pool import NullPool
45
+
46
+ engine = create_engine(
47
+ "thunderduck://:tdk_your_token@api.thunderduck.io/",
48
+ poolclass=NullPool,
49
+ )
50
+
51
+ with engine.connect() as conn:
52
+ for row in conn.execute(text('SELECT * FROM "lego"."public"."lego_sets" LIMIT 10')):
53
+ print(row)
54
+ ```
55
+
56
+ pandas works directly:
57
+
58
+ ```python
59
+ import pandas as pd
60
+
61
+ df = pd.read_sql('SELECT * FROM "thunder_duck_demo"."iris"', engine)
62
+ ```
63
+
64
+ ### URL options
65
+
66
+ | Option | Default | Meaning |
67
+ | --- | --- | --- |
68
+ | password / `?token=` | — | Required. Your `tdk_…` API token. |
69
+ | `?ssl=false` | `true` | Use plain HTTP. For in-cluster use against the console-api Service. |
70
+ | `?poll_ms=` | `1000` | How often to poll for completion. |
71
+ | `?timeout_ms=` | `300000` | How long to wait for a query. |
72
+ | `?arraysize=` | `1000` | Rows fetched per page. |
73
+
74
+ ## Table names
75
+
76
+ thunderduck names are `catalog.schema.table` (flat-file catalogs) or
77
+ `catalog.table` (Iceberg/Nessie catalogs). SQLAlchemy models two levels, so
78
+ **the schema is the whole dotted prefix**:
79
+
80
+ ```python
81
+ from sqlalchemy import MetaData, Table
82
+
83
+ md = MetaData()
84
+ sets = Table("lego_sets", md, schema="lego.public", autoload_with=engine) # 3-level
85
+ iris = Table("iris", md, schema="thunder_duck_demo", autoload_with=engine) # 2-level
86
+ ```
87
+
88
+ Reflection (`inspect(engine).get_schema_names()` etc.) reads thunderduck's
89
+ catalog API rather than issuing SQL, so browsing schemas is fast and free.
90
+
91
+ ## Apache Superset
92
+
93
+ Installing the package is all that is needed — it registers a Superset DB
94
+ engine spec automatically. Add a database of type **Other** with:
95
+
96
+ ```
97
+ thunderduck://:tdk_your_token@api.thunderduck.io/
98
+ ```
99
+
100
+ Superset's stop button genuinely cancels the running query.
101
+
102
+ ## How it works, and what follows from that
103
+
104
+ Every statement is submitted to thunderduck's REST API, which runs it as an
105
+ isolated Kubernetes Job; results are then paged back over HTTP. That model has
106
+ consequences worth knowing up front:
107
+
108
+ - **Latency.** Expect seconds, not milliseconds, before the first row. Built
109
+ for analytics and BI, not for tight interactive loops.
110
+ - **Read-only.** No DML, no DDL, no transactions. `commit()` and `rollback()`
111
+ are no-ops.
112
+ - **Use `NullPool`.** A connection holds no server-side state, so pooling buys
113
+ nothing. The driver also never issues a `SELECT 1` health check, because
114
+ that would start a whole Job.
115
+ - **Parameters are rendered client-side.** thunderduck's API accepts SQL only,
116
+ so this driver renders bound parameters into the statement, escaping them
117
+ strictly and refusing types it does not recognise. Always pass untrusted
118
+ values as parameters — never build SQL by string concatenation. The
119
+ paramstyle is `pyformat`, so — as with psycopg2 — a literal percent sign in
120
+ hand-written SQL must be escaped as `%%` when you pass parameters.
121
+ - **Row ceiling.** The server caps how many rows one page returns and how many
122
+ a result set stores. Very large result sets are truncated; aggregate in SQL
123
+ rather than pulling raw rows.
124
+
125
+ ## Also available
126
+
127
+ For JVM tools (DBeaver, DataGrip) there is a JDBC driver — see the
128
+ `jdbc-driver/` directory of the thunderduck repository.
129
+
130
+ ## Development
131
+
132
+ ```bash
133
+ uv sync --dev
134
+ uv run pytest
135
+ uv run ruff check . && uv run ruff format --check .
136
+ ```
137
+
138
+ One gotcha: the committed `uv.lock` resolves SQLAlchemy 2.x, so a plain
139
+ `uv run pytest` only exercises **one** of the two supported majors. Apache
140
+ Superset pins `sqlalchemy<2`, so check that combination too before releasing:
141
+
142
+ ```bash
143
+ uv venv --python 3.10 .sa14
144
+ uv pip install --python .sa14 -e . "sqlalchemy<2" pytest
145
+ .sa14/bin/python -c "import sqlalchemy; print('SQLALCHEMY', sqlalchemy.__version__)"
146
+ .sa14/bin/pytest -q
147
+ ```
148
+
149
+ CI runs both legs on every push.
150
+
151
+ ## License
152
+
153
+ Apache-2.0
@@ -0,0 +1,13 @@
1
+ thunderduck_sqlalchemy/__init__.py,sha256=dKzBXKWYixVZPClauaq2X_dxIcRZcf1FRRBVNh4E5i4,436
2
+ thunderduck_sqlalchemy/catalog.py,sha256=YAumta1UrEdB0RIajMlCmzx6-t3yE8Tw4ESemsnPa10,2686
3
+ thunderduck_sqlalchemy/client.py,sha256=LIHDeQ2T2qjc4cFILiSiplOXZoKFikS6Hc0KrI1TEQE,7608
4
+ thunderduck_sqlalchemy/dbapi.py,sha256=pAxlGwJyhpVnfhkRq1gPPF8g3PuJWkfouO7wl9Z_ibY,9273
5
+ thunderduck_sqlalchemy/dialect.py,sha256=Acwf9SI36r3qEJvQxHV9tRyPBN0S5JAPFXOrCHoOx4I,9432
6
+ thunderduck_sqlalchemy/exceptions.py,sha256=7KPtRx4gxGKwer8z-nsJ2mfwEIXZmYmgP0DDBYN5oFY,1300
7
+ thunderduck_sqlalchemy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ thunderduck_sqlalchemy/superset_spec.py,sha256=2RTohcx2KjJQixpOllyZYN_HHwXZaROFerDk18CFiWI,5956
9
+ thunderduck_sqlalchemy/types.py,sha256=ngfb4rNItUfiIXlatGsT7VDCUsyZVYt0eofioZ07bVo,9291
10
+ thunderduck_sqlalchemy-0.1.0.dist-info/WHEEL,sha256=4OL6Foqnnp3xRY5wMkjgc25_i5YJC6dKsC6LPcjqEoU,80
11
+ thunderduck_sqlalchemy-0.1.0.dist-info/entry_points.txt,sha256=9rK6gB8cvvDpBpljtM4e62kiok5oTiaQYTqI8s2gHhI,257
12
+ thunderduck_sqlalchemy-0.1.0.dist-info/METADATA,sha256=1gPO1NQuStIY9VNyM9nyUnNnPbXslkRyGELqv57MfxY,5309
13
+ thunderduck_sqlalchemy-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: uv 0.12.5
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,7 @@
1
+ [sqlalchemy.dialects]
2
+ thunderduck = thunderduck_sqlalchemy.dialect:ThunderduckDialect
3
+ thunderduck.rest = thunderduck_sqlalchemy.dialect:ThunderduckDialect
4
+
5
+ [superset.db_engine_specs]
6
+ thunderduck = thunderduck_sqlalchemy.superset_spec:ThunderduckEngineSpec
7
+