airflow.models.param

Module Contents

Classes

Param

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

ParamsDict

Class to hold all params for dags or tasks. All the keys are strictly string and values

DagParam

DAG run parameter reference.

Functions

process_params(dag, task, dag_run, *, suppress_exception)

Merge, validate params, and convert them into a simple dict.

Attributes

logger

airflow.models.param.logger[source]
class airflow.models.param.Param(default=NOTSET, description=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 | None) – Optional help text for the Param

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

property has_value: bool[source]
__version__: ClassVar[int] = 1[source]
CLASS_IDENTIFIER = '__class'[source]
__copy__()[source]
resolve(value=NOTSET, suppress_exception=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. We first check that value is json-serializable; if not, warn. In future release we will require the value to be json-serializable.

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

Dump the Param as a dictionary

serialize()[source]
static deserialize(data, version)[source]
class airflow.models.param.ParamsDict(dict_obj=None, suppress_exception=False)[source]

Bases: MutableMapping[str, Any]

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.

__version__: ClassVar[int] = 1[source]
__slots__ = ['__dict', 'suppress_exception'][source]
__bool__()[source]
__eq__(other)[source]

Return self==value.

__copy__()[source]
__deepcopy__(memo)[source]
__contains__(o)[source]
__len__()[source]
__delitem__(v)[source]
__iter__()[source]
__repr__()[source]

Return repr(self).

__setitem__(key, value)[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__(key)[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

get_param(key)[source]

Get the internal Param object for this key

items()[source]

D.items() -> a set-like object providing a view on D’s items

values()[source]

D.values() -> an object providing a view on D’s values

update(*args, **kwargs)[source]

D.update([E, ]**F) -> None. Update D from mapping/iterable E and F. If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

dump()[source]

Dumps the ParamsDict object as a dictionary, while suppressing exceptions

validate()[source]

Validates & returns all the Params object stored in the dictionary

serialize()[source]
static deserialize(data, version)[source]
class airflow.models.param.DagParam(current_dag, name, default=NOTSET)[source]

Bases: airflow.utils.mixins.ResolveMixin

DAG run parameter reference.

This binds a simple Param object to a name within a DAG instance, so that it can be resolved during the runtime via the {{ context }} dictionary. The ideal use case of this class is to implicitly convert args passed to a method decorated by @dag.

It can be used to parameterize a DAG. 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 }}.

Example:

with DAG(…) as dag:

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

Parameters
  • current_dag (airflow.models.dag.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(context)[source]

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

airflow.models.param.process_params(dag, task, dag_run, *, suppress_exception)[source]

Merge, validate params, and convert them into a simple dict.

Was this entry helpful?