SQLAlchemy dialect for chDB — the in-process SQL OLAP engine powered by ClickHouse. Unlocks LangChain SQLDatabaseToolkit, CrewAI NL2SQLTool, pandas.read_sql, Apache Superset, and Django ORM.
Project description
chdb-sqlalchemy
SQLAlchemy dialect for chDB — the in-process OLAP SQL engine powered by ClickHouse.
chdb-sqlalchemy lets you use chDB as a SQLAlchemy backend, which in turn unlocks every Python data stack that already speaks SQLAlchemy: Django ORM, Flask-SQLAlchemy, pandas.read_sql(), Apache Superset, LangChain's SQLDatabaseToolkit, CrewAI's NL2SQLTool, and more.
v0.1.0a1 alpha is live on TestPyPI — https://test.pypi.org/project/chdb-sqlalchemy/0.1.0a1/
What this is
chDB already supports DB-API 2.0 through chdb.dbapi. chdb-sqlalchemy adds the layer above that: a dialect that handles connection URIs, table reflection, type mapping, and the introspection contract SQLAlchemy expects.
The dialect is a thin wrapper — chDB's SQL surface is ClickHouse SQL, so most of the dialect's job is type mapping and reflection, not query rewriting.
Install
pip install chdb-sqlalchemy
Usage
Basic connection
from sqlalchemy import create_engine, text
# In-memory
engine = create_engine("chdb:///:memory:")
# Persistent
engine = create_engine("chdb:////tmp/my_chdb")
with engine.connect() as conn:
result = conn.execute(text("SELECT version()"))
print(result.scalar())
With pandas
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine("chdb:////tmp/my_chdb")
df = pd.read_sql("SELECT * FROM file('data.parquet') LIMIT 100", engine)
With LangChain SQLDatabaseToolkit
from langchain_community.utilities import SQLDatabase
from langchain_community.agent_toolkits import SQLDatabaseToolkit
db = SQLDatabase.from_uri("chdb:////tmp/my_chdb")
toolkit = SQLDatabaseToolkit(db=db, llm=llm)
With CrewAI NL2SQLTool
from crewai_tools import NL2SQLTool
nl2sql = NL2SQLTool(db_uri="chdb:////tmp/my_chdb")
URI format
chdb:///:memory: # in-memory session
chdb:////absolute/path/to/dir # persistent session at that directory
chdb:///./relative/path # persistent session at a relative path
There are no host, port, username, or password components — chDB runs in-process. Authentication is delegated to the surrounding application.
Type mapping
| ClickHouse type | SQLAlchemy type |
|---|---|
String, FixedString |
String |
UInt8 … UInt64, Int8 … Int64 |
Integer, BigInteger |
Float32, Float64 |
Float |
Decimal(P, S) |
Numeric |
Date, Date32 |
Date |
DateTime, DateTime64 |
DateTime |
UUID |
Uuid |
Array(T) |
ARRAY |
Tuple(...), Map(K, V) |
JSON |
JSON (native) |
JSON |
Introspection support
Following the LangChain SQLDatabaseToolkit introspection contract, the dialect implements:
get_table_names()— list user tables visible to the session.get_columns()— name, type, nullability, default for each column.get_pk_constraint()— primary key columns (when aMergeTreeORDER BY is the de facto PK).get_foreign_keys()— empty list; chDB does not enforce foreign keys.get_indexes()— primary and secondary indexes fromsystem.data_skipping_indices.
Roadmap
- v0.1 — dialect registration, connection URI, basic type mapping, table reflection for
SQLDatabase.from_uri()andpandas.read_sql(). - v0.2 — full LangChain
SQLDatabaseToolkitand CrewAINL2SQLToolcertification — both rely on introspection that the v0.1 surface does not yet cover. - v0.3 —
remoteSecure()federated table support exposed as SQLAlchemyTableobjects.
Milestones land incrementally; check back here or follow @chdb_io for releases.
License
Apache 2.0 — see LICENSE.
Related
- Main chDB repository: https://github.com/chdb-io/chdb
- chDB documentation: https://clickhouse.com/docs/chdb
- chDB DB-API 2.0 module:
chdb.dbapiin the main repository. - LLM-friendly index: https://clickhouse.com/docs/chdb/llms.txt
- LangChain integration: https://github.com/chdb-io/langchain-chdb
- Community: https://discord.gg/D2Daa2fM5K
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 chdb_sqlalchemy-0.2.0.tar.gz.
File metadata
- Download URL: chdb_sqlalchemy-0.2.0.tar.gz
- Upload date:
- Size: 342.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ed98bc75396445db404b1c3309a5dcfff4d4823a8c393f8c4771b26913d4ab8
|
|
| MD5 |
b73fc2010684441cb970a22034e92bc1
|
|
| BLAKE2b-256 |
bcb7fca7c338edd1c1d4635038412e720682abf555a16304395874e30abf43ba
|
File details
Details for the file chdb_sqlalchemy-0.2.0-py3-none-any.whl.
File metadata
- Download URL: chdb_sqlalchemy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 58.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96f91ead6cb575893db70384612b9e4cef8a62a795c837fa1e433a89848121c4
|
|
| MD5 |
1b3055c4bd2ae92db2bcb10185dd8677
|
|
| BLAKE2b-256 |
70cb943d19d084c59a1f4c5957bcb3cdbe83fc189333967229c792e30aff4916
|