DuckDB guide¶
Installation¶
Install the DuckDB extra:
Or with uv:
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¶
Loading from environment variables¶
DuckDBConfig reads all fields from environment variables with the DUCKDB_ prefix:
See also¶
- Configuration — env_prefix, pool tuning
- Pool lifecycle — close_pool, pytest fixtures