How to import Airflow's PostgresOperator

Viewed 3123

I'm trying to import the PostgresOperator from the airflow package:

from airflow.providers.postgres.operators.postgres import PostgresOperator

But I'm getting the following error: Cannot find reference 'postgres' in imported module airflow.providers.

2 Answers

The solution was to run the following in the terminal, using the project's virtualenv: pip install 'apache-airflow[postgres]'.

Please notice that it won't work if you don't wrap the name of the package between single-quotes.

Use:

from airflow.operators.postgres_operator import PostgresOperator
Related