SAS Airflow Provider

0.0.23 · active · verified Thu Apr 16

The SAS Airflow Provider enables Apache Airflow users to create tasks for executing SAS Studio Flows and Jobs on a SAS Viya environment. It provides operators to interact with SAS assets, allowing for orchestration and monitoring of SAS processes within Airflow DAGs. Currently at version 0.0.23, the library is under active development with frequent updates addressing new features and improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple Airflow DAG using the `SASStudioOperator` to execute a SAS Studio Flow. Before running, you must configure a 'SAS' connection in the Airflow UI (Admin -> Connections) with `Connection Id` set to `sas_default`, providing your SAS Viya host, login, and password, or an OAuth token in the 'Extra' JSON field. For local testing, mock environment variables are included, but this is not recommended for production.

import pendulum
from airflow.models.dag import DAG
from sas_airflow_provider.operators.sas_studio import SASStudioOperator
import os

# NOTE: For a real deployment, configure your SAS connection in the Airflow UI.
# (Admin -> Connections, Connection Id: 'sas_default', Connection Type: 'SAS')
# Fill in Host, Login, Password or use 'Extra' JSON for OAuth token.
# Example 'Extra' for OAuth: {"token": "your_oauth_token_here"}
# Or for global variable: {"token_variable": "airflow_variable_name"}
# The connection below is for demonstration if env vars are used for local testing.

# Mock environment variables for connection for local testing (NOT PRODUCTION BEST PRACTICE)
os.environ['AIRFLOW_CONN_SAS_DEFAULT'] = (
    'sas://' + 
    os.environ.get('SAS_DEFAULT_LOGIN', 'user') + 
    ':' + 
    os.environ.get('SAS_DEFAULT_PASSWORD', 'password') + 
    '@' + 
    os.environ.get('SAS_DEFAULT_HOST', 'https://your-sas-viya-host.com')
)

with DAG(
    dag_id="sas_studio_flow_example",
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    catchup=False,
    schedule=None,
    tags=["sas", "studio", "example"],
) as dag:
    run_my_sas_flow = SASStudioOperator(
        task_id="run_sas_studio_flow_task",
        path="/Public/my_airflow_test_flow", # Replace with your actual SAS Studio Flow path
        connection_id="sas_default",
        exec_type="flow", # Can also be 'program' for SAS programs
        # Optional: pass macro variables to the flow
        # macro_variables={"input_param": "airflow_value"},
        # Optional: retrieve SAS logs to Airflow
        # job_exec_log=True,
    )

view raw JSON →