Skip to main content

Flights

A Flight is a Python program that MotherDuck schedules and runs, with direct access to your databases. It can do whatever Python can: call external APIs, use any PyPI package, process files or run custom logic.

Flights overview​

MotherDuck runs two compute planes against the same storage:

Ducklings run your SQL. They're per-user (see Hypertenancy) and start in under ~100ms.

The Python runtime runs your scheduled Python. You provide the Flight's source code, and each run gets its own isolated runtime that executes the source as a plain script and exits, so end the script with if __name__ == "__main__": main(). A run starts from the Flight's schedule or an MD_RUN_FLIGHT call.

A Flight reaches your data the same way any DuckDB client does: the Python runtime opens an md: connection, which routes through a Duckling that executes the SQL against your databases. MotherDuck injects an access token into the Flight's environment so the connection works without you embedding credentials.

The relationship to SQL​

Flights and SQL talk to each other in both directions.

From Python to SQL. A Flight uses the DuckDB Python client to run any query you can express in SQL:

import duckdb

def main():
con = duckdb.connect("md:")
con.execute("INSERT INTO sales.daily_totals SELECT * FROM read_parquet('s3://incoming/today.parquet')")

if __name__ == "__main__":
main()

Anything in the SQL reference is available here: aggregations, MotherDuck table functions, attach commands, and so on.

From SQL to Flights. The Flights SQL functions, such as MD_CREATE_FLIGHT and MD_LIST_FLIGHT_RUNS, let you create, schedule, and monitor Flights from anywhere you run SQL: a DuckDB CLI, your BI tool, or another Flight.

When to pick which. A reasonable rule of thumb:

  • Stay in SQL for a one-off query, or one you already schedule elsewhere.
  • Use a Flight to run a query on a schedule with retries and a run history, or when the work goes beyond SQL: calling an external service, installing a Python package, reading a format SQL can't, or chaining steps.

What you can build with Flights​

  • Ingest. Pull data from external sources (Postgres, BigQuery, Snowflake, S3, APIs) and write it to MotherDuck tables. dltHub's dlt library is the recommended ingest library: it gives you a declarative pipeline with schema evolution, incremental loading, and a MotherDuck destination.
  • Transform. Read MotherDuck data, run Python-heavy transformations (machine-learning features, geospatial work), and write the result back. When the transformation is graph-shaped, dbt with the dbt-duckdb adapter is the recommended approach.
  • AI enrichment. Run LLM and embedding work over your data on a schedule. Call MotherDuck's prompt and embedding functions from SQL to classify, summarize, or extract fields row by row, or call a model API from Python and write the results back.
  • Export and delivery. Write query results to object storage as Parquet or CSV — a scheduled drop in S3, Google Cloud Storage, or Azure Blob Storage for a partner or a downstream pipeline to pick up.
  • Reverse ETL and notifications. Read from MotherDuck and push to a downstream operational system: post a daily summary to Slack, sync an aggregate to a SaaS tool, update a record in a CRM.

Availability and plan limits​

Flights run on every MotherDuck plan. On the Lite plan, your Flight limits depend on whether a credit card is on file. Business and Enterprise are pay-as-you-go.

Lite (with limits)Lite (unlimited)Business & Enterprise
Flight compute30 minutes per dayDrawn from your monthly compute allocation, then pay-as-you-goPay-as-you-go
Usage windowDaily (resets each day)MonthlyMonthly
SchedulingManual (on-demand) onlyManual and scheduled (cron)Manual and scheduled (cron)
Maximum runtime per run1 hour1 hour8 hours (default)
Concurrent runs1UnlimitedUnlimited
Flight instance sizesF4F4, F16F4, F16, F32
Flights you can createUnlimitedUnlimitedUnlimited

On Lite (with limits), runs pause at the daily limit until the next day. Usage beyond the compute allocation is billed at Flight rates.

Flight instance sizes​

Each run gets an instance size (F4, F16, or F32) that sets the CPU and memory of the Flight's Python runtime. SQL sent over md: runs on a Duckling, not on the Flight. See Flight sizes for specs, defaults, and pricing.

Creating a Flight​

You can create a Flight with the MotherDuck MCP server: describe the job in natural language, and the agent writes the Python, sets the schedule, and runs it for you with the MCP's Flight tools (create_flight, edit_flight_source, run_flight, and the rest).

You can also use MD_CREATE_FLIGHT and the other Flight SQL functions.

Integrating with the tools you already use​

  • dltHub for ingest. Generate or hand-write a dlt pipeline that uses MotherDuck as the destination, then deploy it as a Flight.
  • DuckDB Community Extensions that MotherDuck doesn't load, such as BigQuery, Snowflake, or YAML. See Run a local DuckDB with community extensions.
  • Anything on PyPI. Pull in any pip-installable package through requirements.txt.
  • MCP and AI agents. Agents create, edit, and run Flights through the MotherDuck MCP Server.

You are responsible for the code you run and the packages it installs. Flights doesn't scan your code or dependencies for vulnerabilities or malicious intent, so avoid untrusted packages and pin dependency versions.

Beyond Python​

A Flight is a Linux process that runs your Python program, with shell access through subprocess. That opens up two patterns worth knowing.

Install and call system binaries​

git ships preinstalled in the runtime, so cloning a repository needs no setup. For other command-line tools (ffmpeg, Playwright, anything available as a Debian package), use subprocess to install them with apt-get first.

import subprocess

def main():
subprocess.run(["git", "clone", "https://github.com/example/repo"], check=True)
subprocess.run(["apt-get", "install", "-y", "ffmpeg"], check=True)

if __name__ == "__main__":
main()

Run a local DuckDB with community extensions​

A Flight can also open an in-process DuckDB connection to load community extensions that MotherDuck's server-side runtime doesn't support. For example, the bigquery and snowflake extensions let a Flight read directly from another warehouse and write the result to MotherDuck.

import duckdb

def main():
local = duckdb.connect() # local in-process DuckDB
local.execute("INSTALL bigquery FROM community; LOAD bigquery;")
local.execute("ATTACH 'project=my-project' AS bq (TYPE bigquery, READ_ONLY)")

# read from BigQuery into the Flight, then write the result to MotherDuck
events = local.sql("SELECT * FROM bq.analytics.events").df()

md = duckdb.connect("md:")
md.execute("INSERT INTO raw.events SELECT * FROM events")

if __name__ == "__main__":
main()

Keep heavy compute outside the Flight runtime: let the source warehouse and MotherDuck do the heavy lifting, and let the Flight move data between them.

How Flights are scoped​

  • A Flight runs as a triggered job. A run starts from its schedule or a MD_RUN_FLIGHT call, executes the script to completion, and exits; a single run can be long or short.
  • One Flight is one process. A run isn't a worker pool with a queue or distributed state. Fan out by calling MD_RUN_FLIGHT from a Flight, or use a Python thread pool within a run; you write the coordination. Flights fit MotherDuck-centric work where data, schedule, and compute live together. For workflows across many external systems, an orchestrator like Airflow or Prefect fits better.
  • Runs are unattended. You read a run's output afterward from its logs rather than stepping through it live. To explore data interactively, run queries in the SQL editor instead.
  • A Flight belongs to the user who created it. Only the owner can edit or delete it; others need a run grant to run it. Admins can see every Flight and cancel its runs.

Connecting to external systems​

A Flight often reaches out to a system you control: a Postgres database, an API, or object storage behind a firewall. When that system restricts inbound traffic by IP, allowlist the addresses below so the Flight can connect.

Outbound connections from a Flight come from a fixed set of IP addresses, determined by your MotherDuck region. To check your organization's region, run SELECT region FROM md_user_info();.

RegionIP addresses
US East (N. Virginia) us-east-154.145.91.19, 32.195.40.107
US West (Oregon) us-west-254.214.239.87, 54.148.103.191
Europe (Frankfurt) eu-central-13.124.118.210, 63.177.162.15
Europe (Dublin) eu-west-154.77.125.86, 18.200.12.243
Asia Pacific (Tokyo) ap-northeast-135.73.139.124, 57.182.73.46
Asia Pacific (Sydney) ap-southeast-254.66.229.129, 32.236.248.88

These addresses are for outbound connections only. A Flight does not accept inbound connections, so there is nothing to open in the other direction.