0
# Version Compatibility
1
2
Core utilities for detecting Airflow versions and importing version-appropriate modules. This module provides runtime detection of Airflow versions and conditional imports to ensure compatibility across different Airflow releases.
3
4
## Capabilities
5
6
### Version Detection
7
8
Returns the base Airflow version as a tuple of major, minor, and micro version numbers for programmatic version comparison.
9
10
```python { .api }
11
def get_base_airflow_version_tuple() -> tuple[int, int, int]:
12
"""
13
Get the base Airflow version as a tuple.
14
15
Returns:
16
tuple[int, int, int]: Major, minor, micro version numbers
17
"""
18
```
19
20
### Version Constants
21
22
Boolean constants that indicate whether the current Airflow installation meets specific version thresholds.
23
24
```python { .api }
25
AIRFLOW_V_3_0_PLUS: bool # True if Airflow version is 3.0+
26
AIRFLOW_V_3_1_PLUS: bool # True if Airflow version is 3.1+
27
```
28
29
### Compatible BaseOperator
30
31
Version-compatible BaseOperator class that imports from the appropriate module based on the Airflow version.
32
33
```python { .api }
34
class BaseOperator:
35
"""
36
Version-compatible BaseOperator class.
37
38
Imports from airflow.sdk.BaseOperator for Airflow 3.0+
39
Imports from airflow.models.BaseOperator for Airflow < 3.0
40
"""
41
```
42
43
## Usage Examples
44
45
```python
46
from airflow.providers.common.compat.version_compat import (
47
get_base_airflow_version_tuple,
48
AIRFLOW_V_3_0_PLUS,
49
AIRFLOW_V_3_1_PLUS,
50
BaseOperator
51
)
52
53
# Check specific version
54
version = get_base_airflow_version_tuple()
55
if version >= (2, 10, 0):
56
print("Compatible with this provider")
57
58
# Use version flags for conditional logic
59
if AIRFLOW_V_3_0_PLUS:
60
# Use Airflow 3.0+ features
61
from airflow.sdk import SomeNewFeature
62
else:
63
# Use legacy Airflow features
64
from airflow.models import SomeLegacyFeature
65
66
# Create operators using compatible BaseOperator
67
class MyOperator(BaseOperator):
68
def __init__(self, *args, **kwargs):
69
super().__init__(*args, **kwargs)
70
71
def execute(self, context):
72
# Implementation works across versions
73
pass
74
```