No module named 'airflow.sensors.python_sensor'

Question:

I am trying to use PythonSensor in my dag but I am unable to import it.

from airflow.sensors.python_sensor import PythonSensor
    wait_for_stg_completion = PythonSensor(
        task_id='wait_for_stg_completion',
        python_callable=fetch_stg_qa_status
    )

How can I import it? What else can I try?

Asked By: x89

||

Answers:

You have incorrect import. Use

from airflow.sensors.python import PythonSensor

Answered By: Michal Volešíni

For Airflow < 2.0.0:

from airflow.contrib.sensors.python_sensor import PythonSensor

The PythonSensor is unique in that matter. One would expect to find it in airflow.sensors like other core sensors but that is not the case.

For Airflow >= 2.0.0:

from airflow.sensors.python import PythonSensor

You can also import from contrib but it will show deprecation warning so best to use the updated path.

Answered By: Elad Kalif
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.