Skip to content
Back to skills

Airflow Dag Patterns

ASecurity

Best practices and conventions for creating and maintaining Airflow DAGs, including task naming, flow patterns, and error handling.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 27, 2026
documentationpython

Security analysis

A100/100

Scanned September 27, 2026

npx -y skills add David-Li0406/meta-skill-evloving --skill airflow-dag-patterns --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Airflow Dag Patterns?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Airflow Dag Patterns
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/david-li0406-airflow-dag-patterns/badge)](https://www.skillsdirectory.com/skills/david-li0406-airflow-dag-patterns)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: airflow-dag-patterns
description: Best practices and conventions for creating and maintaining Airflow DAGs, including task naming, flow patterns, and error handling.
version: 1.0.0
---

# Airflow DAG Patterns

## Main DAG Location

`dags/multi_sport_betting_workflow.py` - Unified workflow for all sports.

## Task Naming Convention

Format: `{action}_{sport}`

Examples:
- `download_games_nba`
- `update_elo_nhl`
- `identify_bets_mlb`
- `place_bets_nfl`

## Sports Configuration

Add/modify sports in `SPORTS_CONFIG`:

```python
SPORTS_CONFIG = {
    "nba": {
        "elo_module": "nba_elo_rating",
        "games_module": "nba_games",
        "kalshi_function": "fetch_nba_markets",
        "elo_threshold": 0.73,
    },
    # Add new sport here following same pattern
}
```

## Task Flow Pattern

```
download_games → load_to_db → update_elo → fetch_markets → identify_bets → place_bets
```

Each sport runs independently in parallel.

## Critical Rules

1. **NEVER trigger manual DAG runs** - Clear tasks and let Airflow schedule
2. **Use PythonOperator** for all tasks:
   ```python
   from airflow.providers.standard.operators.python import PythonOperator

   task = PythonOperator(
       task_id="update_elo_nba",
       python_callable=update_elo_ratings,
       op_kwargs={"sport": "nba"},
   )
   ```

3. **Handle failures gracefully** - Don't let one sport block others:
   ```python
   task = PythonOperator(
       task_id="download_games_nba",
       python_callable=download_games,
       retries=3,
       retry_delay=timedelta(minutes=5),
   )
   ```

## Adding a New Task

1. Define function in DAG file or import from plugins
2. Create PythonOperator with task_id following naming convention
3. Set dependencies with `>>` operator
4. Test DAG parsing: `python dags/multi_sport_betting_workflow.py`

## Common Imports

```python
from airflow import DAG
from airflow.providers.standard.operators.python import PythonOperator
from datetime import datetime, timedelta
```

## Default Args Pattern

```python
default_args = {
    "owner": "airflow",
    "depends_on_past": False,
    "email_on_failure": False,
    "retries": 1,
    "retry_delay": timedelta(minutes=5),
}

with DAG(
    "multi_sport_betting_workflow",
    default_args=default_args,
    schedule="0 10 * * *",  # 10 AM daily
    start_date=datetime(2024, 1, 1),
    catchup=False,
) as dag:
    ...
```

## Files to Reference

- `dags/multi_sport_betting_workflow.py` - Main DAG
- `dags/portfolio_hourly_snapshot.py` - Simpler DAG example

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…