PUBLIC PROJECT

AirSQL

A decorator-based SQL execution framework for Apache Airflow.

stars
0
forks
0

AirSQL is a Python framework for running SQL as Apache Airflow tasks, using decorators and Airflow connections.

Decorate a Python function that returns SQL, then call it inside a DAG. AirSQL creates a task to run the query through the configured connection and deliver the result as a DataFrame, table, or file.

The real mechanism

Example SQL query in a DAGPython · AirSQL
from airsql import sql

@sql.dataframe(source_conn='postgres_conn')
def get_active_users():
    return 'SELECT * FROM users WHERE active = true'

# Use in DAG
df_task = get_active_users()
  1. A decorated Python function returns SQL.

  2. Calling the function inside a DAG creates an Airflow task reference.

  3. At execution, the task sends the query through the configured source_conn connection.

  4. The result arrives as a DataFrame for downstream tasks.

df_task is not an immediate DataFrame: it is the task reference inside the DAG, evaluated by Airflow.

The decorators determine how each query returns its result: as a DataFrame, in a table, or in a file.

Key features

  • Decorators for queries that return a DataFrame, write to tables, perform replace, merge/upsert and quality checks
  • Native Airflow connections for PostgreSQL and BigQuery
  • SQL files with Jinja templating
  • SQL sensors with retry logic for BigQuery and PostgreSQL, plus transfer operators for BigQuery, Postgres, and GCS

Requirements

  • Apache Airflow 3; incompatible with Airflow 2.x
  • Python 3.12+
  • Airflow providers for PostgreSQL and BigQuery

Limits

  • AirSQL creates tasks inside an existing DAG; it does not build a complete pipeline on its own

Install

pip install airsql