The Apache Airflow Task SDK provides Python-native interfaces for defining Directed Acyclic Graphs (DAGs), executing tasks in isolated subprocesses, and interacting with Airflow resources at runtime. Its primary goal is to decouple DAG authoring from Airflow internals, offering a forward-compatible and stable interface across Airflow versions. The library is currently at version 1.2.0 and receives frequent updates, aligning with the release cadence of Apache Airflow 3.x.
pip install apache-airflow-task-sdkVerified import paths — ran on the pinned version, not inferred.
This quickstart defines a simple Airflow DAG using the Task SDK's `@dag` and `@task` decorators. The `my_task` function is decorated as an Airflow task, and `example_simplest_dag` is a decorated function that defines the DAG structure and invokes the task. This pattern decouples DAG authoring from Airflow internals.
Refactor task code to use the Task SDK's interfaces for interacting with Airflow resources (e.g., Connections, Variables, XComs) instead of direct database access.
Update all DAG and task-related imports to use the `airflow.sdk` namespace. For example, `from airflow.models.dag import DAG` becomes `from airflow.sdk import DAG`.
Migrate SubDAG implementations to use TaskGroups for grouping tasks, and explore Assets and Data Aware Scheduling for managing complex data dependencies.
Transition from using SLAs to implementing Deadline Alerts for monitoring task and DAG adherence to time constraints.
Explicitly set `catchup=True` in your DAG definition if you intend for it to run for past missed schedules. Otherwise, review your DAGs to ensure `catchup=False` is the desired behavior.
Update task definitions to import `get_current_context` from `airflow.sdk` and call it within the task function to retrieve the execution context.
Rename your script to avoid naming conflicts with the Airflow package.
Ensure you are using the latest version of the Airflow Task SDK and check for any known issues or updates related to this import error.
Ensure that the 'dags' folder is included in your Python path or use relative imports to access modules within the 'dags' directory.
Ensure the required module is installed in the Airflow environment using `pip install your_custom_module`. If it's a local module, verify its path is correctly added to `PYTHONPATH` or placed in a discoverable location for Airflow's DAG processor.
Update your DAG imports to use the Task SDK namespace: `from airflow.sdk import dag, task`.