Skip to content

Commit abef8bd

Browse files
sunank200amoghrajesh
authored andcommitted
docs: refresh Public Interface & align how-to guides for Airflow 3.0+ (apache#52297)
* docs: Update public interface documentation for Airflow 3.0+ for metadata direct access change * docs: replace direct metadata model imports in how-to examples with airflow.sdk * Make Public interface for Airflow 3 and add link for Airflow 2.11 * Fix PR comments * Update airflow-core/docs/public-airflow-interface.rst Co-Authored-By: Amogh Desai <[email protected]> * Fix PR comments * Remove duplicates and remove RuntimeTaskInstanceProtocol as it is not public * Fix PR comments --------- Co-authored-by: Amogh Desai <[email protected]>
1 parent 400d4e8 commit abef8bd

File tree

7 files changed

+265
-98
lines changed

7 files changed

+265
-98
lines changed

airflow-core/docs/conf.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120

121121
PACKAGES_THAT_WE_SHOULD_ADD_TO_API_DOCS = {
122122
"hooks",
123-
"decorators",
124123
"example_dags",
125124
"executors",
126125
"operators",
@@ -140,15 +139,7 @@
140139

141140
MODELS_THAT_SHOULD_BE_INCLUDED_IN_API_DOCS: set[str] = {
142141
"baseoperator.py",
143-
"connection.py",
144-
"dag.py",
145-
"dagrun.py",
146-
"dagbag.py",
147142
"param.py",
148-
"taskinstance.py",
149-
"taskinstancekey.py",
150-
"variable.py",
151-
"xcom.py",
152143
}
153144

154145

airflow-core/docs/core-concepts/params.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If the user-supplied values don't pass validation, Airflow shows a warning inste
3232
DAG-level Params
3333
----------------
3434

35-
To add Params to a :class:`~airflow.models.dag.DAG`, initialize it with the ``params`` kwarg.
35+
To add Params to a :class:`~airflow.sdk.DAG`, initialize it with the ``params`` kwarg.
3636
Use a dictionary that maps Param names to either a :class:`~airflow.sdk.definitions.param.Param` or an object indicating the parameter's default value.
3737

3838
.. code-block::

airflow-core/docs/core-concepts/variables.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ To use them, just import and call ``get`` on the Variable model::
3333
# Returns the value of default (None) if the variable is not set
3434
baz = Variable.get("baz", default=None)
3535

36+
You can also access variables through the Task Context using
37+
:func:`~airflow.sdk.get_current_context`:
38+
39+
.. code-block:: python
40+
41+
from airflow.sdk import get_current_context
42+
43+
44+
def my_task():
45+
context = get_current_context()
46+
var = context["var"]
47+
my_variable = var.get("my_variable_name")
48+
return my_variable
49+
3650
You can also use them from :ref:`templates <concepts:jinja-templating>`::
3751

3852
# Raw value

airflow-core/docs/core-concepts/xcoms.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ XComs (short for "cross-communications") are a mechanism that let :doc:`tasks` t
2525

2626
An XCom is identified by a ``key`` (essentially its name), as well as the ``task_id`` and ``dag_id`` it came from. They can have any serializable value (including objects that are decorated with ``@dataclass`` or ``@attr.define``, see :ref:`TaskFlow arguments <concepts:arbitrary-arguments>`:), but they are only designed for small amounts of data; do not use them to pass around large values, like dataframes.
2727

28+
XCom operations should be performed through the Task Context using
29+
:func:`~airflow.sdk.get_current_context`. Directly updating using XCom database model is not possible.
30+
2831
XComs are explicitly "pushed" and "pulled" to/from their storage using the ``xcom_push`` and ``xcom_pull`` methods on Task Instances.
2932

3033
To push a value within a task called **"task-1"** that will be used by another task:
@@ -73,8 +76,6 @@ An example of pushing multiple XComs and pulling them individually:
7376
# Pulling entire xcom data from push_multiple task
7477
data = context["ti"].xcom_pull(task_ids="push_multiple", key="return_value")
7578
76-
77-
7879
.. note::
7980

8081
If the first task run is not succeeded then on every retry task XComs will be cleared to make the task run idempotent.
@@ -91,7 +92,7 @@ Custom XCom Backends
9192

9293
The XCom system has interchangeable backends, and you can set which backend is being used via the ``xcom_backend`` configuration option.
9394

94-
If you want to implement your own backend, you should subclass :class:`~airflow.models.xcom.BaseXCom`, and override the ``serialize_value`` and ``deserialize_value`` methods.
95+
If you want to implement your own backend, you should subclass :class:`~airflow.sdk.bases.xcom.BaseXCom`, and override the ``serialize_value`` and ``deserialize_value`` methods.
9596

9697
You can override the ``purge`` method in the ``BaseXCom`` class to have control over purging the xcom data from the custom backend. This will be called as part of ``delete``.
9798

@@ -104,6 +105,6 @@ If you can exec into a terminal in an Airflow container, you can then print out
104105

105106
.. code-block:: python
106107
107-
from airflow.models.xcom import XCom
108+
from airflow.sdk.execution_time.xcom import XCom
108109
109110
print(XCom.__name__)

airflow-core/docs/howto/connection.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Managing Connections
2222

2323
For an overview of hooks and connections, see :doc:`/authoring-and-scheduling/connections`.
2424

25-
Airflow's :class:`~airflow.models.connection.Connection` object is used for storing credentials and other information necessary for connecting to external services.
25+
Airflow's :class:`~airflow.sdk.Connection` object is used for storing credentials and other information necessary for connecting to external services.
2626

2727
Connections may be defined in the following ways:
2828

@@ -77,7 +77,7 @@ convenience property :py:meth:`~airflow.models.connection.Connection.as_json`. I
7777

7878
.. code-block:: pycon
7979
80-
>>> from airflow.models.connection import Connection
80+
>>> from airflow.sdk import Connection
8181
>>> c = Connection(
8282
... conn_id="some_conn",
8383
... conn_type="mysql",
@@ -94,7 +94,7 @@ In addition, same approach could be used to convert Connection from URI format t
9494

9595
.. code-block:: pycon
9696
97-
>>> from airflow.models.connection import Connection
97+
>>> from airflow.sdk import Connection
9898
>>> c = Connection(
9999
... conn_id="awesome_conn",
100100
... description="Example Connection",

airflow-core/docs/howto/custom-operator.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Creating a custom Operator
2424
Airflow allows you to create new operators to suit the requirements of you or your team.
2525
This extensibility is one of the many features which make Apache Airflow powerful.
2626

27-
You can create any operator you want by extending the :class:`airflow.models.baseoperator.BaseOperator`
27+
You can create any operator you want by extending the public SDK base class :class:`~airflow.sdk.BaseOperator`.
2828

2929
There are two methods that you need to override in a derived class:
3030

0 commit comments

Comments
 (0)