Skip to main content

Dynamically generates and validates Python Airflow DAG file based on a Jinja2 Template and a YAML configuration file to encourage code re-usability

Project description

What is AirflowDAGGenerator?

Dynamically generates Python Airflow DAG file based on given Jinja2 Template and YAML configuration to encourage reusable code. It also validates the correctness (by checking DAG contains cyclic dependency between tasks, invalid tasks, invalid arguments, typos etc.) of the generated DAG automatically by leveraging airflow DagBag, therefore it ensures the generated DAG is safe to deploy into Airflow.

Why is it useful?

Most of the time the Data processing DAG pipelines are same except the parameters like source, target, schedule interval etc. So having a dynamic DAG generator using a templating language can greatly benefit when you have to manage a large number of pipelines at enterprise level. Also it ensures code re-usability and standardizing the DAG, by having a standardized template. It also improves the maintainability and testing effort.

How is it Implemented?

By leveraging the de-facto templating language used in Airflow itself, that is Jinja2 and the standard YAML configuration to provide the parameters specific to a use case while generating the DAG.

Requirements

Python 3.6 or later

Note: Tested on 3.6, 3.7 and 3.8 python environments, see tox.ini for details

How to use this Package?

  1. First install the package using:

pip install airflowdaggenerator
  1. Airflow Dag Generator should now be available as a command line tool to execute. To verify run

airflowdaggenerator -h
  1. Airflow Dag Generator can also be run as follows:

python -m airflowdaggenerator -h

Sample Usage:

If you have installed the package then:
airflowdaggenerator \
    -config_yml_path path/to/config_yml_file \
    -config_yml_file_name  config_yml_file \
    -template_path path/to/jinja2_template_file \
    -template_file_name jinja2_template_file \
    -dag_path path/to/generated_output_dag_py_file \
    -dag_file_name generated_output_dag_py_file
OR
python -m airflowdaggenerator \
          -config_yml_path path/to/config_yml_file \
          -config_yml_file_name  config_yml_file \
          -template_path path/to/jinja2_template_file \
          -template_file_name jinja2_template_file \
          -dag_path path/to/generated_output_dag_py_file \
          -dag_file_name generated_output_dag_py_file

If you have cloned the project source code then you have sample jinja2 template and YAML configuration file present under tests/data folder, so you can test the behaviour by opening a terminal window under project root directory and run the following command:

python -m airflowdaggenerator \
          -config_yml_path ./tests/data \
          -config_yml_file_name dag_properties.yml \
          -template_path ./tests/data \
          -template_file_name sample_dag_template.py.j2 \
          -dag_path ./tests/data/output \
          -dag_file_name test_dag.py

And you can see that test_dag.py is created under ./tests/data/output folder.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflowdaggenerator-0.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airflowdaggenerator-0.0.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file airflowdaggenerator-0.0.1.tar.gz.

File metadata

  • Download URL: airflowdaggenerator-0.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1

File hashes

Hashes for airflowdaggenerator-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7780fdeedbe356b0be6ab111017f1b3b20424844e6bc6df4ecaaa7d5b7a5edfc
MD5 ab57a0f3b0cc2ed5e119b65062a58b0d
BLAKE2b-256 ffbedebb77f156868c8c236a2702121b991f3804ea8c074556d3cd90ae724c7c

See more details on using hashes here.

File details

Details for the file airflowdaggenerator-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: airflowdaggenerator-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.1

File hashes

Hashes for airflowdaggenerator-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa514912d20ebbc26e19961d39651af8575f57f6b4ac27880d9d0c4db8712f97
MD5 48d28dabcfae85360cab272fc44c88a0
BLAKE2b-256 84f147eaf7f5c9af74905f27e648d1418e9111347ea64dccb87db79f31818e6a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page