feluelle commented on a change in pull request #8962: URL: https://github.com/apache/airflow/pull/8962#discussion_r431366969
########## File path: docs/concepts.rst ########## @@ -116,6 +116,47 @@ DAGs can be used as context managers to automatically assign new operators to th op.dag is dag # True +.. _concepts:functional_dags: + +Functional DAGs +--------------- +*Added in Airflow 1.10.11* + +DAGs can be defined using functional abstractions. Outputs and inputs are sent between tasks using +:ref:`XComs <concepts:xcom>` values. In addition, you can wrap functions as tasks using the +:ref:`task decorator <concepts:task_decorator>`. Dependencies are automatically inferred from +the message dependencies. + +Example DAG with functional abstraction + +.. code:: python + + with DAG( + 'send_server_ip', default_args=default_args, schedule_interval=None + ) as dag: + + # Using default connection as it's set to httpbin.org by default + get_ip = SimpleHttpOperator( + task_id='get_ip', endpoint='get', method='GET', xcom_push=True + ) + + @dag.task(multiple_outputs=True) + def prepare_email(raw_json: str) -> str: + external_ip = json.loads(raw_json)['origin'] + return { + 'subject':f'Server connected from {external_ip}', + 'body': f'Seems like today your server executing Airflow is connected from the external IP {external_ip}<br>' Review comment: Or we could use [future-fstrings](https://github.com/asottile/future-fstrings). We already have it as dep of a [dep](https://github.com/apache/airflow/search?q=future-fstrings&unscoped_q=future-fstrings) and add `# -*- coding: future_fstrings -*-`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org