rustac
A Python package for STAC using Rust under the hood.
[!TIP] While you can pronounce "rustac" however you'd like, we like "ruh-stac".
Why?
Q: We already have PySTAC, so why rustac?
A: rustac can
- Read, write, and search stac-geoparquet
- Go to and from arrow tables, allowing easy interoperability with (e.g.) GeoPandas
async
If you don't need those things, rustac probably isn't for you — use pystac and its friend, pystac-client.
Usage
Install via pip:
Or via conda:
Then:
import asyncio
import rustac
async def main() -> None:
# Search a STAC API
items = await rustac.search(
"https://landsatlook.usgs.gov/stac-server",
collections="landsat-c2l2-sr",
intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
sortby="-properties.datetime",
max_items=100,
)
# If you installed with `pystac[arrow]`:
from geopandas import GeoDataFrame
table = rustac.to_arrow(items)
data_frame = GeoDataFrame.from_arrow(table)
items = rustac.from_arrow(data_frame.to_arrow())
# Write items to a stac-geoparquet file
await rustac.write("/tmp/items.parquet", items)
# Read items from a stac-geoparquet file as an item collection
item_collection = await rustac.read("/tmp/items.parquet")
# Use `search_to` for better performance if you know you'll be writing the items
# to a file
await rustac.search_to(
"/tmp/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=100,
)
asyncio.run(main())
See the documentation for details. In particular, our examples demonstrate some of the more interesting features.
CLI
rustac comes with a CLI:
rustac: A command-line interface for the SpatioTemporal Asset Catalog (STAC)
Usage: rustac [OPTIONS] <COMMAND>
Commands:
translate Translates STAC from one format to another
search Searches a STAC API or stac-geoparquet file
serve Serves a STAC API
validate Validates a STAC value
help Print this message or the help of the given subcommand(s)
Options:
-i, --input-format <INPUT_FORMAT>
The input format.
--opt <OPTIONS>
Options for getting and putting files from object storage.
-o, --output-format <OUTPUT_FORMAT>
The output format.
-c, --compact-json <COMPACT_JSON>
Whether to print compact JSON output [possible values: true, false]
--parquet-compression <PARQUET_COMPRESSION>
The parquet compression to use when writing stac-geoparquet.
-v, --verbose...
Increase verbosity
-q, --quiet...
Decrease verbosity
-h, --help
Print help (see more with '--help')
[!NOTE] Before rustac v0.5.4, the CLI was its own PyPI package named stacrs-cli, which is no longer needed.
stac-geoparquet
rustac replicates much of the behavior in the stac-geoparquet library, and even uses some of the same Rust dependencies. We believe there are a couple of issues with stac-geoparquet that make rustac a worthy replacement:
- The stac-geoparquet repo includes Python dependencies
- It doesn't have a nice one-shot API for reading and writing
- It includes some leftover code and logic from its genesis as a tool for the Microsoft Planetary Computer
We test to ensure compatibility between the two libraries, and we intend to consolidate to a single "stac-geoparquet" library at some point in the future.
Development
Get Rust, uv, and (optionally) libduckdb. Then:
See CONTRIBUTING.md for more information about contributing to this project.
DuckDB
By default, this package expects libduckdb to be present on your system. If you get this sort of error when building:
Set your DUCKDB_LIB_DIR
to point to your libduckdb.
If you're using homebrew, that might look like this:
Alternatively, you can use the duckdb-bundled
feature to build DuckDB bindings into the Rust library:
[!WARNING] Building DuckDB bundled takes a long while.
Docs
If you want to run an off-cycle docs update (e.g. if you fixed something and want to post it without having to make a new release):
License
rustac-py is dual-licensed under both the MIT license and the Apache license (Version 2.0). See LICENSE-APACHE and LICENSE-MIT for details.