From 5c323773435fc7c1224f65e2ae5faac47103e64a Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Sat, 21 Sep 2024 13:37:33 -0600 Subject: [PATCH] feat: add stacrs post --- content/posts/2024-09-20-stacrs-v0.1.md | 78 +++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 content/posts/2024-09-20-stacrs-v0.1.md diff --git a/content/posts/2024-09-20-stacrs-v0.1.md b/content/posts/2024-09-20-stacrs-v0.1.md new file mode 100644 index 0000000..71d0ff2 --- /dev/null +++ b/content/posts/2024-09-20-stacrs-v0.1.md @@ -0,0 +1,78 @@ ++++ +title = "Python API for stac-rs v0.1" +slug = "stacrs-python-v0.1" +date = 2024-09-20 + +[taxonomies] +tags = ["python", "stac"] +categories = ["releases"] ++++ + +[stac-rs](https://github.com/stac-utils/stac-rs) has a simple, no-dependency Python API installable from PyPI: + +```shell +pip install stacrs +``` + +The API documentation is available [here](https://stac-utils.github.io/stac-rs/python/api/). +This Python API is intended to complement, not replace, existing Python packages such as [pystac](https://pystac.readthedocs.io) and [pystac-client](https://pystac-client.readthedocs.io) by providing functionality that those packages don't have. + +## stac-geoparquet + +[stac-geoparquet](https://github.com/stac-utils/stac-geoparquet) is a relatively new specification that describes how to store STAC items in [GeoParquet](https://geoparquet.org/). +The specification repo also contains a reference implementation, mostly written in Python. +**stac-geoparquet** was added to **stac-rs** in [v0.9.0](https://github.com/stac-utils/stac-rs/releases/tag/stac-v0.9.0), and v0.1 of the Python package includes this capability: + +```python +import stacrs + +item_collection = stacrs.read("items.parquet") +# do some work +stacrs.write("items.parquet", item_collection) +``` + +Note that these items are read as JSON dictionaries, which might not be the most efficient way to work with the data depending on your use case. + +## Object store + +**stacrs** supports reading and writing from blog storage via [object_store](https://docs.rs/object_store): + +```python +options = [("aws_access_key_id", "...")] +item = stacrs.read("s3://bucket/item.json", options=options) +``` + +Currently, credentials are provided via `options`, which can be a little awkward — we'd like to make that experience better in the future (e.g. via [environment variables](https://github.com/stac-utils/stac-rs/issues/414)). + +## Searching into files + +A common workflow for data analysis is to search a STAC API for a large number of items, save those items to a file (e.g. **stac-geoparquet**) then iteratively work with those items for more focused queries. +**stacrs** supports that workflow with `search_to`: + +```python +stacrs.search_to("items.parquet", + "https://landsatlook.usgs.gov/stac-server", + collections=["landsat-c2l2-sr"], + intersects={"type": "Point", "coordinates": [-105.119, 40.173]}, + sortby="-properties.datetime", + max_items=1000, +) +items = stacrs.read("items.parquet") +# Do some work +``` + +## pystac compatability + +If **pystac** exists on the system, `stacrs.pystac` provides functions that take and return pystac objects: + +```python +from pystac import ItemCollection + +item_collection = stacrs.pystac.read("items.json") +assert isinstance(item_collection, ItemCollection) +``` + +## Get in touch + +If you're using the **stacs** Python package, or you'd like to use it, get in touch! +I'm on [Bluesky](https://bsky.app/profile/gadom.ski), or ask anything in the [Github Discussions](https://github.com/stac-utils/stac-rs/discussions).