0

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?

4
  • 1
    Did you install its module? Commented Dec 12, 2022 at 14:03
  • What other modules did you import? Commented Dec 12, 2022 at 14:06
  • PythonSensor was in contrib not in core so it's not the case as dummy. from airflow.contrib.sensors. python_sensor import PythonSensor will work for you but it will tell you it's deprecated. Commented Dec 12, 2022 at 14:45
  • maybe you can add this as an answer @EladKalif it worked. Commented Dec 13, 2022 at 9:21

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You have incorrect import. Use

from airflow.sensors.python import PythonSensor

4 Comments

didn't work either
@x89 what is your Airflow version?
airflow version 1.10.13
For airflow version 1 use from airflow.contrib.sensors.python_sensor import PythonSensor

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.