Skip to content

Commit d64b829

Browse files
committed
feat: AssetProcessingExtension
1 parent 872f8ef commit d64b829

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

pystac/extensions/processing.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from __future__ import annotations
77

8+
from collections.abc import Iterable
89
from datetime import datetime
910
from typing import (
1011
Any,
@@ -311,3 +312,41 @@ def __init__(self: Self, item: pystac.Item) -> None:
311312

312313
def __repr__(self: Self) -> str:
313314
return f"<ItemProcessingExtension Item id={self.item.id}>"
315+
316+
317+
class AssetProcessingExtension(ProcessingExtension[pystac.Asset]):
318+
"""A concrete implementation of :class:`ProcessingExtension` on an
319+
:class:`~pystac.Asset` that extends the Asset fields to include properties defined
320+
in the :stac-ext:`Processing Extension <processing>`.
321+
322+
This class should generally not be instantiated directly. Instead, call
323+
:meth:`ProcessingExtension.ext` on an :class:`~pystac.Asset` to extend it.
324+
"""
325+
326+
asset_href: str
327+
"""The ``href`` value of the :class:`~pystac.Asset` being extended."""
328+
329+
properties: dict[str, Any]
330+
"""The :class:`~pystac.Asset` fields, including extension properties."""
331+
332+
additional_read_properties: Iterable[dict[str, Any]] | None = None
333+
"""If present, this will be a list containing 1 dictionary representing the
334+
properties of the owning :class:`~pystac.Item`."""
335+
336+
def __init__(self, asset: pystac.Asset):
337+
self.asset_href = asset.href
338+
self.properties = asset.extra_fields
339+
if asset.owner and isinstance(asset.owner, pystac.Item):
340+
self.additional_read_properties = [asset.owner.properties]
341+
342+
def __repr__(self) -> str:
343+
return f"<AssetProcessingExtension Asset href={self.asset_href}>"
344+
345+
346+
class ItemAssetsProcessingExtension(ProcessingExtension[pystac.ItemAssetDefinition]):
347+
properties: dict[str, Any]
348+
asset_defn: pystac.ItemAssetDefinition
349+
350+
def __init__(self, item_asset: pystac.ItemAssetDefinition):
351+
self.asset_defn = item_asset
352+
self.properties = item_asset.properties

0 commit comments

Comments
 (0)