ivanshamaev/de-agent-skills/airflow-dag-factory

Claude Code and agent skill by ivanshamaev/de-agent-skills

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when building, reviewing, debugging, or scaling Apache Airflow DAGs declaratively with dag-factory YAML configs — including project setup, loader configuration, defaults hierarchy, custom/provider operators, dynamic task mapping, datasets/assets, callbacks, TaskFlow decorators, Jinja2 templating, environment variables, YAML DRY patterns, large-scale multi-DAG generation, CI/CD linting, and migration from pre-1.0.

Install

npx vskill@latest install ivanshamaev/de-agent-skills/airflow-dag-factory

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

The same SKILL.md was published earlier as ivanshamaev/de-agent-skills/airflow-dag-factory.

Airflow DAG Factory

Build Apache Airflow DAGs declaratively with dag-factory — a library that turns YAML configuration files into Airflow DAGs with no boilerplate Python.

Package: dag-factory on PyPI
Repo: https://github.com/astronomer/dag-factory
Docs: https://astronomer.github.io/dag-factory/latest/
Targets: dag-factory v1.0+, Python 3.10+, Airflow 2.9+ (Airflow 3 supported)
For pre-1.0 projects, read reference/migration.md before applying any guidance here.

When to Use dag-factory

ScenarioRecommendation
Low-code, repetitive DAG patterns (same operators, varying params)dag-factory — ideal
Many similar DAGs that differ only in config valuesdag-factory — generate many DAGs from one YAML
Complex branching, dynamic Python logic, Pydantic validationPython DAGs or blueprint skill instead
Full TaskFlow pipeline in Pythonauthoring-dags skill instead
Existing dag-factory <1.0 projectFollow reference/migration.md first

Quick Decision Table

User RequestGo to
"Create a YAML DAG" / "Convert Python DAG to YAML"Defining a DAG in YAML
"Set up dag-factory in my project"Project Setup
"Share defaults across DAGs / set start_date once"Defaults
"Custom operator / KPO / Slack / Snowflake"Custom & Provider Operators
"Dynamic / mapped tasks / expand / partial"Dynamic Task Mapping
"Schedule on dataset / outlets / inlets"Datasets and Assets
"Add callback / Slack on failure"Callbacks
"Use @task decorator / TaskFlow in YAML"TaskFlow API
"Use env vars in YAML"Environment Variables
"Jinja2 templates in YAML"Jinja2 Templating
"Generate 50 DAGs from one template"Large-Scale Patterns
"DRY config / reuse blocks across DAGs"DRY with YAML Anchors
"Lint / validate YAML"Validation Commands
"Migrate from Airflow 2 → 3"Validation Commands (dagfactory convert)
"Migrate from dag-factory <1.0"reference/migration.md
Errors / broken DAGTroubleshooting

Project Setup

1. Install

Add to requirements.txt:

dag-factory>=1.0.0

dag-factory does not install Airflow providers. Install providers your YAML references explicitly:

apache-airflow-providers-slack
apache-airflow-providers-cncf-kubernetes
apache-airflow-providers-http
2. Create the Loader File

Create dags/load_dags.py. Airflow discovers DAGs from this file:

python
import os
from pathlib import Path
from dagfactory import load_yaml_dags
CONFIG_ROOT_DIR = Path(os.getenv("CONFIG_ROOT_DIR", "/usr/local/airflow/dags/"))
# Option A: load every *.yml / *.yaml under a folder (recommended)
load_yaml_dags(globals_dict=globals(), dags_folder=str(CONFIG_ROOT_DIR))
# Option B: load a single file
# load_yaml_dags(globals_dict=globals(), config_filepath=str(CONFIG_ROOT_DIR / "my_dag.yml"))
# Option C: load from a Python dict (useful for testing)
# load_yaml_dags(globals_dict=globals(), config_dict={...})

globals_dict=globals() is required — generated DAG objects must be registered into the module namespace for Airflow to discover them.

3. Recommended Project Structure
project/
├── dags/
│ ├── load_dags.py # single loader — only Python file in dags/
│ ├── defaults.yml # global defaults (schedule, owner, retries, start_date)
│ ├── ingestion/
│ │ ├── defaults.yml # team-level overrides
│ │ ├── orders.yml
│ │ └── customers.yml
│ └── transformation/
│ ├── defaults.yml
│ └── mart_revenue.yml
├── include/
│ ├── callbacks/
│ │ └── slack.py # callback functions
│ └── tasks/
│ └── transforms.py # Python callables for PythonOperator / @task
└── requirements.txt

Key rules:

  • Keep dags/ clean — only the loader .py and YAML/YML config files.
  • Put all Python callables, SQL, and helpers in include/ — the DAG processor ignores this directory by default.
  • Never put defaults.yml logic directly in dags_folder root if you point dags_folder at that directory — dag-factory may try to parse it as a DAG config. Use defaults_config_path to separate it, or use a default: block inside each YAML file.
4. Verify
bash
dagfactory --version
dagfactory lint dags/

Defining a DAG in YAML

Each top-level YAML key (other than default) defines one DAG. The key becomes the dag_id.

yaml
# dags/ingestion/orders.yml
default:
default_args:
start_date: 2025-01-01
owner: data-team
retries: 2
catchup: false
schedule: "0 3 * * *"
ingest_orders:
description: "Load orders from source to staging"
tags: [ingestion, orders]
task_groups:
- group_name: validate
tooltip: "Data quality checks"
dependencies: [extract]
tasks:
- task_id: extract
operator: airflow.operators.bash.BashOperator
bash_command: "echo extracting orders"
- task_id: load
operator: airflow.operators.bash.BashOperator
bash_command: "echo loading orders"
dependencies: [extract]
- task_id: check_row_count
operator: airflow.operators.bash.BashOperator
bash_command: "echo checking row count"
dependencies: [load]
task_group_name: validate
- task_id: check_nulls
operator: airflow.operators.bash.BashOperator
bash_command: "echo checking nulls"
dependencies: [load]
task_group_name: validate
Key Fields Reference
FieldLevelDescription
defaultfileShared args applied to every DAG in this file
default_argsDAG or defaultStandard Airflow default_args (owner, retries, start_date, …)
scheduleDAGCron string, preset (@daily), Dataset URI list, or __type__ timetable
catchupDAGBoolean; default Airflow behavior is true — set false explicitly
descriptionDAGHuman-readable description
tagsDAGList of tag strings
max_active_runsDAGMax concurrent DAG runs
dagrun_timeoutDAG__type__: datetime.timedelta block
tasksDAGList of task dicts; each needs task_id + operator
operatortaskFull Python import path to operator class
dependenciestask/groupList of upstream task_ids or group_names
task_groupsDAGList of group dicts; each needs group_name
task_group_nametaskAssigns task to a task group
Tasks do not need to be listed in dependency order — dag-factory resolves topology from dependencies.
List vs Dict Format

Use the list format (shown above) for all new code — it is the v1.0 standard and required for task groups.

The legacy dict format (where tasks is a dict keyed by task_id) still works for backward compatibility but is not recommended.


Defaults

Four layers of defaults, in precedence order (highest wins):

PrioritySourceHow
1 (highest)Individual DAG blockdefault_args: or DAG-level keys inside the DAG
2default: block in the same YAML fileTop-level default: key
3defaults_config_dict=Passed as Python dict to load_yaml_dags
4 (lowest)defaults.yml fileAuto-detected walking up the dir tree, or explicit defaults_config_path=
default: Block (same file)

Best for templates with multiple DAGs in one file:

yaml
default:
default_args:
owner: analytics
start_date: 2025-01-01
retries: 1
retry_delay:
__type__: datetime.timedelta
minutes: 5
catchup: false
schedule: "@daily"
tags: [analytics]
revenue_daily:
description: "Daily revenue mart"
tasks:
- task_id: build
operator: airflow.operators.bash.BashOperator
bash_command: "dbt run --select mart_revenue"
users_daily:
description: "Daily user mart"
tasks:
- task_id: build
operator: airflow.operators.bash.BashOperator
bash_command: "dbt run --select mart_users"
defaults.yml File (hierarchical, team-wide)

Place defaults.yml files in the directory tree. dag-factory merges them walking from the DAG file up to the root, with files closer to the DAG winning:

yaml
# dags/defaults.yml — global
schedule: "0 6 * * *"
catchup: false
default_args:
start_date: '2025-01-01'
owner: platform
retries: 2
yaml
# dags/ingestion/defaults.yml — team-level overrides
default_args:
owner: ingestion-team
retries: 3
tags: [ingestion]

A DAG inside dags/ingestion/ inherits both files, with ingestion/defaults.yml values winning.

Important: set defaults_config_path in the loader to the highest ancestor folder you want merged:

python
load_yaml_dags(
globals_dict=globals(),
dags_folder="/usr/local/airflow/dags/",
defaults_config_path="/usr/local/airflow/dags/", # walk from here
)

Custom & Provider Operators

Reference any operator by its full Python import path. All other task keys become __init__ kwargs.

yaml
tasks:
- task_id: wait_for_api
operator: airflow.providers.http.sensors.http.HttpSensor
http_conn_id: api_conn
endpoint: /health
request_params: {}
response_check:
__type__: builtins.str
__args__: ["lambda response: response.json()['status'] == 'ok'"]
poke_interval: 30
timeout: 600
mode: reschedule
- task_id: run_snowflake
operator: airflow.providers.snowflake.operators.snowflake.SnowflakeOperator
snowflake_conn_id: snowflake_default
sql: "CALL my_procedure()"
warehouse: TRANSFORM_WH
database: ANALYTICS
schema: PUBLIC
- task_id: custom_op
operator: include.operators.MyCustomOperator
my_param: "value"

For Airflow 3, prefer airflow.providers.standard.operators.* over the legacy airflow.operators.* — use dagfactory convert to auto-rewrite:

bash
dagfactory convert dags/ --override
KubernetesPodOperator

Use __type__ for nested k8s objects (legacy auto-casting was removed in v1.0):

yaml
tasks:
- task_id: run_pod
operator: airflow.providers.cncf.kubernetes.operators.pod.KubernetesPodOperator
image: python:3.12-slim
cmds: ["python", "-c"]
arguments: ["print('hello from pod')"]
name: my-pod
namespace: default
get_logs: true
is_delete_operator_pod: true
container_resources:
__type__: kubernetes.client.models.V1ResourceRequirements
limits:
cpu: "1"
memory: "1Gi"
requests:
cpu: "500m"
memory: "512Mi"
env_vars:
- __type__: kubernetes.client.models.V1EnvVar
name: MY_ENV
value: "my_value"

Dynamic Task Mapping

Use expand and partial keys. Two reference syntaxes — do not mix them:

SyntaxUse case
task_id.outputInside expand.op_args / expand.op_kwargs (XCom-style)
+task_idAs a bare expand value; for TaskFlow decorator tasks
PythonOperator — XCom-style expand
yaml
tasks:
- task_id: get_ids
operator: airflow.providers.standard.operators.python.PythonOperator
python_callable_name: fetch_ids
python_callable_file: /usr/local/airflow/include/tasks/extract.py

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/ivanshamaev/de-agent-skills/airflow-dag-factory/badge)](https://verified-skill.com/skills/ivanshamaev/de-agent-skills/airflow-dag-factory)

Something wrong with this skill or its page? Tell us.