GithubHelp home page GithubHelp logo

how to use variables ? about airflow HOT 6 CLOSED

apache avatar apache commented on May 10, 2024
how to use variables ?

from airflow.

Comments (6)

mistercrunch avatar mistercrunch commented on May 10, 2024

I need to add an entry in the documentation to explain this, but variables are general purpose and used to control or alter the behavior of specific pipelines that define logic based on the content of variables.

For instance there could be a convention that an "aggregation framework" would look for variables starting with the prefix aggfwk_ and perhaps read a JSON config from the variable. The JSON config would define the metadata for the aggregation framework needs to operate. Adding new variables would create new pipelines or sets of pipes.

So it's just a place to store metadata that pipelines can read from. Arguably most of this metadata should be code and live in source control, but sometimes we need some settings to be more reactive and that's when we use variables.

Our only internal use case now is a backfilling framework that allows us to run huge backfills efficiently.

Another thought is Airflow doesn't expose a way to communicate across tasks, or even for an upstream task influence the behavior of a downstream tasks. Maybe variables could be used for that purpose, but that's somewhat messy.

from airflow.

m1racoli avatar m1racoli commented on May 10, 2024

How can variables be accessed?
Is there an API to access variables defined in the UI?
I assume they are stored in the database?

We want to use variables for providing development and production flags within the creation of the DAG or within the task template.

from airflow.

mistercrunch avatar mistercrunch commented on May 10, 2024

Variable is a sqlalchemy model and is located at airflow.models.Variable

I just added a simple utility classmethod to easily Variable.get(key, deser_json=False)
9c36068

This makes it a very concise call to get a variable.

from airflow.models import Variable
foo = Variable.get("foo")

Though this is not in the current pypi release, it will make it to 1.1.0 . In the meantime you can look at the method for the more verbose way to get the variable.

from airflow.

m1racoli avatar m1racoli commented on May 10, 2024

Thank's a lot! That was, what I was looking for.
I just discovered the 1.1.0 release on pypi as well.

from airflow.

Yongyiw avatar Yongyiw commented on May 10, 2024

Just asking if it is possible to set Variables in code(like in some hook class). Cause I want to save the http connection cookies as variables.

from airflow.

Yongyiw avatar Yongyiw commented on May 10, 2024

Never mind, I found my answer here: #220

from airflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.