### Install Project Dependencies with make Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md An alternative method to install all project dependencies, including test dependencies, using a traditional make setup. ```bash make setup ``` -------------------------------- ### Set up Development Environment Source: https://github.com/astronomer/dag-factory/blob/main/AGENTS.md Installs dependencies using uv and activates the virtual environment. Ensure uv and hatch are installed first. ```bash uv sync --dev source .venv/bin/activate pre-commit install ``` -------------------------------- ### Install Airflow Dependencies Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Installs necessary dependencies for Airflow 3 using a setup script. ```bash sh scripts/airflow3/setup.sh ``` -------------------------------- ### Install DAG Factory Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-airflow-standalone.md Install the DAG Factory library into your activated virtual environment. ```command-line pip install dag-factory ``` -------------------------------- ### Install Apache Airflow Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-airflow-standalone.md Install the Apache Airflow package using pip. ```command-line pip install apache-airflow ``` -------------------------------- ### Start Airflow Standalone Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-airflow-standalone.md Command to start a standalone Airflow environment with DAG Factory setup. ```command-line airflow standalone ``` -------------------------------- ### Install Project Dependencies with uv Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Use uv to install all project dependencies, including those for testing. This method ensures fast and reproducible builds using the lockfile. ```bash uv sync --dev ``` -------------------------------- ### Run Integration Tests Setup Source: https://github.com/astronomer/dag-factory/blob/main/AGENTS.md Sets up the environment for integration tests for a specific Python and Airflow version matrix cell. ```bash hatch run tests.py3.11-2.9:test-integration-setup ``` -------------------------------- ### Install Pre-Commit Hooks Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Install pre-commit hooks to ensure code quality checks are performed before committing changes. ```bash pre-commit install ``` -------------------------------- ### Example .airflowignore Content Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/load_yaml_dags.md This example shows the syntax and behavior of an `.airflowignore` file used with `load_yaml_dags` to exclude specific YAML files from DAG discovery. ```text *.yml !keep.yml ignored/ backup/**/*.yaml ``` -------------------------------- ### List-Based DAG Tasks and Task Groups Example Source: https://github.com/astronomer/dag-factory/blob/main/docs/migration_guide.md Example demonstrating list-based configuration for tasks and task groups, promoting better readability and maintenance. Note the use of `dependencies` and `task_group_name`. ```yaml basic_example_dag: schedule: "0 3 * * *" start_date: __type__: datetime.datetime year: 2025 month: 1 day: 1 catchup: false task_groups: - group_name: "example_task_group" tooltip: "this is an example task group" dependencies: [task_1] tasks: - task_id: "task_1" operator: airflow.operators.bash.BashOperator bash_command: "echo 1" - task_id: "task_2" operator: airflow.operators.bash.BashOperator bash_command: "echo 2" dependencies: [task_1] - task_id: "task_3" operator: airflow.operators.bash.BashOperator bash_command: "echo 3" dependencies: [task_1] task_group_name: "example_task_group" ``` -------------------------------- ### Install Airflow from Main Branch Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Installs Airflow directly from the main branch using a dedicated installation script. ```bash sh scripts/airflow3/install_from_main.sh ``` -------------------------------- ### Example DAG Configuration (List Format) Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/configuring_workflows.md Demonstrates the recommended list format for defining tasks and task groups in a DAG Factory YAML configuration. This format is more readable and maintainable. ```yaml --8<-- "dev/dags/example_dag_factory.yml:example_dag_yaml_configuration" ``` -------------------------------- ### Example Object Storage Configuration Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/object_storage.md This YAML configuration demonstrates how to set up object storage within DAG-Factory. It specifies the type of storage and its associated parameters. ```yaml --8<-- "dev/dags/example_object_storage.yml" ``` -------------------------------- ### KubernetesPodOperator DAG Example Source: https://github.com/astronomer/dag-factory/blob/main/docs/migration_guide.md Example of a DAG definition using KubernetesPodOperator. Ensure correct configuration for image, commands, and resource requirements. ```yaml kubernetes_pod_dag: start_date: 2025-01-01 schedule: "@daily" description: "A DAG that runs a simple KubernetesPodOperator task" catchup: false tasks: - task_id: hello-world-pod operator: airflow.providers.cncf.kubernetes.operators.pod.KubernetesPodOperator config_file: "path/to/kube/config" image: "python:3.12-slim" cmds: ["python", "-c"] arguments: ["print('Hello from KubernetesPodOperator!')"] name: "example-pod-task" namespace: "default" get_logs: true container_resources: __type__: kubernetes.client.models.V1ResourceRequirements limits: cpu: "1" memory: "1024Mi" requests: cpu: "0.5" memory: "512Mi" ``` -------------------------------- ### Timedelta Schedule Example Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Configure a fixed interval between DAG runs using timedelta. This example schedules the DAG to run every 6 hours. ```yaml schedule: type: timedelta value: "6h" ``` -------------------------------- ### Start Airflow Project with Astro CLI Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-astro-cli.md Start your Airflow environment using the Astro CLI. This command sets up the Airflow services and makes them accessible. ```commandline astro dev start ``` -------------------------------- ### RelativeDelta Schedule Example Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Utilize relativedelta for calendar-aware scheduling. This example triggers the DAG on the first day of every month. ```yaml schedule: type: relativedelta value: "1 day" ``` -------------------------------- ### Activate Virtual Environment for Main Branch Installation Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Activates the Airflow virtual environment before installing from the main branch. ```bash source scripts/airflow3/env.sh source "$(pwd)/scripts/airflow3/venv-af3/bin/activate" ``` -------------------------------- ### Activate Virtual Environment and Run Airflow Standalone Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Activates the Airflow 3 virtual environment and starts Airflow in standalone mode. This initializes the database and starts the webserver, scheduler, and trigger. ```bash source "$(pwd)/scripts/airflow3/venv-af3/bin/activate" airflow standalone ``` -------------------------------- ### Create Project Directory and Set Airflow Home Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-airflow-standalone.md Create a directory for your project and set the AIRFLOW_HOME environment variable. Also, disable loading example DAGs. ```command-line mkdir dag-factory-quick-start && cd dag-factory-quick-start export AIRFLOW_HOME=$(pwd) export AIRFLOW__CORE__LOAD_EXAMPLES=False ``` -------------------------------- ### Activate Local Python Environment (Traditional) Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Activate the Python virtual environment created by a traditional setup to make project dependencies accessible. ```bash source venv/bin/activate ``` -------------------------------- ### Example DAG Configuration (Dictionary Format) Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/configuring_workflows.md Illustrates the legacy dictionary format for defining tasks and task groups in a DAG Factory YAML configuration. This format is supported for backward compatibility. ```yaml --8<-- "dev/dags/example_dag_factory_tasks_taskgroups_as_dict_format.yml:example_dag_dict_configuration" ``` -------------------------------- ### Example DAG with Dataset Outlets and Inlets Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/datasets.md Configure a DAG to produce and consume datasets by specifying their locations in the 'outlets' and 'inlets' keys. The consumer DAG will run when all specified datasets are updated. ```yaml --8<-- "dev/dags/datasets/example_dag_datasets_outlet_inlet.yml" ``` -------------------------------- ### Run Local Airflow via Docker Source: https://github.com/astronomer/dag-factory/blob/main/AGENTS.md Starts and stops a local Airflow environment using Docker Compose. ```bash make docker-run ``` ```bash make docker-stop ``` -------------------------------- ### DAG with Kubernetes Executor Configuration Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/custom_python_object.md Example demonstrating how to define a DAG with Kubernetes-specific executor configurations using the `__type__` feature for custom Python objects. ```yaml --8<-- "dev/dags/airflow2/example_custom_py_object_dag.yml" ``` -------------------------------- ### Cron Schedule Example Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Use a cron string to define a recurring schedule for your DAG. This example sets the DAG to run daily at midnight. ```yaml schedule: type: cron value: "0 0 * * *" ``` -------------------------------- ### Configure Provider Callback Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/callbacks.md Utilize provider-specific callbacks by specifying the callback function and its arguments. Ensure the provider package is installed and accessible. ```yaml ... - task_id: task_4 operator: airflow.operators.bash_operator.BashOperator bash_command: "echo task_4" on_failure_callback: callback: airflow.providers.slack.notifications.slack.send_slack_notification slack_conn_id: slack_conn_id text: | :red_circle: Task Failed. This task has failed and needs to be addressed. Please remediate this issue ASAP. channel: "#channel" ... ``` -------------------------------- ### Asset-Based Triggering (Nested AND/OR) Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Combine AND and OR conditions for complex asset-based triggering logic. This example triggers if file1 is ready AND (file2 OR file3) are ready. ```yaml schedule: type: assets value: and: - "s3://my-bucket/data/file1.csv" - or: - "s3://my-bucket/data/file2.csv" - "s3://my-bucket/data/file3.csv" ``` -------------------------------- ### Clone DAG Factory Repository Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Clone the DAG Factory repository and navigate into its root directory to begin local development setup. ```bash git clone https://github.com/astronomer/dag-factory.git cd dag-factory/ ``` -------------------------------- ### Example Airflow DAG with Params Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/params.md This YAML snippet demonstrates how to define and use parameters within an Airflow DAG. Use this to configure tasks with dynamic values at runtime. ```yaml --8<-- "dev/dags/airflow2/example_params.yml" ``` -------------------------------- ### Show DAG Factory CLI Version Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/cli.md Display the installed version of DAG Factory. Both the CLI and the library share the same version number. ```bash dagfactory --version ``` -------------------------------- ### Conditional Dataset Scheduling with YAML Syntax Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/datasets.md Configure conditional dataset scheduling using YAML syntax for clarity. This example demonstrates combining dataset conditions with logical operators. ```yaml --8<-- "dev/dags/datasets/example_dataset_yaml_syntax.yml" ``` -------------------------------- ### Timetable Schedule Example Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Implement advanced custom trigger logic using Airflow's timetable feature. This requires a custom timetable class. ```yaml schedule: type: timetable value: "com.example.MyCustomTimetable" ``` -------------------------------- ### Run Integration Tests with Specific Python and Airflow Versions Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Execute integration tests for a specific Python and Airflow version combination. This involves running setup and the main integration test commands. ```bash hatch run tests.py3.11-2.9:test-integration-setup hatch run tests.py3.11-2.9:test-integration ``` -------------------------------- ### Datasets-Based Triggering Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Trigger a DAG based on the readiness of specified datasets. This example uses a nested structure for dataset dependencies. ```yaml schedule: type: datasets value: and: - "my_dataset.v1" - or: - "my_dataset.v2" - "my_dataset.v3" ``` -------------------------------- ### Example DAG with User-Defined Macros Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/jinja2_template.md Shows how to define and use custom Jinja2 macros in a YAML-based DAG definition using DAG-Factory's 'user_defined_macros' parameter. ```yaml --8<-- "dev/dags/airflow3/example_user_defined_macros.yml" ``` -------------------------------- ### Example DAG with Built-in Jinja2 Variables Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/jinja2_template.md Demonstrates the use of Airflow's built-in Jinja2 variables like 'ds', 'run_id', and 'task' within a YAML-based DAG definition. ```yaml --8<-- "dev/dags/airflow2/example_jinja2_template_dag.yml" ``` -------------------------------- ### Asset-Based Triggering with Watchers Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Trigger a DAG based on asset readiness and include watchers for additional checks. This example triggers when file1 is ready and checks for file2. ```yaml schedule: type: assets value: and: - "s3://my-bucket/data/file1.csv" watch: - "s3://my-bucket/data/file2.csv" ``` -------------------------------- ### Usage of default block in YAML for Dynamic DAG Generation Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/defaults.md This example shows how the `default` block can be used for dynamic DAG generation. It defines both `default_args` and default tasks, creating a template that can be used to generate multiple DAGs with consistent structures and arguments, while allowing for individual overrides. ```yaml --8<-- "dev/dags/airflow2/example_dag_factory_default_config.yml" ``` -------------------------------- ### Configure Airflow for Local Development Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Set environment variables to configure Apache Airflow's home directory and disable loading example DAGs. This also sets the directory for locating DAG config files. ```bash export AIRFLOW_HOME=$(pwd)/dev export AIRFLOW__CORE__LOAD_EXAMPLES=false export CONFIG_ROOT_DIR=$AIRFLOW_HOME/dags ``` -------------------------------- ### Conditional Dataset Scheduling with String Condition Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/datasets.md Use a string condition to define complex dataset update requirements for a consumer DAG. This example shows how to specify multiple datasets with logical AND and OR operators. ```yaml --8<-- "dev/dags/datasets/example_dataset_condition_string.yml" ``` -------------------------------- ### Build and Serve Documentation Locally Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Use this command to build and serve the documentation locally for development and review. ```bash hatch run docs:dev ``` -------------------------------- ### Release Documentation to GitHub Pages Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Execute this command to build and deploy the documentation, updating it with the current project version. ```bash hatch run docs:gh-release ``` -------------------------------- ### Build Wheel and Source Distribution Source: https://github.com/astronomer/dag-factory/blob/main/AGENTS.md Builds the project's wheel and sdist packages using uv. ```bash uv build --wheel --sdist ``` -------------------------------- ### Create and Activate Virtual Environment Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-airflow-standalone.md Create and activate a Python virtual environment for your project. ```command-line python3 -m venv dagfactory_env source dagfactory_env/bin/activate ``` -------------------------------- ### Build and Publish Package to PyPI Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Commands to build the package wheels and source distribution, and then publish it to PyPI. Requires a PyPI token. ```bash uv build --wheel --sdist ``` ```bash uv publish --token ``` -------------------------------- ### Load DAGs with .airflowignore Support Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/load_yaml_dags.md Demonstrates loading DAGs from a folder while respecting `.airflowignore` rules. Matching YAML files will be skipped during discovery. ```python from dagfactory import load_yaml_dags load_yaml_dags( globals_dict=globals(), dags_folder="/path/to/your/dags", ) # If /path/to/your/dags/.airflowignore exists, matching YAML files are skipped during discovery. ``` -------------------------------- ### Show DAG Factory CLI Help Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/cli.md Display help information for the DAG Factory command line, listing available options and commands. ```bash dagfactory --help ``` -------------------------------- ### Instantiate DAGs with default configuration path Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/defaults.md Demonstrates how to load DAGs from a specific YAML file while specifying a parent directory for merging default configurations. Precedence is given to `defaults.yml` files closer to the DAG YAML. ```python load_yaml_dags( "a/b/c/some_dags.yml", defaults_config_path="a" ) ``` -------------------------------- ### Build Documentation Strictly Source: https://github.com/astronomer/dag-factory/blob/main/AGENTS.md Performs a strict build of the project's documentation. ```bash hatch run docs:build ``` -------------------------------- ### Initialize Airflow Project with Astro CLI Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-astro-cli.md Create a new directory and initialize your Astro CLI project. This sets up the necessary Airflow files and directories. ```commandline mkdir dag-factory-quick-start && cd dag-factory-quick-start astro dev init ``` -------------------------------- ### Run Airflow Tests Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Activates the Airflow environment and virtual environment, then executes the Airflow tests. ```bash source scripts/airflow3/env.sh source "$(pwd)/scripts/airflow3/venv-af3/bin/activate" sh scripts/airflow3/tests.sh ``` -------------------------------- ### Run Development Environment with Docker Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Build and run the development environment using Docker. This approach builds a DAG Factory wheel, and code changes require restarting the containers. ```bash make docker-run ``` -------------------------------- ### Run All Unit Tests with All Matrix Combinations Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Execute all defined unit tests across all supported Python and Airflow version matrices using hatch. ```bash hatch run tests:test-cov ``` -------------------------------- ### Named Mapping for Dynamic Tasks Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/dynamic_tasks.md Configures custom naming for dynamically mapped tasks using Airflow's 'map_index_template' feature. This example uses a Jinja2 expression with a callable function to set meaningful task names based on extracted data. ```yaml --8<-- "dev/dags/example_map_index_template.yml" ``` -------------------------------- ### Activate Local Python Environment (uv) Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Activate the Python virtual environment created by uv to ensure all project dependencies are available in your current session. ```bash source .venv/bin/activate ``` -------------------------------- ### Define Callback with Parameters Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/callbacks.md Configure a callback with keyword arguments directly in the YAML. This allows for dynamic parameter passing to user-defined functions. ```yaml ... - task_id: task_2 operator: airflow.operators.bash_operator.BashOperator bash_command: "echo task_2" on_success_callback: callback: include.custom_callbacks.output_custom_message param1: "Task status" param2: "Successful!" ... ``` -------------------------------- ### DAG Factory YAML Implementation Source: https://github.com/astronomer/dag-factory/blob/main/docs/comparison/taskflow_api.md Shows how to implement the PyPI stats workflow using DAG Factory and YAML, referencing the same core Python logic. ```yaml from __future__ import annotations from airflow.decorators import dag @dag( schedule=None, start_date=pendulum.datetime(2023, 10, 26, tz="UTC"), catchup=False, tags=["example"], ) def example_pypi_stats_dagfactory(): return DAGFactory("example_pypi_stats_dagfactory.yml", globals()) example_pypi_stats_dagfactory() ``` -------------------------------- ### Run Static Checks with Hatch Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Execute static code analysis and checks using hatch for a specific Python and Airflow version matrix. ```bash hatch run tests.py3.11-2.9:static-check ``` -------------------------------- ### Advanced Dynamic Task Mapping Usage Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/dynamic_tasks.md Illustrates advanced dynamic task mapping techniques including static input mapping, task-generated input mapping using taskflow outputs, and mapping with multiple inputs from different tasks. ```yaml --8<-- "dev/dags/airflow2/example_taskflow.yml" ``` -------------------------------- ### Load DAGs from a Folder Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/load_yaml_dags.md Use this snippet to load all DAG configurations from YAML files within a specified folder. Ensure the folder path is correctly set. ```python from dagfactory import load_yaml_dags # Load DAGs from a folder, e.g. /path/to/dags load_yaml_dags(globals_dict=globals(), dags_folder="/path/to/your/dags") ``` -------------------------------- ### Access PostgreSQL Console Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Connects to the running PostgreSQL container via the command line using psql. ```commandline psql --u postgres ``` -------------------------------- ### Setting DAG-specific arguments in defaults.yml Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/defaults.md Explains how to set DAG-specific arguments like `schedule` and `catchup` at the root level of `defaults.yml`, as they are not supported under `default_args`. ```yaml schedule: 0 1 * * * # set DAG-specific arguments at the root level catchup: False default_args: start_date: '2024-12-31' ... ``` -------------------------------- ### Load DAGs from a Specific YAML File Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/load_yaml_dags.md Use this snippet to load DAG configurations from a single, specific YAML file. Provide the exact file path. ```python from dagfactory import load_yaml_dags # Load DAGs from a specific YAML file load_yaml_dags(globals_dict=globals(), config_filepath="/path/to/your/dag_config.yaml") ``` -------------------------------- ### Plain Airflow Python DAG Implementation Source: https://github.com/astronomer/dag-factory/blob/main/docs/comparison/taskflow_api.md Shows how to implement the PyPI stats workflow using Airflow's TaskFlow API decorators directly in Python. ```python from __future__ import annotations import pendulum from airflow.decorators import dag, task @dag( schedule=None, start_date=pendulum.datetime(2023, 10, 26, tz="UTC"), catchup=False, tags=["example"], ) def example_pypi_stats_plain_airflow(): @task def get_pypi_stats(package_name: str) -> dict: """Fetches PyPI stats for a given package.""" import requests response = requests.get(f"https://api.pypistats.org/v1/quick/{package_name}") response.raise_for_status() return response.json() @task def summarize_stats(stats: dict) -> str: """Summarizes the fetched PyPI stats into a Markdown table.""" from io import StringIO output = StringIO() output.write("| package_name | last_day | last_month | last_week | ") output.write("|:-----------------|-----------:|-------------:|------------:| ") for package_data in stats["data"]["rows"]: output.write( f"| {package_data['package_name']} | {package_data['last_day']} | {package_data['last_month']} | {package_data['last_week']} |\n" ) return output.getvalue() package_names = ["apache-airflow", "astronomer-cosmos", "dag-factory"] stats = get_pypi_stats.partial(package_names=package_names).expand() markdown_table = summarize_stats(stats) example_pypi_stats_plain_airflow() ``` -------------------------------- ### Define Dynamic Tasks with YAML Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/dynamic_tasks.md This configuration defines a 'request' task to generate a list of items and a 'process' task that dynamically creates a task for each item in the list. Use 'expand' for runtime task generation and 'partial' for fixed parameters. ```yaml --8<-- "dev/dags/airflow2/example_dynamic_task_mapping.yml" ``` -------------------------------- ### Load DAGs from YAML with Custom Defaults Path Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/load_yaml_dags.md Load DAGs from a specific YAML file while specifying a custom root directory for default configurations. This is useful when default configurations are not in the same directory as the DAG config file. ```python from dagfactory import load_yaml_dags # Load a single DAG from a YAML file with a custom defaults root directory load_yaml_dags( globals_dict=globals(), config_filepath="/path/to/your/dag_config.yaml", defaults_config_path="/path/to/your/config-root", ) ``` -------------------------------- ### Run Unit Tests with Specific Python and Airflow Versions Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Execute unit tests for a specific Python and Airflow version combination. This command uses hatch to run tests with coverage. ```bash hatch run tests.py3.10-2.9:test-cov ``` -------------------------------- ### Load DAGs from a Dictionary Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/load_yaml_dags.md Use this snippet to load DAG configurations directly from a Python dictionary. This is useful for dynamically generating DAGs or when configurations are managed in memory. ```python from dagfactory import load_yaml_dags # Load DAGs from a dictionary configuration dag_config_dict = { # Your DAG configuration here } load_yaml_dags(globals_dict=globals(), config_dict=dag_config_dict) ``` -------------------------------- ### Define Callback by String Reference Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/callbacks.md Use this method to reference a pre-defined Python function by its import path. Ensure the file containing the function is on the Python sys.path. ```yaml ... - task_id: task_1 operator: airflow.operators.bash_operator.BashOperator bash_command: "echo task_1" on_failure_callback: include.custom_callbacks.output_standard_message ... ``` -------------------------------- ### Use Airflow's direct equivalents for timeout and delay parameters Source: https://github.com/astronomer/dag-factory/blob/main/docs/migration_guide.md Replace deprecated YAML parameters like dagrun_timeout_sec, retry_delay_sec, and sla_secs with Airflow's direct equivalents: dagrun_timeout, retry_delay, and sla. ```yaml dagrun_timeout: __type__: datetime.timedelta seconds: 300 ``` ```yaml retry_delay: __type__: datetime.timedelta seconds: 10 ``` -------------------------------- ### Define Callback by File and Function Name Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/callbacks.md Specify a callback by providing the full path to the Python file and the function name. This is useful when the callback's directory is not in sys.path. ```yaml ... - task_id: task_3 operator: airflow.operators.bash_operator.BashOperator bash_command: "echo task_3" on_retry_callback_name: output_standard_message on_retry_callback_file: /usr/local/airflow/include/custom_callbacks.py ... ``` -------------------------------- ### Run Integration Tests Source: https://github.com/astronomer/dag-factory/blob/main/AGENTS.md Executes integration tests for a specific Python and Airflow version matrix cell. ```bash hatch run tests.py3.11-2.9:test-integration ``` -------------------------------- ### HttpSensor with External Response Check File Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/http_task.md Configure HttpSensor to use a Python file for response checking. Ensure the specified file exists and contains the `check_sensor` function. ```yaml - task_id: task_2 operator: airflow.providers.http.sensors.http.HttpSensor http_conn_id: 'test-http' method: 'GET' response_check_name: check_sensor response_check_file: /path/to/example1/http_conn.py dependencies: [task_1] ``` -------------------------------- ### Create DAGs Folder Source: https://github.com/astronomer/dag-factory/blob/main/docs/getting-started/quick-start-airflow-standalone.md Create a 'dags' folder within your AIRFLOW_HOME directory to store DAG files. ```command-line mkdir dags ``` -------------------------------- ### Update Project Version (Minor) Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Use this hatch command to increment the project's version by a minor release. ```bash hatch version minor ``` -------------------------------- ### Load KubernetesPodOperator DAG Configuration Dynamically Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/kpo.md Load the YAML configuration dynamically in Python to create and run Pods on a Kubernetes cluster using the Airflow Kubernetes Provider. Ensure the YAML file is correctly referenced. ```python --8<-- "dev/dags/kpo.py" ``` -------------------------------- ### Python File Usage of default_args_config_dict Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/defaults.md Shows how to use the `default_args_config_dict` parameter within a Python file to configure default arguments for DAGs generated by DagFactory. ```python --8<-- "dev/dags/example_dag_factory_default_config_dict.py:13:19" ``` -------------------------------- ### Run Pre-Commit Checks Manually Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Manually run all pre-commit checks across all files in the repository to verify code quality and style. ```bash pre-commit run --all-files ``` -------------------------------- ### Defining default_args in defaults.yml Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/defaults.md Illustrates how to keep `default_args` within the `defaults.yml` file, which will be applied to all DAG Factory-generated DAGs. Use with caution as these settings affect all DAGs. ```yaml --8<-- "dev/dags/defaults.yml" ``` -------------------------------- ### Pull Postgres Image Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Pulls the official PostgreSQL Docker image and creates a container named 'postgres'. ```commandline docker run --name postgres -p 5432:5432 -p 5433:5433 -e POSTGRES_PASSWORD=postgres postgres ``` -------------------------------- ### Define timetable using '__type__' annotation Source: https://github.com/astronomer/dag-factory/blob/main/docs/migration_guide.md Custom parsing for 'timetable' is removed. Use the '__type__' annotation to define timetables in YAML, specifying the full Python path and arguments. ```yaml timetable: __type__: airflow.timetables.trigger.CronTriggerTimetable __args__: - 0 1 * * 3 ``` -------------------------------- ### Consolidate logical keys in YAML configuration Source: https://github.com/astronomer/dag-factory/blob/main/docs/migration_guide.md Replace logical and join keys like '!and', '!or', '!join', 'and', 'or' with their consolidated equivalents: '__and__', '__or__', '__join__'. -------------------------------- ### Load Asset Triggered DAGs Dynamically Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/asset.md This Python script dynamically loads DAG configurations defined in YAML, enabling the use of asset-triggered DAGs. Ensure the YAML file is correctly referenced. ```python --8<-- "dev/dags/asset_triggered_dags.py" ``` -------------------------------- ### Opt-out of Telemetry via Environment Variables Source: https://github.com/astronomer/dag-factory/blob/main/PRIVACY_NOTICE.md Alternatively, opt out of analytics by setting either DO_NOT_TRACK to True or SCARF_NO_ANALYTICS to True. ```shell DO_NOT_TRACK=True ``` ```shell SCARF_NO_ANALYTICS=True ``` -------------------------------- ### Define KubernetesPodOperator DAG Configuration Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/kpo.md Define your DAG configuration in a YAML file to specify Kubernetes Pod settings. This is the first step in setting up a KPO task. ```yaml --8<-- "dev/dags/kpo.yml" ``` -------------------------------- ### Load DAGs from Dictionary with Custom Defaults Dictionary Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/load_yaml_dags.md Load DAGs from a Python dictionary, providing custom default arguments also defined in a dictionary. This allows for fine-grained control over default DAG parameters. ```python from dagfactory import load_yaml_dags # Load DAGs with custom default arguments from a dictionary default_args_dict = { # Your default arguments } dag_config_dict = { # Your DAG configuration here } load_yaml_dags( globals_dict=globals(), config_dict=dag_config_dict, defaults_config_dict=default_args_dict, ) ``` -------------------------------- ### Usage of default block for default_args in YAML Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/defaults.md This snippet demonstrates how to use the `default` block to specify `default_args` that will be inherited by all DAGs defined in the same YAML file. This ensures consistent arguments across multiple DAGs. ```yaml --8<-- "dev/dags/airflow2/example_dag_factory_default_args.yml" ``` -------------------------------- ### Set Environment Variables for Integration Tests Source: https://github.com/astronomer/dag-factory/blob/main/docs/contributing/howto.md Configure necessary environment variables before running integration tests. This includes setting Airflow timeouts, home directory, and Python path. ```bash export AIRFLOW__CORE__DAGBAG_IMPORT_TIMEOUT=90 export AIRFLOW_HOME=$(pwd)/dev/ export CONFIG_ROOT_DIR=$(pwd)/dev/dags export PYTHONPATH=$(pwd)/dev/dags:$PYTHONPATH ``` -------------------------------- ### General YAML Format for Python Objects Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/custom_py_object.md Defines a generalized object in YAML. Use '__type__' for the Python import path and other keys for arguments or attributes. '__args__' is used for positional arguments. ```yaml object_name: __type__: : : ... ``` -------------------------------- ### Convert DAGs with CLI Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/cli.md Use the convert command to update DAG files to the latest Airflow 3 syntax. This command processes specified directories and reports on changes made. ```bash dagfactory convert dev/dags/airflow3 ``` -------------------------------- ### DAG Factory YAML Loading Script Source: https://github.com/astronomer/dag-factory/blob/main/docs/comparison/taskflow_api.md A Python script that loads and registers DAGs defined in YAML files using DAG Factory. ```python from __future__ import annotations import pendulum from airflow.decorators import dag from dag_factory import DAGFactory @dag( schedule=None, start_date=pendulum.datetime(2023, 10, 26, tz="UTC"), catchup=False, tags=["example"], ) def example_load_yaml_dags(): return DAGFactory("example_pypi_stats_dagfactory.yml", globals()) example_load_yaml_dags() ``` -------------------------------- ### Define Datetime Object in Python Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/custom_py_object.md Instantiate a Python datetime object. This is useful for setting specific dates in configurations. ```python from datetime import datetime start_date = datetime(2025, 1, 1) ``` -------------------------------- ### Define Airflow Asset Object in Python Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/custom_py_object.md Instantiate an Airflow Asset object. Use this to define data assets with names and URIs. ```python from airflow.sdk import Asset my_asset = Asset(name="sales_report", uri="s3://data/object_storage_ops.csv") ``` -------------------------------- ### Define ObjectStoragePath in YAML Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/custom_py_object.md Represent an ObjectStoragePath object in YAML format using positional arguments. This allows configuration of object storage paths. ```yaml my_obj_storage: __type__: airflow.io.path.ObjectStoragePath __args__: - file:///data/object_storage_ops.csv ``` -------------------------------- ### Asset-Based Triggering (AND Condition) Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/schedule.md Explicitly define an AND condition to trigger a DAG only when all specified assets are ready. ```yaml schedule: type: assets value: and: - "s3://my-bucket/data/file1.csv" - "s3://my-bucket/data/file2.csv" ``` -------------------------------- ### Define Timedelta Object in Python Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/custom_py_object.md Instantiate a Python timedelta object. Use this to specify durations or time differences in configurations. ```python from datetime import timedelta execution_timeout = timedelta(hours=1) ``` -------------------------------- ### Load DAGs with Suffix Configuration Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/multiple_configuration_files.md Use `load_yaml_dags` with a suffix to load relevant YAML files as Airflow DAGs. This is useful for organizing complex DAG structures into multiple configuration files. ```python from dagfactory import load_yaml_dags # load relevant YAML files as airflow DAGs load_yaml_dags(globals_dict=globals(), suffix=['dag.yaml']) ``` -------------------------------- ### Define ObjectStoragePath in Python Source: https://github.com/astronomer/dag-factory/blob/main/docs/configuration/custom_py_object.md Instantiate an ObjectStoragePath object using positional arguments. This is for specifying object storage locations. ```python from airflow.io.path import ObjectStoragePath my_obj_storage = ObjectStoragePath("file:///data/object_storage_ops.csv") ``` -------------------------------- ### DAG Factory YAML for Hacker News Source: https://github.com/astronomer/dag-factory/blob/main/docs/comparison/traditional_operators.md Defines the Hacker News workflow using DAG Factory's YAML syntax. This demonstrates an alternative to traditional Python DAGs. ```yaml from __future__ import annotations import pendulum from airflow.decorators import dag @dag( dag_id="example_hackernews_dagfactory", schedule=None, start_date=pendulum.datetime(2023, 10, 24, tz="UTC"), catchup=False, tags=["example"], ) def example_hackernews_dagfactory(): pass example_hackernews_dagfactory_dag = example_hackernews_dagfactory() ``` -------------------------------- ### Lint YAML Files with DAG Factory Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/cli.md Check if the given directory or file contains valid YAML. Use the --verbose flag for detailed results, including syntax errors. ```bash dagfactory lint some/dir --verbose ``` -------------------------------- ### Create Airflow Database Source: https://github.com/astronomer/dag-factory/blob/main/scripts/airflow3/README.md Creates a new database named 'airflow_db' within the psql interactive terminal. ```sql CREATE DATABASE airflow_db; ``` -------------------------------- ### Define Asset Triggered DAGs Configuration Source: https://github.com/astronomer/dag-factory/blob/main/docs/features/asset.md This YAML file defines the configuration for DAGs that are triggered by asset events. It specifies the DAGs to load and their associated configurations. ```yaml --8<-- "dev/dags/asset_triggered_dags.yml" ```