airflow.models.param
¶
Module Contents¶
Classes¶
Class to hold the default value of a Param and rule set to do the validations. Without the rule set |
|
Class to hold all params for dags or tasks. All the keys are strictly string and values |
|
Class that represents a DAG run parameter & binds a simple Param object to a name within a DAG instance, |
- 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 (Optional[str]) – 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]¶
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.
- 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.
- __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
- 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]¶
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) – 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.