Provider package that enables OpenAI integration for Apache Airflow, including hooks, operators, and triggers for AI-powered data pipelines.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
The version compatibility module provides utilities and constants for handling different versions of Apache Airflow. This module enables the OpenAI provider to maintain compatibility across Airflow 2.x and future 3.x versions by conditionally importing the appropriate base classes and providing version detection capabilities.
Functions and constants for detecting the current Airflow version and enabling version-specific behavior.
def get_base_airflow_version_tuple() -> tuple[int, int, int]:
"""
Get the base Airflow version as a tuple of integers.
Returns:
Tuple containing (major, minor, micro) version numbers
Example:
For Airflow 2.10.2, returns (2, 10, 2)
"""
# Version detection constants
AIRFLOW_V_3_0_PLUS: bool
"""True if running on Airflow 3.0.0 or higher"""
AIRFLOW_V_3_1_PLUS: bool
"""True if running on Airflow 3.1.0 or higher"""Provides the appropriate base classes based on the detected Airflow version, ensuring compatibility across different Airflow versions.
# Conditional imports based on Airflow version
if AIRFLOW_V_3_1_PLUS:
from airflow.sdk import BaseHook
else:
from airflow.hooks.base import BaseHook
if AIRFLOW_V_3_0_PLUS:
from airflow.sdk import BaseOperator
else:
from airflow.models import BaseOperator
class BaseHook:
"""
Base hook class compatible across Airflow versions.
Imported from airflow.sdk (3.1+) or airflow.hooks.base (older versions).
"""
class BaseOperator:
"""
Base operator class compatible across Airflow versions.
Imported from airflow.sdk (3.0+) or airflow.models (older versions).
"""from airflow.providers.openai.version_compat import (
AIRFLOW_V_3_0_PLUS,
AIRFLOW_V_3_1_PLUS,
BaseHook,
BaseOperator,
get_base_airflow_version_tuple
)
# Check current Airflow version
major, minor, micro = get_base_airflow_version_tuple()
print(f"Running on Airflow {major}.{minor}.{micro}")
# Use version-specific features
if AIRFLOW_V_3_0_PLUS:
print("Using Airflow 3.0+ features")
# Use new SDK-based BaseOperator
if AIRFLOW_V_3_1_PLUS:
print("Using Airflow 3.1+ features")
# Use new SDK-based BaseHook
# Always use compatible base classes
class MyHook(BaseHook):
"""This will work on all supported Airflow versions"""
pass
class MyOperator(BaseOperator):
"""This will work on all supported Airflow versions"""
pass# This is the recommended way to import base classes in the OpenAI provider
from airflow.providers.openai.version_compat import BaseHook, BaseOperator
# Instead of directly importing from airflow (which may not be compatible)
# from airflow.hooks.base import BaseHook # Don't do this
# from airflow.models import BaseOperator # Don't do thisThe module uses packaging.version to parse the Airflow version string and create comparable version tuples. This ensures accurate version comparisons across different Airflow release patterns (stable, alpha, beta, rc).
The conditional imports follow a future-forward strategy:
airflow.sdkairflow.hooks.baseairflow.hooks.base and airflow.modelsThis approach ensures the provider works seamlessly across the transition from Airflow 2.x to 3.x while taking advantage of new SDK features when available.
# Version tuple type
VersionTuple = tuple[int, int, int]
# Version constants
AIRFLOW_V_3_0_PLUS: bool
AIRFLOW_V_3_1_PLUS: bool
# Compatible base classes (actual type depends on Airflow version)
BaseHook: type
BaseOperator: typeInstall with Tessl CLI
npx tessl i tessl/pypi-apache-airflow-providers-openai