airflow.models.param
¶
Module Contents¶
Classes¶
Class to hold the default value of a Param and rule set to do the validations. |
|
Class to hold all params for dags or tasks. |
|
DAG run parameter reference. |
Functions¶
|
Merge, validate params, and convert them into a simple dict. |
Attributes¶
- 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
- resolve(value=NOTSET, suppress_exception=False)[source]¶
Run 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.
- class airflow.models.param.ParamsDict(dict_obj=None, suppress_exception=False)[source]¶
Bases:
collections.abc.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.
- Parameters
dict_obj (collections.abc.MutableMapping | None) – A dict or dict like object to init ParamsDict
suppress_exception (bool) – Flag to suppress value exceptions while initializing the ParamsDict
- __setitem__(key, value)[source]¶
Override for dictionary’s
setitem
method to ensure 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 to call the resolve method after fetching the key.- Parameters
key (str) – The key to fetch
- 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
- 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.sdk.definitions.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.