Creating an Operator

This lesson demonstrates how to create an operator, import it using a plugin, and then execute it in a DAG file.

Operators represent a task or the actual work performed at each node of a DAG. Airflow can run any kind of workload as long as there’s an operator that encapsulates the logic to perform that workload. Previously, we introduced the BashOperator that executed bash commands. Now we’ll create our own operator as an example, which we’ll call the HelloWorldOperator. It simply prints a message on the console with the argument passed into it.

Remember that all operators are derived from the BaseOperator base class. The code for our HelloWorldOperator appears below. The primary logic of our operator is captured in the execute method, which must be defined in an operator. Remember that since the execute method can retry many times, it must be idempotent.

Get hands-on with 1400+ tech skills courses.