DuckLake
Setup
pluginlake.core.ducklake.setup
DuckLake database setup and connection management.
ensure_database(settings)
Create the DuckLake PostgreSQL database if it does not exist.
Connects to the default postgres database to check for and
optionally create the target database. Uses autocommit because
CREATE DATABASE cannot run inside a transaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
DuckLakeSettings
|
DuckLake settings with PostgreSQL connection details. |
required |
Source code in src/pluginlake/core/ducklake/setup.py
create_connection(settings, backend=None)
Create a DuckDB connection with DuckLake attached.
Installs and loads the DuckLake extension, applies any storage-specific DuckDB configuration, and attaches the DuckLake catalog.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
DuckLakeSettings
|
DuckLake settings with PostgreSQL connection details. |
required |
backend
|
StorageBackend | None
|
Storage backend to use. If None, one is resolved from settings. |
None
|
Returns:
| Type | Description |
|---|---|
DuckDBPyConnection
|
A ready-to-use DuckDB connection with the |
Source code in src/pluginlake/core/ducklake/setup.py
setup_ducklake(settings=None)
Run the full DuckLake setup: ensure database exists, then connect.
This is the main entry point called at server startup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
settings
|
DuckLakeSettings | None
|
DuckLake settings. Loaded from environment if None. |
None
|
Returns:
| Type | Description |
|---|---|
DuckDBPyConnection
|
A ready-to-use DuckDB connection with the |
Source code in src/pluginlake/core/ducklake/setup.py
IO Manager
pluginlake.core.ducklake.io_manager
DuckLake IO manager for Dagster assets.
DuckLakeIOManager
Bases: IOManager
Dagster IO manager that persists asset outputs to DuckLake.
Resolves each asset key to a catalog.schema.table path:
- ["condition_era"] → ducklake.main.condition_era
- ["omop", "condition_era"] → ducklake.omop.condition_era
- ["raw", "omop", "condition_era"] → ducklake.raw.omop_condition_era
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
A DuckDB connection with the |
required |
Source code in src/pluginlake/core/ducklake/io_manager.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
__init__(conn)
Initialize with an open DuckDB connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conn
|
DuckDBPyConnection
|
A DuckDB connection with the |
required |
table_ref(asset_key_path)
Derive a fully qualified DuckLake table reference from an asset key.
First segment becomes the schema, remaining segments are joined
with _ to form the table name. Single-segment keys use the
default schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_key_path
|
list[str]
|
The asset key path segments,
e.g. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Fully qualified reference like |
Source code in src/pluginlake/core/ducklake/io_manager.py
handle_output(context, obj)
Write a Polars DataFrame or LazyFrame to a DuckLake table.
Accepts both eager and lazy frames. When a pl.LazyFrame is
provided, DuckDB evaluates the query plan internally via the
native Polars plugin, so data never materializes in Python.
Ensures the target schema exists, registers the frame with DuckDB, and creates or replaces the table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
OutputContext
|
Dagster output context containing the asset key. |
required |
obj
|
DataFrame | LazyFrame
|
The Polars DataFrame or LazyFrame to persist. |
required |
Source code in src/pluginlake/core/ducklake/io_manager.py
load_input(context)
Load a DuckLake table as a Polars LazyFrame.
Uses DuckDB's pl(lazy=True) to return a lazy frame with
projection and filter pushdown support. Polars operations
chained on the result are pushed down to DuckDB at collect
time, enabling DuckLake file pruning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
InputContext
|
Dagster input context containing the upstream asset key. |
required |
Returns:
| Type | Description |
|---|---|
LazyFrame
|
A lazy view of the table. Call |
Source code in src/pluginlake/core/ducklake/io_manager.py
ducklake_io_manager(_init_context)
Dagster IO manager factory that sets up DuckLake and returns an IO manager.
Calls :func:setup_ducklake to ensure the database exists and
attach the DuckLake catalog, then wraps the connection in a
:class:DuckLakeIOManager.
Source code in src/pluginlake/core/ducklake/io_manager.py
Settings
pluginlake.core.config
Configuration for the DuckLake data catalog.
DuckLakeSettings
Bases: BaseSettings
DuckLake catalog settings.
All settings can be overridden via environment variables
prefixed with DUCKLAKE_.
Source code in src/pluginlake/core/config.py
pg_connection_string
property
Build the libpq connection string for DuckLake metadata.
attach_url
property
Build the full DuckLake ATTACH URL.