Skip to content

DuckDB

Installation

pip install "toolfront[duckdb]"

Connection URL

Connect to DuckDB by passing a connection URL to the Database constructor:

1
2
3
4
5
from toolfront import Database

db = Database(url="duckdb://")

revenue = db.ask("What's our total revenue this month?")
1
2
3
4
5
from toolfront import Database

db = Database(url="duckdb://{path/to/database.db}")

revenue = db.ask("What's our total revenue this month?")

Connection Parameters

Alternatively, connect using the Database.from_duckdb() method with parameters:

from toolfront import Database

# In-memory database
db = Database.from_duckdb()

# File-based database with extensions
db = Database.from_duckdb(
    database="mydata.duckdb",
    extensions=["httpfs", "parquet"],
    config={"threads": 4}
)

revenue = db.ask("What's our total revenue this month?")
PARAMETER DESCRIPTION
database

Path to a duckdb database. Default is ':memory:'.

TYPE: str DEFAULT: ':memory:'

read_only

Whether the database is read-only. Default is False.

TYPE: bool DEFAULT: False

extensions

A list of duckdb extensions to install/load upon connection.

TYPE: list[str] DEFAULT: None

config

DuckDB configuration parameters. See the DuckDB configuration documentation for possible configuration values.

TYPE: dict[str, Any] DEFAULT: None

match_schema

Regex pattern to filter schemas. Mutually exclusive with match_tables.

TYPE: str DEFAULT: None

match_tables

Regex pattern to filter tables. Mutually exclusive with match_schema.

TYPE: str DEFAULT: None

**kwargs

Additional arguments passed to the DBAPI connection call.

TYPE: Any DEFAULT: {}