CARVIEW |
Content
- Overview
- Quick Start
- Installation of Airflow®
- Security
- Tutorials
- How-to Guides
- UI Overview
- Core Concepts
- Authoring and Scheduling
- Administration and Deployment
- Integration
- PUBLIC INTERFACE FOR AIRFLOW 3.0+
- Using Airflow Public Interfaces
- Using the Public Interface for DAG Authors
- Dags
- Operators
- Task Instances
- Task Instance Keys
- Hooks
- Public Airflow utilities
- Public Exceptions
- Public Utility classes
- Using Public Interface to extend Airflow capabilities
- Triggers
- Timetables
- Listeners
- Extra Links
- Using Public Interface to integrate with external services and applications
- Executors
- Secrets Backends
- Auth managers
- Connections
- Extra Links
- Logging and Monitoring
- Decorators
- Email notifications
- Notifications
- Cluster Policies
- Lineage
- What is not part of the Public Interface of Apache Airflow?
- Best Practices
- FAQ
- Troubleshooting
- Release Policies
- Release Notes
- Privacy Notice
- Project
- License
References
Internal DB details
Content
- Overview
- Quick Start
- Installation of Airflow®
- Security
- Tutorials
- How-to Guides
- UI Overview
- Core Concepts
- Authoring and Scheduling
- Administration and Deployment
- Integration
- PUBLIC INTERFACE FOR AIRFLOW 3.0+
- Using Airflow Public Interfaces
- Using the Public Interface for DAG Authors
- Dags
- Operators
- Task Instances
- Task Instance Keys
- Hooks
- Public Airflow utilities
- Public Exceptions
- Public Utility classes
- Using Public Interface to extend Airflow capabilities
- Triggers
- Timetables
- Listeners
- Extra Links
- Using Public Interface to integrate with external services and applications
- Executors
- Secrets Backends
- Auth managers
- Connections
- Extra Links
- Logging and Monitoring
- Decorators
- Email notifications
- Notifications
- Cluster Policies
- Lineage
- What is not part of the Public Interface of Apache Airflow?
- Best Practices
- FAQ
- Troubleshooting
- Release Policies
- Release Notes
- Privacy Notice
- Project
- License
References
Internal DB details
Variables¶
Variables are Airflow’s runtime configuration concept - a general key/value store that is global and can be queried from your tasks, and easily set via Airflow’s user interface, or bulk-uploaded as a JSON file.
To use them, just import and call get
on the Variable model:
from airflow.sdk import Variable
# Normal call style
foo = Variable.get("foo")
# Auto-deserializes a JSON value
bar = Variable.get("bar", deserialize_json=True)
# Returns the value of default (None) if the variable is not set
baz = Variable.get("baz", default=None)
You can also access variables through the Task Context using
get_current_context()
:
from airflow.sdk import get_current_context
def my_task():
context = get_current_context()
var = context["var"]
my_variable = var.get("my_variable_name")
return my_variable
You can also use them from templates:
# Raw value
echo {{ var.value.<variable_name> }}
# Auto-deserialize JSON value
echo {{ var.json.<variable_name> }}
Variables are global, and should only be used for overall configuration that covers the entire installation; to pass data from one Task/Operator to another, you should use XComs instead.
We also recommend that you try to keep most of your settings and configuration in your DAG files, so it can be versioned using source control; Variables are really only for values that are truly runtime-dependent.
For more information on setting and managing variables, see Managing Variables.
Was this entry helpful?