Skip to main content

MD_CREATE_FLIGHT

Preview
This feature is in preview and is subject to change.

Creates a new Flight and returns its summary. The initial version is captured from source_code, requirements_txt, config, access_token_name, and flight_secret_names.

You are responsible for the code you run and the packages it installs. Flights does not scan customer code or dependencies. Avoid untrusted packages, pin dependency versions, and treat dependency installs as a supply-chain risk.

Syntax

SELECT * FROM MD_CREATE_FLIGHT(
name := 'my_flight',
source_code := '<python_source>',
schedule_cron := '0 * * * *',
requirements_txt := 'duckdb==1.5.3',
config := MAP {'KEY': 'value'},
access_token_name := '<token_name>',
flight_secret_names := ['secret_name']
);

Parameters

ParameterTypeRequiredDescription
nameVARCHARYesHuman-readable Flight name. Must be non-empty.
access_token_nameVARCHARNoLabel of a MotherDuck access token to run the Flight as. The token value is injected into the Flight as MOTHERDUCK_TOKEN. Omit it to use the default MotherDuck Flights access token for your user. List labels with SELECT * FROM md_access_tokens();.
source_codeVARCHARYesPython source for the Flight. A single-file program, executed as a plain script; end it with if __name__ == "__main__": main() to invoke your entrypoint.
schedule_cronVARCHARNo5-field cron expression in UTC. Omit for an on-demand-only Flight.
requirements_txtVARCHARNoContents of a requirements.txt, one pinned package per line.
configMAP(VARCHAR, VARCHAR)NoNon-secret key/value pairs surfaced to the Flight as environment variables.
flight_secret_namesLIST(VARCHAR)NoList of names of Flight secrets (TYPE FLIGHTS). Each key in a secret's PARAMS map is surfaced to the Flight as an environment variable.
note

source_code is capped at 200 KB and requirements_txt at 20 KB. Load large reference data from object storage at run time instead of embedding it in the source.

Return columns

ColumnTypeDescription
flight_idUUIDUnique identifier of the created Flight.
flight_nameVARCHARThe Flight name.
schedule_cronVARCHARThe cron expression, or NULL for on-demand.
statusVARCHARSchedule status (for example, JOB_STATUS_ACTIVE).
current_versionINTEGERAlways 1 for a newly created Flight.
created_atTIMESTAMP WITH TIME ZONECreation timestamp.
updated_atTIMESTAMP WITH TIME ZONELast update timestamp.

Examples

Minimal Flight, no schedule:

SELECT flight_id
FROM MD_CREATE_FLIGHT(
name := 'heartbeat',
source_code := 'def main(): print("hello")

if __name__ == "__main__":
main()'
);

Scheduled Flight with config, running as a specific access token:

SELECT flight_id, current_version
FROM MD_CREATE_FLIGHT(
name := 'hourly_metrics',
access_token_name := 'analytics_token',
source_code := $$
import duckdb

def main():
con = duckdb.connect("md:")
con.execute("INSERT INTO analytics.hourly_counts SELECT now(), COUNT(*) FROM events")

if __name__ == "__main__":
main()
$$,
requirements_txt := 'duckdb==1.5.3',
schedule_cron := '0 * * * *',
config := MAP {'REGION': 'eu-central-1'}
);