MotherDuck
The MotherDuck source reads tables, or the result of one SQL query, from MotherDuck over HTTPS with your access token. It is a one-time full load: each table is copied once, and later sync runs do not load new or changed rows. Use it to move MotherDuck data into another warehouse or lake.
Before you begin
- Network access. The machine running Mfd must reach
https://api.motherduck.comover HTTPS. - An access token. Create a MotherDuck access token for a user that can read the database. Mfd only runs the
SELECTstatements you configure.
Configure
Store the token in an environment variable and reference it as ${MOTHERDUCK_TOKEN}. Mfd also reads .env and .env.local next to mfd.yml.
export MOTHERDUCK_TOKEN="your-access-token"from mfd import Config, DataSourceMotherduck, EnvRef, Pipeline
cfg = Config.discover()
src = cfg.data_source(
"motherduck",
DataSourceMotherduck(
motherduck_token=EnvRef("MOTHERDUCK_TOKEN"),
database="analytics",
tables=["users", "events"],
),
)
pipe = cfg.pipeline("motherduck", Pipeline(data_source=src))
cfg.save()mfd connect data-source motherduck \
--pipeline motherduck \
--name motherduck \
--motherduck-token '${MOTHERDUCK_TOKEN}' \
--database analytics \
--tables users \
--tables eventspipelines:
motherduck:
data_source: data_sources.motherduck
data_sources:
motherduck:
Motherduck:
motherduck_token: ${MOTHERDUCK_TOKEN}
database: analytics
tables: ["users", "events"]To load the result of a query instead, set query and omit tables:
data_sources:
motherduck:
Motherduck:
motherduck_token: ${MOTHERDUCK_TOKEN}
database: analytics
query: "SELECT country, count(*) AS users FROM users GROUP BY country"Add a destination to the pipeline (see the connector catalog), then discover the schema and run one sync pass:
from mfd import Session
session = Session(pipe)
session.discover()
session.sync(once=True)mfd discover --pipeline motherduck --log
mfd sync --pipeline motherduck --once --logOptions
Set either tables or query. If you set both, Mfd runs query and ignores tables.
| Key | Type | Default | Description |
|---|---|---|---|
motherduck_token | ${ENV} reference | Required | MotherDuck access token. Must be an environment reference such as ${MOTHERDUCK_TOKEN}. |
database | string | none | Database to run queries in. Also used in destination table names. |
tables | list of strings | none | Tables to read. Each entry is used as written in SELECT * FROM <entry>. |
query | string | none | One SQL SELECT to run instead of tables. |
batch_size_rows | integer | 10000 | Rows per snapshot chunk. YAML may lower this; it cannot raise the ceiling. |
format | string | arrow_ipc | Leave unset, or set arrow_ipc. Any other value is rejected. MotherDuck's SQL HTTP API returns JSON objects; Mfd maps those values onto Arrow types and stores snapshot batches as Arrow IPC. |
batch_size_bytes | integer | none | Not used by this source. |
batch_size_seconds | integer | none | Not used by this source. |
What gets synced
Tables. Each entry in tables, or the single result of query. Mfd streams the HTTP response into Arrow batches of 10,000 rows. A large table does not sit in memory as one result.
Table names. Each table lands in a destination table named motherduck_<database>_<table>: users in analytics becomes motherduck_analytics_users. Without database, the middle part is motherduck. A query lands in motherduck_<database>_query. Mfd lowercases names and replaces characters other than letters, digits, and _ with _.
Types. MotherDuck's SQL HTTP API returns JSON objects. Mfd maps JSON numbers onto Arrow integers or floats, booleans onto booleans, and strings onto text. The first batch of a query freezes each column's Arrow type; later batches that disagree are rejected. Nested JSON arrays and objects are rejected. Run mfd discover to infer column types; see Schema discovery and evolution.
Incremental behaviour. Mfd records each snapshot chunk as loaded once its rows are durably written. Later runs skip those chunks. To reload, run the source under a new pipeline name, which starts with fresh progress.
Deletes. Not captured.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
MotherDuck API HTTP 401 or 403 | The token is wrong, expired, or not exported. | Check that MOTHERDUCK_TOKEN is exported in the shell that runs Mfd and that the token is still valid. |
MotherDuck API HTTP 4xx naming a missing table or catalog | database or a table name is wrong. | Fix database or the entry in tables. |
MotherDuck request: ... | Mfd cannot reach the MotherDuck API. | Allow outbound HTTPS to api.motherduck.com. |
MotherDuck: must specify either 'tables' or 'query' | Neither is set. | Add tables or query. |
| New rows never arrive | Each table loads once. | Run the source under a new pipeline name to take a fresh copy. |
Next steps
- Connector catalog — pick a destination
- MotherDuck destination — land data in MotherDuck
- mfd sync — run once or on a schedule
