跳转到主要内容

用于许多DAG和DAG环境的Airflow配置工具

项目描述

airflow-config

Apache Airflow 的工具,用于配置许多DAG和DAG环境

Build Status codecov License PyPI

概述

这个库允许通过 YAML 驱动的Airflow配置,包括DAG、操作符和声明式定义的DAG(类似于 dag-factory)。它使用 PydanticHydraOmegaConf 构建。

考虑以下基本的DAG

from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime, timedelta

with DAG(
    dag_id="test-dag",
    default_args={
        "depends_on_past": False,
        "email": ["my.email@myemail.com"],
        "email_on_failure": False,
        "email_on_retry": False,
        "retries": 0,
    },
    description="test that dag is working properly",
    schedule=timedelta(minutes=1),
    start_date=datetime(2024, 1, 1),
    catchup=False,
    tags=["utility", "test"],
):
    BashOperator(
        task_id="test-task",
        bash_command="echo 'test'",
    )

我们已看到许多可能希望通过配置集中管理的选项,例如基于某些环境概念(例如 devprod 等)。

  • "email": ["my.email@myemail.com"]
  • "email_on_failure": False
  • "email_on_retry": False
  • "retries": 0
  • schedule=timedelta(minutes=1)
  • tags=["utility", "test"]

如果我们想在我们的DAG中更改这些,我们需要修改代码。现在想象一下,我们有成百上千个DAG,这会迅速变得难以控制,特别是由于Airflow DAG是Python代码,我们很容易注入语法错误或尾随逗号或其他常见问题。

现在考虑另一种配置驱动的替代方法

config/config.yaml

# @package _global_
_target_: airflow_config.Configuration
default_args:
  _target_: airflow_config.DefaultArgs
  owner: test
  email: [myemail@myemail.com]
  email_on_failure: false
  email_on_retry: false
  retries: 0
  depends_on_past: false
all_dags:
  _target_: airflow_config.DagArgs
  schedule: "01:00"
  start_date: "2024-01-01"
  catchup: false
  tags: ["utility", "test"]
from airflow import DAG
from airflow.operators.bash import BashOperator
from airflow_config import DAG, load_config

config = load_config()

with DAG(dag_id="test-dag", description="test that dag is working properly", config=config):
    BashOperator(
        task_id="test-task",
        bash_command="echo 'test'",
    )

这有几个优点

  • 无需代码更改即可进行更改,具有静态类型验证
  • 无需复制粘贴即可跨多个DAG进行更改
  • 将DAG集合组织成组,例如通过devprod等环境

配置

更多文档即将推出!

许可证

本软件根据Apache 2.0许可证授权。有关详细信息,请参阅LICENSE文件。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

airflow_config-0.1.3.tar.gz (23.5 kB 查看哈希)

上传时间 源代码

构建分发

airflow_config-0.1.3-py3-none-any.whl (33.4 kB 查看哈希)

上传时间 Python 3

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面