Search
Airflow DAG Factory Pattern
Dynamically generate Apache Airflow DAGs from YAML configuration files. A declarative way of using Airflow.
# Benefits
- Construct DAGs without knowing Python
- Construct DAGs without learning Airflow primitives
- Avoid duplicative code
- done with YAML
# Quickstart Example
The following example demonstrates how to create a simple DAG using dag-factory. We will be generating a DAG with three tasks, where task_2 and task_3 depend on task_1. These tasks will be leveraging the BashOperator to execute simple bash commands.
- To install dag-factory, run the following pip command in your Apache Airflow® environment:
|
|
- Create a YAML configuration file called
config_file.ymland save it within your dags folder:
|
|
We are setting the execution order of the tasks by specifying the dependencies key.
- In the same folder, create a python file called
generate_dags.py. This file is responsible for generating the DAGs from the configuration file and is a one-time setup. You won’t need to modify this file unless you want to add more configuration files or change the configuration file name.
|
|
After a few moments, the DAG will be generated and ready to run in Airflow. Unpause the DAG in the Apache Airflow® UI and watch the tasks execute!
Read more on GitHub - astronomer/dag-factory: Dynamically generate Apache Airflow DAGs from YAML configuration files.
# Further Reads
- Factory Pattern // Abstract Factory // Facade Pattern
- Factory Pattern in Python:
- Data-Asset Reusability Pattern
- Parametric Data Pipeline
Origin: Anna Geller on
LinkedIn
References: Factory Pattern
Created 2024-08-13

