Module Contents

class airflow.models.param.NoValueSentinel[source]

Sentinel class used to distinguish between None and no passed value

class airflow.models.param.Param(default: Any = __NO_VALUE_SENTINEL, description: str = None, **kwargs)[source]

Class to hold the default value of a Param and rule set to do the validations. Without the rule set it always validates and returns the default value.

  • default (Any) -- The value this Param object holds

  • description (str) -- Optional help text for the Param

  • schema (dict) -- The validation schema of the Param, if not given then all kwargs except default & description will form the schema

resolve(self, value: Optional[Any] = __NO_VALUE_SENTINEL, suppress_exception: bool = False)[source]

Runs the validations and returns the Param's final value. May raise ValueError on failed validations, or TypeError if no value is passed and no value already exists.

  • value (Optional[Any]) -- The value to be updated for the Param

  • suppress_exception (bool) -- To raise an exception or not when the validations fails. If true and validations fails, the return value would be None.


Dump the Param as a dictionary

class airflow.models.param.ParamsDict(dict_obj: Optional[Dict] = None, suppress_exception: bool = False)[source]

Bases: dict

Class to hold all params for dags or tasks. All the keys are strictly string and values are converted into Param's object if they are not already. This class is to replace param's dictionary implicitly and ideally not needed to be used directly.

__setitem__(self, key: str, value: Any)[source]

Override for dictionary's setitem method. This method make sure that all values are of Param's type only.

  • key (str) -- A key which needs to be inserted or updated in the dict

  • value (Any) -- A value which needs to be set against the key. It could be of any type but will be converted and stored as a Param object eventually.

__getitem__(self, key: str)[source]

Override for dictionary's getitem method. After fetching the key, it would call the resolve method as well on the Param object.


key (str) -- The key to fetch


Dumps the ParamsDict object as a dictionary, while suppressing exceptions

update(self, other_dict: dict)[source]

Override for dictionary's update method. :param other_dict: A dict type object which needs to be merged in the ParamsDict object :type other_dict: dict


Validates & returns all the Params object stored in the dictionary

class airflow.models.param.DagParam(current_dag, name: str, default: Optional[Any] = None)[source]

Class that represents a DAG run parameter & binds a simple Param object to a name within a DAG instance, so that it can be resolved during the run time via {{ context }} dictionary. The ideal use case of this class is to implicitly convert args passed to a method which is being decorated by @dag keyword.

It can be used to parameterize your dags. You can overwrite its value by setting it on conf when you trigger your DagRun.

This can also be used in templates by accessing {{context.params}} dictionary.


with DAG(...) as dag:

EmailOperator(subject=dag.param('subject', 'Hi from Airflow!'))

  • current_dag (airflow.models.DAG) -- Dag being used for parameter.

  • name (str) -- key value which is used to set the parameter

  • default (Any) -- Default value used if no parameter was set.

resolve(self, context: Dict)[source]

Pull DagParam value from DagRun context. This method is run during op.execute().

Was this entry helpful?