Static Type Checking for Dags
Airflow publishes a set of mypy plugins as a standalone, independently versioned distribution: apache-airflow-mypy.
When to use it
If you run mypy over your Dags, custom operators, or hooks, install the plugins to get accurate
results for Airflow-specific patterns that plain mypy cannot reason about and would otherwise report
as false positives. The plugins teach mypy about:
Typed decorators – decorators that inject keyword arguments at runtime (for example
GoogleBaseHook.fallback_to_default_project_id), somypydoes not flag those arguments as missing.Operator outputs – the
.outputattribute of operators and the return value of@task-decorated functions (anXComArg) are resolved to the underlying runtime type. This lets you wire a task’s output into a downstream task without spurious type errors:@task def f(a: str) -> int: return len(a) @task def g(b: int) -> None: ... g(f("hello")) # mypy understands the output of f() is an int
The package is entirely optional – Airflow does not require it at runtime; it only improves the accuracy of static type checking for Dag authors.
Installation
Install it alongside mypy:
pip install apache-airflow-mypy
The package follows SemVer and is released on its own cadence, so you can adopt it independently of your Airflow version.
Configuration
Enable the plugins in your mypy configuration (mypy.ini, setup.cfg or pyproject.toml):
[mypy]
plugins = airflow_mypy.plugins.decorators, airflow_mypy.plugins.outputs