pystac.asset

class pystac.asset.Asset(href: str, title: Optional[str] = None, description: Optional[str] = None, media_type: Optional[str] = None, roles: Optional[List[str]] = None, extra_fields: Optional[Dict[str, Any]] = None)[source]

An object that contains a link to data associated with an Item or Collection that can be downloaded or streamed.

Parameters:
  • href – Link to the asset object. Relative and absolute links are both allowed.

  • title – Optional displayed title for clients and users.

  • description – A description of the Asset providing additional details, such as how it was processed or created. CommonMark 0.29 syntax MAY be used for rich text representation.

  • media_type – Optional description of the media type. Registered Media Types are preferred. See MediaType for common media types.

  • roles – Optional, Semantic roles (i.e. thumbnail, overview, data, metadata) of the asset.

  • extra_fields – Optional, additional fields for this asset. This is used by extensions as a way to serialize and deserialize properties on asset object JSON.

clone() Asset[source]

Clones this asset. Makes a deepcopy of the extra_fields.

Returns:

The clone of this asset.

Return type:

Asset

property common_metadata: CommonMetadata

Access the asset’s common metadata fields as a CommonMetadata object.

copy(href: str) Asset[source]

Copies this asset’s file to a new location on the local filesystem, setting the asset href accordingly.

Modifies the asset in place, and returns the same asset.

Parameters:

href – The new asset location. Must be a local path. If relative it must be relative to the owner object.

Returns:

The asset with the updated href.

Return type:

Asset

delete() None[source]

Delete this asset’s file. Does not delete the asset from the item that owns it. See delete_asset() for that.

Does not modify the asset.

description: Optional[str]

A description of the Asset providing additional details, such as how it was processed or created. CommonMark 0.29 syntax MAY be used for rich text representation.

extra_fields: Dict[str, Any]

Optional, additional fields for this asset. This is used by extensions as a way to serialize and deserialize properties on asset object JSON.

classmethod from_dict(d: Dict[str, Any]) A[source]

Constructs an Asset from a dict.

Returns:

The Asset deserialized from the JSON dict.

Return type:

Asset

get_absolute_href() Optional[str][source]

Gets the absolute href for this asset, if possible.

If this Asset has no associated Item, and the asset HREF is a relative path,

this method will return None. If the Item that owns the Asset has no self HREF, this will also return None.

Returns:

The absolute HREF of this asset, or None if an absolute HREF could not

be determined.

Return type:

str

has_role(role: str) bool[source]

Check if a role exists in the Asset role list.

Parameters:

role – Role to check for existence.

Returns:

True if role exists, else False.

Return type:

bool

href: str

Link to the asset object. Relative and absolute links are both allowed.

media_type: Optional[str]

Optional description of the media type. Registered Media Types are preferred. See MediaType for common media types.

move(href: str) Asset[source]

Moves this asset’s file to a new location on the local filesystem, setting the asset href accordingly.

Modifies the asset in place, and returns the same asset.

Parameters:

href – The new asset location. Must be a local path. If relative it must be relative to the owner object.

Returns:

The asset with the updated href.

Return type:

Asset

owner: Optional[Union[Item, Collection]]

The Item or Collection that this asset belongs to, or None if it has no owner.

roles: Optional[List[str]]

Optional, Semantic roles (i.e. thumbnail, overview, data, metadata) of the asset.

set_owner(obj: Union[Collection, Item]) None[source]

Sets the owning item of this Asset.

The owning item will be used to resolve relative HREFs of this asset.

Parameters:

obj – The Collection or Item that owns this asset.

title: Optional[str]

Optional displayed title for clients and users.

to_dict() Dict[str, Any][source]

Returns this Asset as a dictionary.

Returns:

A serialization of the Asset.

Return type:

dict