jroachgolf84 commented on code in PR #67299:
URL: https://github.com/apache/airflow/pull/67299#discussion_r3367309812


##########
airflow-core/docs/core-concepts/asset-store.rst:
##########
@@ -0,0 +1,189 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+.. _concepts:asset-store:
+
+.. spelling:word-list::
+
+   subscripted
+   subscripting
+
+Asset Store
+===========
+
+.. versionadded:: 3.3
+
+Asset store is a persistent key/value store scoped to an *asset*, independent 
of any particular DAG run. Unlike :doc:`task store 
</core-concepts/task-store>`, which is tied to a single task instance, asset 
store persists across runs and is logically owned by the asset itself. It is 
the natural home for cross-run metadata such as watermarks, incremental-load 
cursors, and per-asset configuration.
+
+Asset store is accessed through the task context via 
``context["asset_store"]``.
+
+
+When is ``asset_store`` available?
+----------------------------------
+
+When using asset store within a task, ``context["asset_store"]`` is populated 
for **concrete** :class:`~airflow.sdk.definitions.asset.Asset` inlets and 
outlets. A task must declare at least one concrete inlet or outlet for 
``asset_store`` to contain any entries.
+
+Accessing asset store using ``context``
+---------------------------------------
+
+An asset becomes available through context["asset_store"] when it is included 
in inlets (or in both inlets and outlets). You can then retrieve its asset 
store by subscripting context["asset_store"] with the asset object.
+
+.. code-block:: python
+
+    from airflow.sdk import Asset, DAG, task
+
+    my_asset = Asset("my_data", uri="s3://bucket/my_data")
+
+    with DAG("example_asset_store", schedule=None):
+
+        @task(inlets=[my_asset], outlets=[my_asset])
+        def process(**context):
+            asset_store = context["asset_store"][my_asset]
+            watermark = asset_store.get("watermark")
+            asset_store.set("watermark", "2024-06-01")
+
+To see asset store in-action in a real DAG, checkout the DAG in 
`example_asset_store.py 
<https://github.com/apache/airflow/blob/main/airflow-core/src/airflow/example_dags/example_asset_store.py>`_.
+
+Single-inlet shorthand
+~~~~~~~~~~~~~~~~~~~~~~~
+
+For tasks with exactly **one** concrete inlet, you can call ``get``, ``set``, 
``delete``, and ``clear`` directly on ``context["asset_store"]`` without 
subscripting.
+
+.. code-block:: python
+
+    @task(inlets=[my_asset], outlets=[my_asset])
+    def process_single(**context):
+        asset_store = context["asset_store"]
+        watermark = asset_store.get("watermark")
+        asset_store.set("watermark", "2024-06-01")
+
+If the task has more than one concrete inlet, calling the shorthand raises a 
``ValueError``. Use the subscript form (``context["asset_store"][my_asset]``) 
whenever a task has multiple inlets.
+
+
+API reference
+-------------
+
+The following methods are available on both the per-asset accessor 
(``context["asset_store"][my_asset]``), the shorthand 
(``context["asset_store"]``) when the task has exactly one inlet, and when 
using the ``self.asset_store`` attribute.
+
+``get(key, default)``
+~~~~~~~~~~~~~~~~~~~~~
+
+Returns the stored JSON value, or the ``default`` value if the key does not 
exist.
+
+.. code-block:: python
+
+    # Using context
+    watermark = context["asset_store"][my_asset].get("watermark", 
default="initial_watermark")
+
+    # Using self.asset_store
+    watermark = self.asset_store[my_asset].get("watermark")
+
+``set(key, value)``
+~~~~~~~~~~~~~~~~~~~
+
+Writes or overwrites a key-value pair. Unlike task store, asset store has no 
``retention`` parameter. Values persist until explicitly deleted or until the 
asset is deactivated. Like with task store, ``value`` can be any 
JSON-compatible type, except for ``None``. This includes:
+
+* ``str``
+* ``int``
+* ``float``
+* ``bool``
+* ``list``
+* ``dict``
+
+.. code-block:: python
+
+    # Using context
+    context["asset_store"][my_asset].set("watermark", 
default="2024-06-01T00:00:00Z")

Review Comment:
   Resolved in next commit.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to