DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Treating Web Scrapers Like Production Services
  • When Feature Flags Become Workflows: Configuring Multi-Tenant State Machines
  • The "Just Read the Code" Myth Is Killing Your AI Workflow
  • Kill the Worker, Keep the Research: Build a Recoverable LangGraph Agent on Temporal

Trending

  • Claude Code Superpowers: The 5-Tool Stack That Ends Limits and Context Amnesia
  • Slopsquatting: Building a Scanner That Catches AI-Hallucinated Packages Before They Reach Production
  • Building a Real Pipeline With senro: Monorepos, Caching, and Triggers
  • Beyond the Wall of Charts: How Advanced Observability Displaced the Telemetry Dashboard

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Culture and Methodologies
  3. Team Management
  4. Visualize Airflow Workflows Without Airflow

Visualize Airflow Workflows Without Airflow

During development, it's hard to visualize the connections mentioned in Python code. We take a look at how to validate the DAG without deploying it on Airflow.

By 
Bipin Patwardhan
·
Oct. 05, 21 · Code Snippet
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
6.8K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Apache Airflow has gained a lot of traction in the data processing world. It is a Python-based orchestration tool. When I say "Python-based" it is not just that the application has been developed using Python. The directed acyclic graphs (DAGs) — Airflows term for workflows — are also written as Python. In other words, workflows are code. Many of the popular workflows tools like Informatica and Talend have visual tools that allow developers to lay out the workflow visually. As Airflow workflows are Python code, we are able to visualize the workflow only after uploading it. While this is an acceptable situation, in some cases, it can become problematic because Airflow refuses to load the workflow due to errors. Additionally, during development, it is difficult to visualize all the connections mentioned in Python code.

While looking for a way to visualize the workflow, I came across a Sankey diagram. Not just that, I also came across a gist where Python code has been conveniently packaged into a function. All I had to do was download the gist and include it in my program.

Once I had the drawing code handy, I was left with the task of parsing the Airflow DAG and populating a data structure as needed to draw the chart. Below is the function I wrote. The function looks for the set_upstream function in the code. As set_upstream is used to connect the child task to the parent task, I had to place it properly in a list.

I hope you also enjoy validating the DAG without having to deploy it on Airflow.

Python
 
def process_file(input_directory, filename, output_directory):
    input_file = os.path.join(input_directory, filename)
    output_file = os.path.join(output_directory, filename).replace(".py", ".html")

    data = list()

    input_file = open(input_file, "r")
    for line in input_file.readlines():
        line = line.replace("\n", "")
        if "set_upstream" in line:
            names = line.split(".")
            child = names[0]
            parent = names[1].replace("set_upstream(", "").replace(")", "")
            data.append([parent, child, 1])
    dataframe = pd.DataFrame(data, columns=["source", "target", "count"])
    fig = genSankey(dataframe, cat_cols=["source", "target"], value_cols="count", title=input_file)
    go.Figure.write_html(fig, output_file)


workflow

Published at DZone with permission of Bipin Patwardhan. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Treating Web Scrapers Like Production Services
  • When Feature Flags Become Workflows: Configuring Multi-Tenant State Machines
  • The "Just Read the Code" Myth Is Killing Your AI Workflow
  • Kill the Worker, Keep the Research: Build a Recoverable LangGraph Agent on Temporal

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook