Overview
When you runpython my_flow.py dagster create dagster_defs.py, the compiler analyzes your flow and emits a complete, self-contained Dagster definitions file. This file includes all the plumbing needed to run your flow through Dagster.
Command Syntax
Common Options
| Option | Description |
|---|---|
--name <job_name> | Override the Dagster job name (defaults to flow class name) |
--with <decorator> | Inject step decorators at deploy time (e.g., --with=sandbox) |
--tag <key:value> | Attach Metaflow tags forwarded to every step subprocess |
--workflow-timeout <seconds> | Cap the total wall-clock time for the job |
--namespace <name> | Set the Metaflow namespace (for flow isolation) |
Example
The generated file is deterministic — running the same command twice produces identical output (modulo timestamp comments).
Generated File Structure
From the compiler source (dagster_compiler.py:10-19), the file contains nine sections:
1. Preamble + Imports
A header comment identifies the source flow and regeneration command:2. Constants
Metadata and datastore settings are baked in at compile time (fromdagster_compiler.py:76-98):
These constants ensure every step subprocess uses the same backend configuration as the compile-time environment, preventing accidental metadata or datastore mismatches.
3. Helpers
From the preamble template (dagster_compiler.py:100-561):
4. Config Class (if flow has Parameters)
Fromdagster_compiler.py:747-771:
deploy_time_eval() and infers types (bool, int, float, str).
5. Ops (one per step)
Fromdagster_compiler.py:843-1203, each step generates an @op:
6. Job Definition
The@job function wires together all ops in topological order:
7. Schedule (if @schedule decorator present)
If your flow has a @schedule decorator, the compiler emits a ScheduleDefinition:
Metaflow’s
@schedule decorator supports daily, hourly, weekly, or raw cron strings. The compiler translates these to Dagster’s cron format.8. Sensors (from @trigger / @trigger_on_finish)
If your flow has event-driven decorators:
@trigger(event=...), the compiler emits a stub with a TODO comment:
9. Definitions
The finalDefinitions object bundles everything:
dagster dev -f train_dagster.py.
Metadata and Datastore Baking
The compiler embeds your Metaflow backend configuration at compile time (fromdagster_compiler.py:659-676):
metaflow step subprocess uses the same backend as the deployment environment.
Example: Using Remote S3 Datastore
Before runningdagster create, configure Metaflow:
Decorator Forwarding
Fromdagster_compiler.py:678-697, the compiler extracts decorator information for each step:
STEP_DECORATOR_SPECS
Full decorator specs from the flow source (e.g., retry:times=3):
_run_step() to invoke runtime_step_cli() hooks (for decorators like @sandbox or @conda).
STEP_WITH_DECORATORS
Decorators injected at deploy time via --with=<decorator>, plus @resources hints:
metaflow step command as --with=... flags.
Resume Support
If you generate a file with--origin-run-id (used by dagster resume), the ORIGIN_RUN_ID constant is set:
_run_init and _run_step call then passes --clone-run-id <ORIGIN_RUN_ID> to Metaflow, which reuses completed tasks and re-executes only failed/pending steps.
Generated Code Example
Here’s a minimal generated file forLinearFlow:
Next Steps
How It Works
Understand the compilation and execution process
Graph Shapes
Learn how different Metaflow patterns translate to Dagster