pystac.asset#
- class pystac.asset.Asset(href: str, title: str | None = None, description: str | None = None, media_type: str | None = None, roles: list[str] | None = None, extra_fields: dict[str, Any] | None = 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 theextra_fields
.- Returns:
The clone of this asset.
- Return type:
- 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:
- 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: str | None
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.
- property ext: AssetExt
Accessor for extension classes on this asset
Example:
asset.ext.proj.epsg = 4326
- 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:
- get_absolute_href() str | None [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 returnNone
.
- Returns:
- The absolute HREF of this asset, or None if an absolute HREF could not
be determined.
- Return type:
- 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:
- href: str
Link to the asset object. Relative and absolute links are both allowed.
- media_type: str | None
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:
- owner: Assets | None
The
Item
orCollection
that this asset belongs to, orNone
if it has no owner.
- roles: list[str] | None
Optional, Semantic roles (i.e. thumbnail, overview, data, metadata) of the asset.
- class pystac.asset.Assets(*args, **kwargs)[source]
Protocol, with functionality, for STAC objects that have assets.
- add_asset(key: str, asset: Asset) None [source]
Adds an Asset to this object.
- Parameters:
key – The unique key of this asset.
asset – The Asset to add.
- delete_asset(key: str) None [source]
Deletes the asset at the given key, and removes the asset’s data file from the local filesystem.
It is an error to attempt to delete an asset’s file if it is on a remote filesystem.
To delete the asset without removing the file, use del item.assets[“key”].
- Parameters:
key – The unique key of this asset.
- get_assets(media_type: str | MediaType | None = None, role: str | None = None) dict[str, Asset] [source]
Get this object’s assets.
- Parameters:
media_type – If set, filter the assets such that only those with a matching
media_type
are returned.role – If set, filter the assets such that only those with a matching
role
are returned.
- Returns:
- A dictionary of assets that match
media_type
and/or
role
if set or else all of this object’s assets.
- A dictionary of assets that match
- Return type:
- get_self_href() str | None [source]
Abstract definition of STACObject.get_self_href.
Needed to make the make_asset_hrefs_{absolute|relative} methods pass type checking. Refactoring out all the link behavior in STACObject to its own protocol would be too heavy, so we just use this stub instead.
- make_asset_hrefs_absolute() Assets [source]
Modify each asset’s HREF to be absolute.
Any asset HREFs that are relative will be modified to absolute based on this item’s self HREF.
- Returns:
self
- Return type:
Assets