diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e1a8576..9d920c67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Add netCDF to pystac.media_type ([#1386](https://github.com/stac-utils/pystac/pull/1386)) - Add convenience method for accessing pystac_client ([#1365](https://github.com/stac-utils/pystac/pull/1365)) - Fix field ordering when saving `Item`s ([#1423](https://github.com/stac-utils/pystac/pull/1423)) +- Add keywords to common metadata ([#1443](https://github.com/stac-utils/pystac/pull/1443)) - Add roles to common metadata ([#1444](https://github.com/stac-utils/pystac/pull/1444/files)) ### Changed diff --git a/pystac/common_metadata.py b/pystac/common_metadata.py index 11081266..b7d7fbfc 100644 --- a/pystac/common_metadata.py +++ b/pystac/common_metadata.py @@ -232,6 +232,15 @@ def updated(self) -> datetime | None: def updated(self, v: datetime | None) -> None: self._set_field("updated", utils.map_opt(utils.datetime_to_str, v)) + @property + def keywords(self) -> list[str] | None: + """Get or set the keywords describing the STAC entity.""" + return self._get_field("keywords", list[str]) + + @keywords.setter + def keywords(self, v: list[str] | None) -> None: + self._set_field("keywords", v) + @property def roles(self) -> list[str] | None: """Get or set the semantic roles of the entity.""" diff --git a/tests/data-files/item/sample-item-asset-properties.json b/tests/data-files/item/sample-item-asset-properties.json index 78be8ac5..fe7c7b16 100644 --- a/tests/data-files/item/sample-item-asset-properties.json +++ b/tests/data-files/item/sample-item-asset-properties.json @@ -74,6 +74,7 @@ "start_datetime": "2017-05-01T13:22:30.040Z", "end_datetime": "2017-05-02T13:22:30.040Z", "license": "CC-BY-4.0", + "keywords": ["keyword_a"], "roles": ["a_role"], "providers": [ { diff --git a/tests/test_common_metadata.py b/tests/test_common_metadata.py index 21e1a2e7..4ea76732 100644 --- a/tests/test_common_metadata.py +++ b/tests/test_common_metadata.py @@ -541,6 +541,28 @@ def test_updated(self) -> None: analytic.to_dict()["updated"], utils.datetime_to_str(set_value) ) + def test_keywords(self) -> None: + item = self.item.clone() + cm = item.common_metadata + analytic = item.assets["analytic"] + analytic_cm = CommonMetadata(analytic) + thumbnail = item.assets["thumbnail"] + thumbnail_cm = CommonMetadata(thumbnail) + + item_value = cm.keywords + a2_known_value = ["keyword_a"] + + # Get + self.assertNotEqual(thumbnail_cm.keywords, item_value) + self.assertEqual(thumbnail_cm.keywords, a2_known_value) + + # Set + set_value = ["keyword_b"] + analytic_cm.keywords = set_value + + self.assertEqual(analytic_cm.keywords, set_value) + self.assertEqual(analytic.to_dict()["keywords"], set_value) + def test_roles(self) -> None: item = self.item.clone() cm = item.common_metadata