Skip to content

Commit

Permalink
feat: add stacrs post
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Sep 21, 2024
1 parent f2abfe5 commit 5c32377
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions content/posts/2024-09-20-stacrs-v0.1.md
Original file line number Diff line number Diff line change
@@ -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).

0 comments on commit 5c32377

Please sign in to comment.