Skip to content

Asset

pystac.Asset

Bases: ItemAsset

An asset, e.g. a geospatial data file.

Source code in src/pystac/asset.py
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class Asset(ItemAsset):
    """An asset, e.g. a geospatial data file."""

    @classmethod
    def from_dict(cls: type[Self], d: dict[str, Any]) -> Self:
        """Creates an asset from a dictionary."""
        return cls(**d)

    def __init__(
        self,
        href: str,
        title: str | None = None,
        description: str | None = None,
        type: str | None = None,
        roles: list[str] | None = None,
        **kwargs: Any,
    ) -> None:
        """Creates a new asset."""
        self.href = href
        super().__init__(
            title=title, description=description, type=type, roles=roles, **kwargs
        )

    @deprecate.function(
        "assets aren't owned anymore, all this method does is make the asset's "
        "relative href absolute using the 'owner's href"
    )
    def set_owner(self, owner: STACObject) -> None:
        if owner.href:
            self.href = utils.make_absolute_href(self.href, owner.href)

    @deprecate.function("prefer to use `STACObject.render()` then `asset.href`")
    def get_absolute_href(self) -> str | None:
        if utils.is_absolute_href(self.href):
            return self.href
        else:
            return None

    def to_dict(self) -> dict[str, Any]:
        """Converts this asset to a dictionary."""
        d = {"href": self.href}
        d.update(super().to_dict())
        return d

__init__

__init__(
    href: str,
    title: str | None = None,
    description: str | None = None,
    type: str | None = None,
    roles: list[str] | None = None,
    **kwargs: Any,
) -> None

Creates a new asset.

Source code in src/pystac/asset.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
def __init__(
    self,
    href: str,
    title: str | None = None,
    description: str | None = None,
    type: str | None = None,
    roles: list[str] | None = None,
    **kwargs: Any,
) -> None:
    """Creates a new asset."""
    self.href = href
    super().__init__(
        title=title, description=description, type=type, roles=roles, **kwargs
    )

from_dict classmethod

from_dict(d: dict[str, Any]) -> Self

Creates an asset from a dictionary.

Source code in src/pystac/asset.py
58
59
60
61
@classmethod
def from_dict(cls: type[Self], d: dict[str, Any]) -> Self:
    """Creates an asset from a dictionary."""
    return cls(**d)

to_dict

to_dict() -> dict[str, Any]

Converts this asset to a dictionary.

Source code in src/pystac/asset.py
93
94
95
96
97
def to_dict(self) -> dict[str, Any]:
    """Converts this asset to a dictionary."""
    d = {"href": self.href}
    d.update(super().to_dict())
    return d

pystac.ItemAsset

An asset without a href.

This was made a "first-class" data structure in STAC v1.1.

Source code in src/pystac/asset.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class ItemAsset:
    """An asset without a href.

    This was made a "first-class" data structure in STAC v1.1.
    """

    @classmethod
    def from_dict(cls: type[Self], d: dict[str, Any]) -> Self:
        """Creates a new item asset from a dictionary."""
        return cls(**d)

    def __init__(
        self,
        title: str | None = None,
        description: str | None = None,
        type: str | None = None,
        roles: list[str] | None = None,
        **kwargs: Any,
    ) -> None:
        """Creates a new item asset."""
        self.title = title
        self.description = description
        self.type = type
        self.roles = roles
        self.extra_fields = kwargs

    def to_dict(self) -> dict[str, Any]:
        """Converts this item asset to a dictionary."""
        d: dict[str, Any] = {}
        if self.title is not None:
            d["title"] = self.title
        if self.description is not None:
            d["description"] = self.description
        if self.type is not None:
            d["type"] = self.type
        if self.roles is not None:
            d["roles"] = self.roles
        d.update(copy.deepcopy(self.extra_fields))
        return d

__init__

__init__(
    title: str | None = None,
    description: str | None = None,
    type: str | None = None,
    roles: list[str] | None = None,
    **kwargs: Any,
) -> None

Creates a new item asset.

Source code in src/pystac/asset.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def __init__(
    self,
    title: str | None = None,
    description: str | None = None,
    type: str | None = None,
    roles: list[str] | None = None,
    **kwargs: Any,
) -> None:
    """Creates a new item asset."""
    self.title = title
    self.description = description
    self.type = type
    self.roles = roles
    self.extra_fields = kwargs

from_dict classmethod

from_dict(d: dict[str, Any]) -> Self

Creates a new item asset from a dictionary.

Source code in src/pystac/asset.py
20
21
22
23
@classmethod
def from_dict(cls: type[Self], d: dict[str, Any]) -> Self:
    """Creates a new item asset from a dictionary."""
    return cls(**d)

to_dict

to_dict() -> dict[str, Any]

Converts this item asset to a dictionary.

Source code in src/pystac/asset.py
40
41
42
43
44
45
46
47
48
49
50
51
52
def to_dict(self) -> dict[str, Any]:
    """Converts this item asset to a dictionary."""
    d: dict[str, Any] = {}
    if self.title is not None:
        d["title"] = self.title
    if self.description is not None:
        d["description"] = self.description
    if self.type is not None:
        d["type"] = self.type
    if self.roles is not None:
        d["roles"] = self.roles
    d.update(copy.deepcopy(self.extra_fields))
    return d