Skip to content

API Reference parrot.interfaces.duckdb_engine

github-actions[bot] edited this page Dec 2, 2026 · 1 revision

parrot.interfaces.duckdb_engine

View source

In-process DuckDB engine over Arrow (FEAT-713 M1).

A reusable engine with no domain concept: one root connection, Arrow-registered frames and a fresh cursor per call, run off the event loop. duckdb is an optional extra (ai-parrot[duckdb]).

Frame isolation (spec §8 Q1): a frame registered on a DuckDB cursor is a connection-local temporary view, so it is invisible to every other cursor of the same root connection — and a frame registered on the root is not visible to its cursors either. The engine therefore keeps long-lived tables in Python and re-registers them, together with the per-call frames, on the fresh cursor of every call.

Class DuckDBEngine

In-process DuckDB over Arrow: one root connection, per-thread cursors, never a shared cursor.

Parameter Type Default Description
threads int 4 Maximum concurrent executions.
database str ':memory:' DuckDB database path, ":memory:" by default.

Method DuckDBEngine.register

Register a long-lived Arrow table visible to every later call.

register(name: str, table: 'pa.Table', *, replace: bool = True) -> None

Parameter Type Default Description
name str Table name as seen by SQL.
table 'pa.Table' The Arrow table.
replace bool True Replace an existing table of the same name.

Raises:

  • ValueError — The name exists and replace is False.
  • RuntimeError — The engine is closed.

Method DuckDBEngine.unregister

Remove a long-lived table; unknown names are ignored.

unregister(name: str) -> None

Parameter Type Default Description
name str Table name.

Method DuckDBEngine.registered

Names of the long-lived tables, sorted.

registered() -> tuple[str, ...]

Returns: tuple[str, ...]

Method DuckDBEngine.execute

Run sql on a fresh cursor in a worker thread.

frames are registered for this call only and removed afterwards; they shadow long-lived tables of the same name and are invisible to other calls.

execute(sql: str, *, frames: Mapping[str, 'pa.Table'] | None = None, parameters: Sequence[Any] | None = None) -> 'pa.Table'

Parameter Type Default Description
sql str The SQL statement.
frames Mapping[str, 'pa.Table'] | None None Per-call Arrow tables keyed by SQL name.
parameters Sequence[Any] | None None Positional statement parameters.

Returns: 'pa.Table' — The result as an Arrow table.

Raises:

  • RuntimeError — The engine is closed.

Method DuckDBEngine.close

Close the root connection; later calls raise RuntimeError.

close() -> None

Class FrameConversionError

A frame could not be converted to Arrow under the requested numeric rules.

Alias require_extra

Re-exported from parrot._imports.require_extra.

Function to_arrow

Convert a pandas, polars-like or Arrow frame to a pa.Table.

to_arrow(frame: Any, *, decimal_columns: tuple[str, ...] = (), allow_float: bool = False) -> 'pa.Table'

Parameter Type Default Description
frame Any pa.Table (passed through), a pandas DataFrame, or any object exposing to_arrow().
decimal_columns tuple[str, ...] () Columns that must be exact decimals.
allow_float bool False When True, float decimal columns are cast to decimal128(38, 6).

Returns: 'pa.Table' — The Arrow table.

Raises:

  • FrameConversionError — Unsupported frame type, an object-dtype decimal column, or a float decimal column while allow_float is False.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally