Skip to content

DuckDB guide

Installation

Install the DuckDB extra:

pip install adbc-poolhouse[duckdb]

Or with uv:

uv add "adbc-poolhouse[duckdb]"

The extra requires DuckDB 1.4.1 or later. Earlier releases ship an ADBC driver that DuckDBConfig cannot load.

Connection

DuckDBConfig supports file-backed and in-memory databases.

Both default to a pool_size of 5 connections. The pool clones every connection from one source connection, so they all open the same database. With :memory: that means one in-memory database shared by the whole pool: a table one connection creates and commits is visible to the others, including connections the pool opens later to replace ones it recycled. The database lasts until you close the pool with close_pool, or until the managed_pool block exits.

File-backed

from adbc_poolhouse import DuckDBConfig, create_pool

config = DuckDBConfig(database="/tmp/warehouse.db")
pool = create_pool(config)

In-memory

Set up tables and data once, on any connection, and commit. ADBC connections start with autocommit off, so other connections see nothing until you commit.

from adbc_poolhouse import DuckDBConfig, create_pool

config = DuckDBConfig(database=":memory:")
pool = create_pool(config)

with pool.connect() as conn:
    cur = conn.cursor()
    cur.execute("CREATE TABLE events AS SELECT 1 AS id")
    cur.close()
    conn.commit()

Temporary tables and connection-level settings such as SET search_path still belong to one connection, as they do with a file-backed database.

Read-only

config = DuckDBConfig(database="/data/warehouse.db", read_only=True)
pool = create_pool(config)

Loading from environment variables

DuckDBConfig reads all fields from environment variables with the DUCKDB_ prefix:

export DUCKDB_DATABASE=/data/warehouse.db
export DUCKDB_READ_ONLY=false
config = DuckDBConfig()  # reads from env

See also