Airflow Summit 2025 is coming October 07-09. Register now for early bird ticket!

PythonSensor

The PythonSensor executes an arbitrary callable and waits for its return value to be True.

Tip

The @task.sensor decorator is recommended over the classic PythonSensor to execute Python callables to check for True condition.

tests/system/standard/example_sensor_decorator.py[source]

# Using a sensor operator to wait for the upstream data to be ready.
@task.sensor(poke_interval=60, timeout=3600, mode="reschedule")
def wait_for_upstream() -> PokeReturnValue:
    return PokeReturnValue(is_done=True, xcom_value="xcom_value")

tests/system/standard/example_sensors.py[source]

t9 = PythonSensor(task_id="success_sensor_python", python_callable=success_callable)

t10 = PythonSensor(
    task_id="failure_timeout_sensor_python", timeout=3, soft_fail=True, python_callable=failure_callable
)

Was this entry helpful?