{"library":"apache-airflow-providers-common-compat","code":"import os\n\n# This example demonstrates how a custom Airflow component (e.g., an operator or hook)\n# would use the common.compat.sdk to ensure compatibility across Airflow versions.\n# In a real scenario, this would typically be part of a custom provider package's code.\n\n# Ensure Airflow environment variables are set for a minimal run, e.g., for 'conf'\n# In a live Airflow environment, these are usually handled by the Airflow setup.\nif 'AIRFLOW_HOME' not in os.environ:\n    os.environ['AIRFLOW_HOME'] = os.path.expanduser('~/airflow')\n\ntry:\n    # Attempt to import common Airflow components via the compatibility layer\n    from airflow.providers.common.compat.sdk import BaseOperator, conf, task\n    print(\"Successfully imported BaseOperator, conf, and task via common.compat.sdk\")\n\n    # Example usage (simplified, as these are typically used within an operator/hook definition)\n    # The actual 'conf' object would be more complex and used for configuration access\n    print(f\"Retrieved BaseOperator from compat layer: {BaseOperator.__name__}\")\n    print(f\"Retrieved conf object from compat layer: {conf}\")\n    print(f\"Retrieved task decorator from compat layer: {task}\")\n\n    # Minimal example of using a compat-imported BaseOperator (not runnable as a full DAG)\n    class MyCompatOperator(BaseOperator):\n        def __init__(self, **kwargs):\n            super().__init__(task_id='my_compat_task', **kwargs)\n\n    my_op_instance = MyCompatOperator()\n    print(f\"Instantiated a custom operator using compat BaseOperator: {my_op_instance.task_id}\")\n\nexcept ImportError as e:\n    print(f\"Failed to import from common.compat.sdk: {e}\")\n    print(\"Ensure 'apache-airflow-providers-common-compat' is installed and Airflow is properly set up.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how a developer building a custom Airflow provider or plugin would use `airflow.providers.common.compat.sdk` to import core Airflow components like `BaseOperator`, `conf`, or `@task` in a way that is compatible across different major versions of Apache Airflow (e.g., Airflow 2.x and 3.x). This code snippet shows successful imports and basic instantiation of a class using `BaseOperator` obtained from the compatibility layer.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}