Skip to main content

interloper-duckdb

DuckDB tables as an interloper destination: a DuckDBDestination writing to a local .duckdb file or a MotherDuck database, and the DuckDBConnection that opens it.

Setup

A local file needs nothing but a path; DuckDB creates the file on first write:

from interloper_duckdb import DuckDBConnection

connection = DuckDBConnection(database="./warehouse.duckdb")

A MotherDuck database is named md:<database> and authenticates with a service token from the MotherDuck settings page:

connection = DuckDBConnection(database="md:my_db", motherduck_token="...")

Both fields also load from the environment (DUCKDB_DATABASE, DUCKDB_MOTHERDUCK_TOKEN), so DuckDBConnection() works with no arguments.

Usage

import interloper as il
from interloper_duckdb import DuckDBConnection, DuckDBDestination

destination = DuckDBDestination(
    connection=DuckDBConnection(database="./warehouse.duckdb"),
    default_dataset="raw",
)

In a deployed instance you configure this through the UI instead: add a DuckDB connection, then a DuckDB destination using it.

Datasets are schemas

An asset's dataset is a DuckDB schema. A table lands in the asset's dataset, else in the destination's default_dataset, else in main. The schema and the table are created on the first write, the columns typed from the asset's schema (or from one inferred from the data), and never altered afterwards: a column the table does not have is dropped from the write with a warning.

Field type Column type
bool BOOLEAN
int BIGINT
float DOUBLE
Decimal DECIMAL(38,9)
datetime TIMESTAMP
date DATE
bytes BLOB
str, Any VARCHAR
nested model, list[...] JSON

Partitions

A write replaces what it covers, in one transaction: the whole table for an unpartitioned asset, the rows inside a time partition's bounds (day >= start AND day < end), or the rows equal to a partition's id for any other partitioning. A window deletes each partition it covers and inserts the whole batch once. If the insert fails, the delete is rolled back and the table keeps its previous rows.

One writer per file

A local DuckDB file admits one writing process at a time. Concurrent assets in one process are fine (each write runs on its own cursor), but two processes writing to the same file, such as two pods or a scheduler and a notebook, fail to open it. A connection holds the file from its first use until its process exits, and that includes the connection check the app runs from the API process. Run the instance's writes in one process, or use MotherDuck, which serves many writers.

Querying the tables

The tables are plain DuckDB tables, so any DuckDB client reads them:

duckdb warehouse.duckdb -c 'SELECT * FROM raw.ads_stats LIMIT 10'
import duckdb

duckdb.connect("warehouse.duckdb", read_only=True).sql("SELECT * FROM raw.ads_stats").df()

Another process can open the file only while no process holds it for writing. Open it read_only, so the reader does not lock the instance out in turn.

Docker images

The published interloper images do not ship this package. They are built on Alpine, and DuckDB publishes no musllinux wheels, so installing it there means compiling DuckDB from source. Run it from a glibc-based image (for example a python:3.12-slim base with pip install interloper-duckdb), or anywhere outside the images: the CLI, a notebook, a local scheduler.

Metadata

Release files for interloper-duckdb 0.94.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for interloper-duckdb 0.94.0
File Size Uploaded
interloper_duckdb-0.94.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for interloper-duckdb 0.94.0
File Interpreter ABI Platform
interloper_duckdb-0.94.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.1 kB

Release files / interloper_duckdb-0.94.0.tar.gz

Download URL interloper_duckdb-0.94.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4406b1203d347b8d8d8609a4045907054c388d27d392d73edada8beeaf237ee0
BLAKE2b-256 checksum
How to use checksums
3b910fe578935ec1f0d01e1575d21cf41a6b875ed46000fe911ba1ea35f37495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / interloper_duckdb-0.94.0-py3-none-any.whl

Download URL interloper_duckdb-0.94.0-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17865325638c1615eb627e755d78d98f344fc52a6080782183519c393820b0d6
BLAKE2b-256 checksum
How to use checksums
eb400e7c50be3ff18ff4ad40aff68efd5268a88f7d5a00fbb95b0735917c5e11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.19 {"installer":{"name":"uv","version":"0.12.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

0.94.1

1 release file

This release

0.94.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page