airflow.models.variable

Module Contents

airflow.models.variable.log[source]
class airflow.models.variable.Variable(key=None, val=None, description=None)[source]

Bases: airflow.models.base.Base, airflow.utils.log.logging_mixin.LoggingMixin

Variables are a generic way to store and retrieve arbitrary content or settings as a simple key value store within Airflow.

__tablename__ = variable[source]
__NO_DEFAULT_SENTINEL[source]
id[source]
key[source]
_val[source]
description[source]
is_encrypted[source]
val[source]

Get Airflow Variable from Metadata DB and decode it using the Fernet Key

on_db_load(self)[source]
__repr__(self)[source]
get_val(self)[source]

Get Airflow Variable from Metadata DB and decode it using the Fernet Key

set_val(self, value)[source]

Encode the specified value with Fernet Key and store it in Variables Table.

classmethod setdefault(cls, key, default, deserialize_json=False)[source]

Like a Python builtin dict object, setdefault returns the current value for a key, and if it isn't there, stores the default value and returns it.

Parameters
  • key (str) -- Dict key for this Variable

  • default (Mixed) -- Default value to set and return if the variable isn't already in the DB

  • deserialize_json -- Store this as a JSON encoded value in the DB and un-encode it when retrieving a value

Returns

Mixed

classmethod get(cls, key: str, default_var: Any = __NO_DEFAULT_SENTINEL, deserialize_json: bool = False)[source]

Gets a value for an Airflow Variable Key

Parameters
  • key -- Variable Key

  • default_var -- Default value of the Variable if the Variable doesn't exists

  • deserialize_json -- Deserialize the value to a Python dict

classmethod set(cls, key: str, value: Any, serialize_json: bool = False, session: Session = None)[source]

Sets a value for an Airflow Variable with a given Key

Parameters
  • key -- Variable Key

  • value -- Value to set for the Variable

  • serialize_json -- Serialize the value to a JSON string

  • session -- SQL Alchemy Sessions

classmethod delete(cls, key: str, session: Session = None)[source]

Delete an Airflow Variable for a given key

Parameters
  • key -- Variable Key

  • session -- SQL Alchemy Sessions

rotate_fernet_key(self)[source]

Rotate Fernet Key

static get_variable_from_secrets(key: str)[source]

Get Airflow Variable by iterating over all Secret Backends.

Parameters

key -- Variable Key

Returns

Variable Value

Was this entry helpful?