airflow.models.variable

Module Contents

Classes

Variable

Variables are a generic way to store and retrieve arbitrary content or settings

Attributes

log

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.

  • property val[source]

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

  • __tablename__ = ‘variable’[source]

  • id[source]

  • key[source]

  • description[source]

  • is_encrypted[source]

  • on_db_load()[source]

  • __repr__()[source]

    Return repr(self).

  • get_val()[source]

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

  • set_val(value)[source]

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

  • classmethod setdefault(key, default, description=None, 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 – Dict key for this Variable

      • default – Default value to set and return if the variable isn’t already in the DB

      • description – Default value to set Description of the Variable

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

      Returns

      Mixed

  • classmethod get(key, default_var=\_NO_DEFAULT_SENTINEL, _deserialize_json=False)[source]

    Gets a value for an Airflow Variable Key

    • Parameters

      • key (str) – Variable Key

      • default_var (Any) – Default value of the Variable if the Variable doesn’t exist

      • deserialize_json (bool) – Deserialize the value to a Python dict

  • static set(key, value, description=None, serialize_json=False, session=None)[source]

    Sets a value for an Airflow Variable with a given Key. This operation will overwrite an existing variable.

    • Parameters

      • key (str) – Variable Key

      • value (Any) – Value to set for the Variable

      • description (str | None) – Description of the Variable

      • serialize_json (bool) – Serialize the value to a JSON string

      • session (sqlalchemy.orm.Session) – SQL Alchemy Sessions

  • static update(key, value, serialize_json=False, session=None)[source]

    Updates a given Airflow Variable with the Provided value

    • Parameters

      • key (str) – Variable Key

      • value (Any) – Value to set for the Variable

      • serialize_json (bool) – Serialize the value to a JSON string

      • session (sqlalchemy.orm.Session) – SQL Alchemy Session

  • static delete(key, session=None)[source]

    Delete an Airflow Variable for a given key

  • rotate_fernet_key()[source]

    Rotate Fernet Key

  • static check_for_write_conflict(key)[source]

    Logs a warning if a variable exists outside of the metastore.

    If we try to write a variable to the metastore while the same key exists in an environment variable or custom secrets backend, then subsequent reads will not read the set value.

    • Parameters

      key (str) – Variable Key

  • static get_variable_from_secrets(key)[source]

    Get Airflow Variable by iterating over all Secret Backends.

    • Parameters

      key (str) – Variable Key

      Returns

      Variable Value

      Return type

      str | None