Skip to main content

DAG Tool

pypi version python support version size

A Friendly Airflow DAG Build Tool for Data Engineer with YAML file template.

Airflow Version Supported Noted
>2.7.1,<3.0.0 ✅ Common version support for Airflow version 2.x.x
>=3.x.x ✅ Common version support for Airflow version 3.x.x

Feature Supported:

  • ✅ JSON Schema Validation (Set IDE with json-schema.json)
  • 💚 Allow Passing Variable to DAG Template before build

From my opinion, a data Engineer should focus on the user requirement instead of focusing on the Python code when it need creates a new DAG in our Airflow application.

So, this project focus for this plain to make sure that all DAG can readable and easy to maintain with the same standard when we want to scale up and out the Airflow application support 10 to 1000 DAGs.

File Structure:

dags/
├── { domain }/
│     ├── { module-dags }/
│     │     ├── __init__.py
│     │     ├── dag.yml
│     │     ├── variables.yml
│     │     └── assets/
│     │         ├── dag-schema-mapping.json
│     │         └── dag-transform-query.sql
│     │
│     └── { module-dags }/
│           ├── __init__.py

📦 Installation

uv pip install -U common

📍 Usage

This DAG generator engine need you define the dag.yml file and set engine object to get the current path on __init__.py file.

DAG Template

On the dag-transaction.yml file:

name: transaction
schedule: "@daily"
owner: "de-oncall@email.com,de@email.com"
start_date: "{{ vars('start_date') }}"
catchup: "{{ vars('catchup') }}"
tags:
  - "domain:sales"
  - "tier:1"
  - "schedule:daily"
tasks:
  - task: start
    op: empty

  - group: etl_master
    upstream: start
    tasks:
      - type: extract
        op: python
        caller: get_api_data
        params:
          path: gcs://{{ vars("project_id") }}/sales/master/date/{{ exec_date | fmt('%y') }}

      - task: transform
        upstream: extract
        op: operator
        operator_name: gcs_transform_data
        params:
          path: gcs://{{ vars("project_id") }}/landing/master/date/{{ exec_date | fmt('%y') }}

      - task: sink
        upstream: transform
        op: common
        uses: write_iceberg
        params:
          path: gcs://{{ vars("project_id") }}

  - task: end
    upstream: etl_master
    op: empty

On the __inti__.py file:

"""# SALES DAG

This DAG will extract data from Google Cloud Storage to Google BigQuery LakeHouse
via DuckDB engine.

> This DAG is the temp DAG for ingest data to GCP.
"""
from dagtool import Factory, ToolModel, BuildContext

from airflow.models import DAG
from airflow.utils.dates import days_ago
from airflow.utils.task_group import TaskGroup
from airflow.operators.empty import EmptyOperator

# NOTE: Some external provider operator object.
from airflow.providers.google.cloud.operators import MockGCSTransformData
from pydantic import Field

# NOTE: Some function that want to use with PythonOperator
def get_api_data(path: str) -> dict[str, list[str]]:
    return {"data": [f"src://{path}/table/1", f"src://{path}/table/2"]}

# NOTE: Some common task that create any Airflow Task instance object.
class WriteIcebergTool(ToolModel):
    """Custom Task for user defined inside of template path."""

    path: str = Field(description="An Iceberg path.")

    def build(
        self,
        dag: DAG,
        task_group: TaskGroup | None = None,
        build_context: BuildContext | None = None,
    ) -> TaskGroup:
        with TaskGroup(
            group_id="write_iceberg",
            parent_group=task_group,
            dag=dag,
        ) as tg:
            t1 = EmptyOperator(task_id="prepare", dag=dag)
            t2 = EmptyOperator(task_id="write", dag=dag)
            t2.set_upstream(t1)
        return tg


factory = Factory(
    name="sales",
    path=__file__,
    docs=__doc__,
    operators={"gcs_transform_data": MockGCSTransformData},
    python_callers={"get_api_data": get_api_data},
    tools={"write_iceberg": WriteIcebergTool},
)
factory.build_airflow_dags_to_globals(
    gb=globals(),
    default_args={"start_date": days_ago(2)},
)

Output:

The DAG that was built from this package will have the name is, sales_transaction.

🎯 Roadmaps

  • Support Airflow Parameter
  • Support Airflow Asset
  • Support Backfill for Hotfix
  • Support Declarative template

💬 Contribute

I do not think this project will go around the world because it has specific propose, and you can create by your coding without this project dependency for long term solution. So, on this time, you can open the GitHub issue on this project 🙌 for fix bug or request new feature if you want it.

Metadata

Release files for dagtool 0.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dagtool 0.0.13
File Size Uploaded
dagtool-0.0.13.tar.gz 40.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dagtool 0.0.13
File Interpreter ABI Platform
dagtool-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 80.8 kB

Release files / dagtool-0.0.13.tar.gz

Download URL dagtool-0.0.13.tar.gz
Size 40.4 kB
Tags Source
SHA-256 checksum
How to use checksums
78c2421357cea7225a576f6f7dd42bd36db84ee698e778063893ccbc14ae8b38
BLAKE2b-256 checksum
How to use checksums
d2b1c7fa21b8d5349a38190c30f491e0e745e5678925e974b9a5cf897cacfbf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2025.

Transparency log

Release files / dagtool-0.0.13-py3-none-any.whl

Download URL dagtool-0.0.13-py3-none-any.whl
Size 40.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1f6b30347be7580716e37c0dc9b5a825f806cfdf63581ea14291f60cf4055ef
BLAKE2b-256 checksum
How to use checksums
9d3957322e3d4a1ef64c48338594e2dab52fc3859ff9017aaf7b5c884951897b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 22, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 release files

0.0.12

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page