Lightweight wrapper over DuckDB with convenience helpers for DuckLake.
Project description
ducklake-client
Lightweight Python helpers for opening DuckLake connections through DuckDB.
Install
pip install ducklake-client
Open a DuckLake connection
from ducklake_client import ColumnDef, DiskStorage, DuckDBCatalog, DuckLake
lake = DuckLake(
catalog=DuckDBCatalog("metadata.ducklake"),
storage=DiskStorage("data"),
)
try:
lake.schema.create("main")
lake.table.create(
"items",
id=ColumnDef("INTEGER", nullable=False),
name=ColumnDef("VARCHAR"),
)
rows = lake.connection.sql("SELECT * FROM lake.main.items").fetchall()
finally:
lake.close()
DuckLake opens the underlying DuckDB connection lazily on first use. The client installs and loads the DuckDB ducklake and parquet extensions, attaches the catalog as lake, and exposes the native DuckDB connection through connection.
Context manager usage
from ducklake_client import DiskStorage, DuckDBCatalog, DuckLake
with DuckLake(
catalog=DuckDBCatalog("metadata.ducklake"),
storage=DiskStorage("data"),
) as lake:
lake.connection.execute("CREATE TABLE IF NOT EXISTS lake.main.events (id INTEGER)")
lake.connection.execute("INSERT INTO lake.main.events VALUES (?)", [1])
print(lake.connection.sql("SELECT count(*) FROM lake.main.events").fetchone())
Modules
DuckLake-specific helpers are grouped into modules. Native DuckDB behavior stays on lake.connection.
from ducklake_client import ColumnDef, DiskStorage, DuckDBCatalog, DuckLake
with DuckLake(
catalog=DuckDBCatalog("metadata.ducklake"),
storage=DiskStorage("data"),
) as lake:
lake.schema.create("main")
lake.table.create_from_csv(
"nl_train_stations",
"https://blobs.duckdb.org/nl_stations.csv",
)
lake.table.comment("nl_train_stations", "Dutch railway stations")
lake.table.comment(
"nl_train_stations",
"Full station name",
column_name="name_long",
)
tables = lake.table.list()
views = lake.view.list()
info = lake.table.info("nl_train_stations")
Transactions
Use transaction() to automatically begin, commit, or roll back a block on the native DuckDB connection.
from ducklake_client import ColumnDef, DiskStorage, DuckDBCatalog, DuckLake
with DuckLake(
catalog=DuckDBCatalog("metadata.ducklake"),
storage=DiskStorage("data"),
) as lake:
with lake.transaction():
lake.schema.create("main")
lake.table.create(
"items",
id=ColumnDef("INTEGER", nullable=False),
name=ColumnDef("VARCHAR"),
)
lake.connection.execute("INSERT INTO lake.main.items VALUES (?, ?)", [1, "example"])
Configuration
DuckLake requires explicit catalog and storage config objects:
from ducklake_client import DiskStorage, DuckDBCatalog, DuckLake
lake = DuckLake(
catalog=DuckDBCatalog("metadata.ducklake"),
storage=DiskStorage("data"),
)
You can pass DuckDB runtime settings with DuckDBConfig:
from ducklake_client import DiskStorage, DuckDBConfig, DuckDBCatalog, DuckLake
lake = DuckLake(
catalog=DuckDBCatalog("metadata.ducklake"),
storage=DiskStorage("data"),
duckdb=DuckDBConfig(
database=":memory:",
threads=4,
memory_limit="2GB",
),
)
Catalogs can be DuckDBCatalog, SqliteCatalog, or PostgresCatalog. Storage can be DiskStorage or S3Storage.
Project details
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 ducklake_client-0.1.1.tar.gz.
File metadata
- Download URL: ducklake_client-0.1.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2551e0320f97c130eca7d1c8807114de320e8ce9d5e4fd65e434ea30ab90f730
|
|
| MD5 |
8bd50e8d5c627b3600e083bf5333032e
|
|
| BLAKE2b-256 |
ebd9bcff1b00c0a652d75fa631d222b88ccdad6ff69b59e6473172d739ba1638
|
File details
Details for the file ducklake_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ducklake_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 25.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3701b29800d1086569b8cb75325391014af38f5869bfec1179c35d577bec50b4
|
|
| MD5 |
52dad27a2e3c50638362eeb056c3f5bb
|
|
| BLAKE2b-256 |
da775ab04082e3c41ed225fbd2f930312902cd1138f5b7368f82e2d8f200c242
|