blob: 4bd6eb9475cf6affd39836e9092bff69756e6aca [file] [log] [blame]
:py:mod:`airflow.models.variable`
=================================
.. py:module:: airflow.models.variable
Module Contents
---------------
Classes
~~~~~~~
.. autoapisummary::
airflow.models.variable.Variable
Attributes
~~~~~~~~~~
.. autoapisummary::
airflow.models.variable.log
.. py:data:: log
.. py:class:: Variable(key=None, val=None, description=None)
Bases: :py:obj:`airflow.models.base.Base`, :py:obj:`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.
.. py:attribute:: __tablename__
:annotation: = variable
.. py:attribute:: id
.. py:attribute:: key
.. py:attribute:: description
.. py:attribute:: is_encrypted
.. py:method:: on_db_load(self)
.. py:method:: __repr__(self)
Return repr(self).
.. py:method:: get_val(self)
Get Airflow Variable from Metadata DB and decode it using the Fernet Key
.. py:method:: set_val(self, value)
Encode the specified value with Fernet Key and store it in Variables Table.
.. py:method:: val(cls)
:property:
Get Airflow Variable from Metadata DB and decode it using the Fernet Key
.. py:method:: setdefault(cls, key, default, description=None, deserialize_json=False)
:classmethod:
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.
:param key: Dict key for this Variable
:type key: str
:param default: Default value to set and return if the variable
isn't already in the DB
:type default: Mixed
:param deserialize_json: Store this as a JSON encoded value in the DB
and un-encode it when retrieving a value
:return: Mixed
.. py:method:: get(cls, key: str, default_var: Any = __NO_DEFAULT_SENTINEL, deserialize_json: bool = False) -> Any
:classmethod:
Gets a value for an Airflow Variable Key
:param key: Variable Key
:param default_var: Default value of the Variable if the Variable doesn't exists
:param deserialize_json: Deserialize the value to a Python dict
.. py:method:: set(cls, key: str, value: Any, description: str = None, serialize_json: bool = False, session: sqlalchemy.orm.Session = None)
:classmethod:
Sets a value for an Airflow Variable with a given Key.
This operation will overwrite an existing variable.
:param key: Variable Key
:param value: Value to set for the Variable
:param description: Value to set for the Variable
:param serialize_json: Serialize the value to a JSON string
:param session: SQL Alchemy Sessions
.. py:method:: update(cls, key: str, value: Any, serialize_json: bool = False, session: sqlalchemy.orm.Session = None)
:classmethod:
Updates a given Airflow Variable with the Provided value
:param key: Variable Key
:param value: Value to set for the Variable
:param serialize_json: Serialize the value to a JSON string
:param session: SQL Alchemy Session
.. py:method:: delete(cls, key: str, session: sqlalchemy.orm.Session = None) -> int
:classmethod:
Delete an Airflow Variable for a given key
:param key: Variable Key
:param session: SQL Alchemy Sessions
.. py:method:: rotate_fernet_key(self)
Rotate Fernet Key
.. py:method:: check_for_write_conflict(key: str) -> None
:staticmethod:
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.
:param key: Variable Key
.. py:method:: get_variable_from_secrets(key: str) -> Optional[str]
:staticmethod:
Get Airflow Variable by iterating over all Secret Backends.
:param key: Variable Key
:return: Variable Value