Registry / workflow / dag-factory

dag-factory

JSON →
library1.1.0pypypi✓ verified 24d ago

dag-factory is an open-source Python library that dynamically generates Apache Airflow DAGs from YAML configuration files. It enables users to define complex data pipelines using a declarative syntax, reducing the need for extensive Python knowledge and promoting consistency across many DAGs. The library is actively maintained by Astronomer, with the current stable version being 1.0.1, and receives regular updates and feature enhancements.

pip install dag-factory
INSTALL
IMPORT
SIG · DAG-FACTORY
D
dag-factory
workflowpythonv1.1.0
Install
28.7s avg
Import
6147ms
Disk
388MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
installs and imports cleanly · install 0.0s · import 6.350s · 390.1MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 28.7s · import 5.945s · 390MB
388MB installed
● package 388MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

load_yaml_dags
from dagfactory import load_yaml_dags
from dagfactory import DagFactory
As of v1.0.0, the `DagFactory` class is private (`_DagFactory`), and `load_yaml_dags` is the recommended entry point for loading DAGs from YAML files.

This quickstart demonstrates how to define an Airflow DAG using a YAML configuration and then use `dag-factory`'s `load_yaml_dags` function to generate it. The `load_yaml_dags` function is designed to be called within an Airflow DAG file, automatically populating the `globals()` dictionary with the generated DAGs, making them discoverable by the Airflow scheduler.

import os from dagfactory import load_yaml_dags # Define a simple YAML configuration for a DAG # In a real Airflow setup, this would be in a .yml file in your DAGs folder # e.g., dags/my_dag.yml yaml_config_content = ''' my_example_dag: default_args: owner: 'airflow' start_date: '2023-01-01' retries: 1 schedule: '@daily' description: 'A simple example DAG from YAML' tasks: start_task: operator: airflow.operators.bash.BashOperator bash_command: 'echo "Starting DAG!"' end_task: operator: airflow.operators.bash.BashOperator bash_command: 'echo "DAG finished."' dependencies: [start_task] ''' # For demonstration, we'll write the YAML to a temporary file. # In a real Airflow environment, this file would be picked up by the scheduler. dags_folder = os.environ.get('AIRFLOW_HOME', './dags') os.makedirs(dags_folder, exist_ok=True) config_filepath = os.path.join(dags_folder, 'my_dag.yml') with open(config_filepath, 'w') as f: f.write(yaml_config_content) # Load DAGs from the YAML file(s) into Airflow's DAG Bag. # This Python file (e.g., dags/dag_generator.py) will be parsed by Airflow. # All YAML files in the dags_folder (or specified path) will be processed. load_yaml_dags(globals_dict=globals(), config_filepath=config_filepath)
Debug
Known issues
breakingAirflow providers (`apache-airflow-providers-http`, `apache-airflow-providers-cncf-kubernetes`) are no longer automatically installed. They are now optional dependencies.
fix
If your DAGs rely on these providers, you must explicitly install them, e.g., `pip install dag-factory[all]` or `pip install dag-factory[kubernetes]`.
affects: >=1.0.0
breakingThe `DagFactory` class is now considered private (`_DagFactory`), and its direct import path (`from dagfactory import DagFactory`) has been removed.
fix
Use the recommended function `from dagfactory import load_yaml_dags` to generate DAGs from your YAML configurations.
affects: >=1.0.0
breakingThe `schedule_interval` parameter in YAML DAG configurations is no longer supported.
fix
Use the `schedule` parameter instead to define DAG schedules.
affects: >=1.0.0
breakingThe `clean_dags()` method has been removed. DAG cleanup is now handled directly by Airflow's configuration (`AIRFLOW__DAG_PROCESSOR__REFRESH_INTERVAL`).
fix
Remove any calls to `example_dag_factory.clean_dags(globals())` from your DAG files. Rely on Airflow's native mechanisms for DAG lifecycle management.
affects: >=1.0.0
breakingSupport for older Airflow and Python versions has been dropped.
fix
Ensure your environment meets the minimum requirements: Python 3.9+ and Apache Airflow 2.4+.
affects: >=0.23.0
breakingSeveral inconsistent YAML parameters (e.g., `dagrun_timeout_sec`, `retry_delay_sec`, `sla_secs`, `execution_delta_secs`, `execution_timeout_secs`) have been removed.
fix
Switch to Airflow's direct equivalents: `dagrun_timeout`, `retry_delay`, `sla`, `execution_delta`, `execution_timeout`. Ensure these are specified using `__type__: datetime.timedelta` for time-related values where applicable.
affects: >=1.0.0
gotchaThe `sla_miss_callback` parameter is removed from `dag_kwargs` for Airflow versions >= 3.1.0.
fix
For Airflow 3.1.0 and above, `sla_miss_callback` is no longer supported directly within `dag-factory`. Airflow 3 deprecates SLA features in favor of 'deadline alerts'. Consider migrating to deadline alerts or Airflow's standard callback mechanisms.
affects: >=1.0.1 (dag-factory), >=3.1.0 (Airflow)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dagfactory'
The 'dag-factory' library is not installed in the Apache Airflow environment where the DAGs are being parsed, or it's not accessible on the Python path.
fix
Ensure 'dag-factory' is included in your Airflow environment's `requirements.txt` file and that these requirements are installed. For Docker-based Airflow, this means rebuilding the image or ensuring the `requirements.txt` is processed during environment setup.
Broken DAG: [/usr/local/airflow/dags/example_dag_factory.py] airflow.exceptions.AirflowException: missing keyword argument 'python_callable'
When defining a PythonOperator in a dag-factory YAML configuration, the `python_callable` parameter is specified incorrectly (e.g., with parentheses as if called directly) or its required arguments are not passed via the `op_kwargs` dictionary. This can also occur due to compatibility issues with specific Airflow provider versions.
fix
Ensure your YAML configuration correctly references the `python_callable` function name without parentheses and passes any necessary arguments using the `op_kwargs` dictionary. Example: 
```yaml
tasks:
  my_task:
    operator: airflow.operators.python.PythonOperator
    python_callable: my_module.my_function # Reference the function
    op_kwargs:
      arg1: "value1"
      arg2: "value2"
```
Broken DAG (or DAGs disappear) due to defaults.yml being parsed as a DAG, often seen as an empty DAG named 'default_args' in the UI.
When `dag-factory`'s `load_yaml_dags` function is configured to load all YAML files recursively from a directory, and a `defaults.yml` or `defaults.yaml` file is present in that directory, `dag-factory` might attempt to parse it as a standalone DAG, leading to parsing errors or an unexpected 'default_args' DAG.
fix
Separate your `defaults.yml` file into a dedicated directory and provide its path using the `defaults_config_path` parameter to `load_yaml_dags`, distinct from your `dag_folder` where other DAG YAMLs are stored. 
Example:
```python
from dagfactory import load_yaml_dags

load_yaml_dags(
    globals_dict=globals(),
    dag_folder="/opt/airflow/dags/configs", # Path to your DAG YAMLs
    defaults_config_path="/opt/airflow/dags/defaults" # Path to defaults.yml
)
```
schedule_interval is no longer supported (in YAML) in dag-factory v1.0.0+ for Airflow 2.x+.
With `dag-factory` v1.0.0 and Airflow 2.x+, the `schedule_interval` parameter in YAML DAG configurations has been deprecated and replaced with `schedule`. Using `schedule_interval` will result in the DAG not being correctly recognized or parsed.
fix
Update your YAML configuration files to use `schedule` instead of `schedule_interval`.
Example:
```yaml
my_dag:
  schedule: "0 0 * * *"
```
Upgrade
Version history
1.1.0latest on PyPI · released May 7, 2026
Audit
Dependencies
apache-airflowrequiredCore dependency for dynamic DAG generation. Requires >=2.4.
apache-airflow-providers-httpoptionalOptional provider, previously enforced. Install if your DAGs use HTTP operations.
apache-airflow-providers-cncf-kubernetesoptionalOptional provider, previously enforced. Install if your DAGs use KubernetesPodOperator.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
dag-factory — pip install dag-factory · libregistry