A first DAG

examples/sync.py is a complete DAG: two Python tasks and a command, scheduled for 03:00 in Warsaw. Python 3.14 or newer is required (a command can use a t-string, t"..."); pip install schedr installs the package and the schedr binary.

examples/sync.py
"""The example DAG of archive/PROJECT.md (Native API): extract, load, notify; daily at 03:00."""

from datetime import timedelta

from schedr import CommandOperator, Cron, Dag, StepDefaults, dag_ctx, task

with Dag(
    "sync_customers",
    description="Syncs customers daily at 03:00 Warsaw time: extract, load, notify.",
    trigger=Cron("0 3 * * *", tz="Europe/Warsaw", start="2026-01-01"),
    defaults=StepDefaults(retries=2, retry_delay=timedelta(minutes=5)),
):

    @task
    def extract() -> list[dict[str, str]]:
        return [{"id": "1", "name": "Ada"}, {"id": "2", "name": "Grace"}]

    @task(timeout=timedelta(minutes=10))
    def load(rows: list[dict[str, str]]) -> int:
        print(f"loading {len(rows)} customers")
        return len(rows)

    rows = extract()  # Output[list[dict[str, str]]]
    count = load(rows)  # load depends on extract (data flow)

    CommandOperator(  # depends on load: its command uses `count`
        "notify",
        command=["echo", t"synced {count} customers for {dag_ctx.run.planned_for}"],
    )

with Dag(...) defines one DAG. The string is its ID. Everything created in the block belongs to it, and the block records the DAG when it ends. Calling extract() here does not run extract: it records a task and returns an Output, a reference to the value the task will produce. load(rows) records a second task that receives that value, so load runs after extract. The command is a third task; {count} and {dag_ctx.run.planned_for} are filled in when the run reaches it.

        flowchart LR
    extract --> load --> notify
    

trigger is the schedule. defaults apply to every task in the block; load also sets its own timeout. The other pages cover tasks, data flow, groups, schedules, defaults, the DAG context, run parameters, routing by outcome and mapping.

Check the file, then run it locally. Neither command needs a server:

schedr dags check examples/sync.py
schedr dags test sync_customers --path examples/sync.py --for 2026-10-15T01:00Z

dags check imports each file in its own process and prints one line per file. It uses the configured fork server when usable, as a worker’s parse does. dags test runs one real run, each task in this example in its own process, and prints the logs and a table. Testing a DAG explains both commands and how to run a DAG from pytest. Life of a run follows a run inside schedr.

A file and its DAGs

The file

What an import does

One with Dag(...)

Records that DAG

Several with Dag(...) blocks, one after another

Records each of them. Schedules is a file of five.

No with Dag(...)

Records nothing. Its @task functions can be called in another DAG.

with Dag(...) inside another with Dag(...)

RuntimeError: `with Dag('inner')` inside `with Dag('outer')`: DAGs can't be nested

A DAG ID is explicit and nonempty. It is up to 250 bytes: ASCII letters, digits and _ . - : / #; . and .. alone are not allowed. The same ID in two files of the newest code is a conflict. schedr creates no new runs of that DAG until the conflict is resolved (Parsing and code versions).

A new DAG’s trigger is stored paused. schedr dags unpause <id> lets it create runs (Schedules). A run started by hand starts either way.

Libraries in a root

Python files whose bytes contain schedr are imported by the parser. Other files are copied and hashed with the root, but aren’t loaded on their own. They can still be imported normally by a DAG. For example, a root can contain:

sync.py
mylib/__init__.py
mylib/core.py
mylib/util.py
# mylib/util.py
VALUE = "hello"
# mylib/core.py
from .util import VALUE

def greeting():
    return VALUE

sync.py can import greeting with from mylib.core import greeting and use it in a task. Relative imports resolve in the helper’s package, including when the parser loads a helper that mentions schedr on its own.

A file defining DAGs must mention schedr. Usually from schedr import Dag does that. If it gets Dag through a company module instead, add import schedr or a # schedr comment. Otherwise the file is skipped and its DAGs count as removed. A DAG belongs to the file running its with Dag(...) block. A helper function can build a DAG for the file that calls it.