data.sources.duckdb

data.sources.duckdb

Generic DuckDB-backed data source.

Unlike the network vendors, this reads/writes arbitrary tables in a DuckDB database rather than a fixed schema – point :func:connect at a database file (or :memory:) and pass a table name to read/write.

Multiple independent connections are just multiple :func:connect calls – there is no shared/cached registry::

prod = q.data.sources.duckdb.connect(path="prod.duckdb")
paper = q.data.sources.duckdb.connect(path="paper.duckdb")

Classes

Name Description
DuckDBConnection A single DuckDB connection, opened via :func:connect.

DuckDBConnection

data.sources.duckdb.DuckDBConnection(conn)

A single DuckDB connection, opened via :func:connect.

Methods

Name Description
close Close the underlying connection.
read Read OHLC(V) rows for one symbol from table.
write Insert df into table (created on first write).
close
data.sources.duckdb.DuckDBConnection.close()

Close the underlying connection.

read
data.sources.duckdb.DuckDBConnection.read(
    symbol,
    start_date,
    end_date,
    *,
    table='ohlc',
)

Read OHLC(V) rows for one symbol from table.

write
data.sources.duckdb.DuckDBConnection.write(df, *, table='ohlc')

Insert df into table (created on first write).

Functions

Name Description
connect Open a DuckDB connection for reading/writing OHLC(V) tables.

connect

data.sources.duckdb.connect(path=':memory:', **connect_kwargs)

Open a DuckDB connection for reading/writing OHLC(V) tables.

Parameters

Name Type Description Default
path str | Path Database file, or :memory: for an in-memory database. ':memory:'
**connect_kwargs Any Passed to :func:duckdb.connect. {}
Back to top