Displaying complete DAG information and dependencies : Airflow’s “dags show” Command

Apache Airflow

For users seeking to grasp the structure and dependencies of a specific DAG without accessing the web interface, the “dags show” command provides an ideal solution. In this article, we’ll explore the “dags show” command in-depth, walking through its functionalities with a sample DAG.

Overview of the “dags show” Command:

The “dags show” command gives users a visualization of their DAG, detailing tasks, dependencies, and other related information. It can generate the visual representation in multiple formats, such as JSON or Dot (which can be converted to an image format).

Command Syntax:

To utilize the “dags show” command, the following syntax is adopted:

airflow dags show <DAG_ID> [--save] [--filetype <FILETYPE>]

<DAG_ID>: The identifier of the DAG you wish to visualize.
–save: Saves the output to a file.
–filetype <FILETYPE>: The format in which to save the output. Common filetypes include “json” or “dot”.
Consider the following sample DAG, named freshers_in_sample_dag:

from datetime import datetime
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
default_args = {
    'owner': 'airflow',
    'start_date': datetime(2023, 1, 1)
dag = DAG('freshers_in_sample_dag',
          description='A basic tutorial DAG',
start = DummyOperator(task_id='start_task', dag=dag)
middle = DummyOperator(task_id='middle_task', dag=dag)
end = DummyOperator(task_id='end_task', dag=dag)
start >> middle >> end

To generate a visual representation of this DAG, execute:

airflow dags show freshers_in_sample_dag

If you’d like to save the output in a “dot” format, the command would be:

airflow dags show freshers_in_sample_dag --save --filetype dot

This will generate a .dot file, which can be converted to various image formats (like PNG) using external tools like Graphviz.

Interpreting the Output:

For our freshers_in_sample_dag, the “dags show” command will display:

The DAG’s nodes (start_task, middle_task, and end_task).
The directional arrows indicating the order of execution and dependencies between nodes.
Other metadata like the owner, start date, and scheduling interval.

Benefits of Using “dags show”:

Visual Representation: Users can quickly grasp the flow and structure of a DAG, especially beneficial for more complex DAGs.

Dependency Verification: Ensures that tasks are correctly sequenced, and dependencies are set as intended.

Documentation: An excellent way to generate visual documentation for team members or stakeholders unfamiliar with Airflow’s codebase.

Easy Troubleshooting: A visual tool aids in identifying issues with task sequencing or missing dependencies.

Read more on Airflow here :

Author: user

Leave a Reply