airflow.models.param

Module Contents

class airflow.models.param.NoValueSentinel[source]

Sentinel class used to distinguish between None and no passed value

__str__(self)[source]
__repr__(self)[source]
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.

Parameters
  • 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

CLASS_IDENTIFIER = __class[source]
has_value[source]
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.

Parameters
  • 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(self)[source]

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.

Parameters
  • 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.

Parameters

key (str) – The key to fetch

dump(self)[source]

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

validate(self)[source]

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.

Example:

with DAG(…) as dag:

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

Parameters
  • 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: Context)[source]

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

Was this entry helpful?