CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-apache-airflow-providers-openai

Provider package that enables OpenAI integration for Apache Airflow, including hooks, operators, and triggers for AI-powered data pipelines.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

version_compat.mddocs/

Version Compatibility

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.

Capabilities

Version Detection

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"""

Compatible Base Classes

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).
    """

Usage Examples

Version-Aware Code

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

Import Pattern

# 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 this

Technical Details

Version Detection Logic

The 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).

Import Strategy

The conditional imports follow a future-forward strategy:

  • Airflow 3.1+: Uses the new SDK-based BaseHook from airflow.sdk
  • Airflow 3.0: Uses SDK-based BaseOperator but legacy BaseHook from airflow.hooks.base
  • Airflow 2.x: Uses legacy imports from airflow.hooks.base and airflow.models

This 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.

Types

# 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: type

Install with Tessl CLI

npx tessl i tessl/pypi-apache-airflow-providers-openai

docs

exceptions.md

hooks.md

index.md

operators.md

triggers.md

version_compat.md

tile.json