Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions python/rustac/rustac.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ class DuckdbClient:
A list of STAC Collections
"""

def collection_from_id_and_items(id: str, items: list[Item]) -> Collection:
"""Creates a collection from an id and some items.

The extents will be calculated from the items, and the items will be linked.

Args:
id: The collection id
items: A list of STAC items

Returns:
A STAC collection
"""

def migrate(value: dict[str, Any], version: Optional[str] = None) -> dict[str, Any]:
"""
Migrates a STAC dictionary to another version.
Expand Down
17 changes: 17 additions & 0 deletions src/collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use pyo3::{
Bound, PyResult, Python, pyfunction,
types::{PyAny, PyAnyMethods, PyDict},
};
use stac::{Collection, Item};

#[pyfunction]
pub fn collection_from_id_and_items<'py>(
py: Python<'py>,
id: String,
items: Bound<'_, PyAny>,
) -> PyResult<Bound<'py, PyDict>> {
let items: Vec<Item> = pythonize::depythonize(&items)?;
let collection = Collection::from_id_and_items(id, &items);
let collection = pythonize::pythonize(py, &collection)?.extract()?;
Ok(collection)
}
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod arrow;
mod cli;
mod collection;
mod duckdb;
mod error;
mod migrate;
Expand All @@ -27,6 +28,10 @@ fn rustac(py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(arrow::from_arrow, m)?)?;
m.add_function(wrap_pyfunction!(arrow::to_arrow, m)?)?;
m.add_function(wrap_pyfunction!(cli::main, m)?)?;
m.add_function(wrap_pyfunction!(
collection::collection_from_id_and_items,
m
)?)?;
m.add_function(wrap_pyfunction!(migrate::migrate, m)?)?;
m.add_function(wrap_pyfunction!(read::read, m)?)?;
m.add_function(wrap_pyfunction!(search::search, m)?)?;
Expand Down
12 changes: 12 additions & 0 deletions tests/test_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pathlib import Path

import rustac
from pystac import Collection


async def test_collection_from_id_and_items(data: Path) -> None:
items = await rustac.read(str(data / "100-sentinel-2-items.parquet"))
collection = Collection.from_dict(
rustac.collection_from_id_and_items("a-collection", items["features"]) # type: ignore
)
collection.validate()