Skip to content

Search

stacrs.search async

search(href: str, *, intersects: Optional[str | dict[str, Any]] = None, ids: Optional[str | list[str]] = None, collections: Optional[str | list[str]] = None, max_items: Optional[int] = None, limit: Optional[int] = None, bbox: Optional[list[float]] = None, datetime: Optional[str] = None, include: Optional[str | list[str]] = None, exclude: Optional[str | list[str]] = None, sortby: Optional[str | list[str]] = None, filter: Optional[str | dict[str, Any]] = None, query: Optional[dict[str, Any]] = None, use_duckdb: Optional[bool] = None, **kwargs: str) -> list[dict[str, Any]]

Searches a STAC API server.

Parameters:

  • href (str) –

    The STAC API to search.

  • intersects (str | dict[str, Any] | GeoInterface | None, default: None ) –

    Searches items by performing intersection between their geometry and provided GeoJSON geometry.

  • ids (list[str] | None, default: None ) –

    Array of Item ids to return.

  • collections (list[str] | None, default: None ) –

    Array of one or more Collection IDs that each matching Item must be in.

  • max_items (int | None, default: None ) –

    The maximum number of items to iterate through.

  • limit (int | None, default: None ) –

    The page size returned from the server. Use max_items to actually limit the number of items returned from this function.

  • bbox (list[float] | None, default: None ) –

    Requested bounding box.

  • datetime (str | None, default: None ) –

    Single date+time, or a range (/ separator), formatted to RFC 3339, section 5.6. Use double dots .. for open date ranges.

  • include (list[str]] | None, default: None ) –

    fields to include in the response (see the extension docs) for more on the semantics).

  • exclude (list[str]] | None, default: None ) –

    fields to exclude from the response (see the extension docs) for more on the semantics).

  • sortby (list[str] | None, default: None ) –

    Fields by which to sort results (use -field to sort descending).

  • filter (str | dict[str, Any] | none, default: None ) –

    CQL2 filter expression. Strings will be interpreted as cql2-text, dictionaries as cql2-json.

  • query (dict[str, Any] | None, default: None ) –

    Additional filtering based on properties. It is recommended to use filter instead, if possible.

  • use_duckdb (bool | None, default: None ) –

    Query with DuckDB. If None and the href has a 'parquet' or 'geoparquet' extension, will be set to True. Defaults to None.

  • kwargs (str, default: {} ) –

    Additional parameters to pass in to the search.

Returns:

  • list[dict[str, Any]]

    list[dict[str, Any]]: A list of the returned STAC items.

Examples:

>>> items = await stacrs.search(
...     "https://landsatlook.usgs.gov/stac-server",
...     collections=["landsat-c2l2-sr"],
...     intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
...     sortby="-properties.datetime",
...     max_items=1,
... )

stacrs.search_to async

search_to(outfile: str, href: str, *, intersects: Optional[str | dict[str, Any]] = None, ids: Optional[str | list[str]] = None, collections: Optional[str | list[str]] = None, max_items: Optional[int] = None, limit: Optional[int] = None, bbox: Optional[list[float]] = None, datetime: Optional[str] = None, include: Optional[str | list[str]] = None, exclude: Optional[str | list[str]] = None, sortby: Optional[str | list[str]] = None, filter: Optional[str | dict[str, Any]] = None, query: Optional[dict[str, Any]] = None, format: Optional[str] = None, options: Optional[list[Tuple[str, str]]] = None, use_duckdb: Optional[bool] = None) -> int

Searches a STAC API server and saves the result to an output file.

Parameters:

  • outfile (str) –

    The output href. This can be a local file path, or any url scheme supported by [stac::object_store::write].

  • href (str) –

    The STAC API to search.

  • intersects (str | dict[str, Any] | GeoInterface | None, default: None ) –

    Searches items by performing intersection between their geometry and provided GeoJSON geometry.

  • ids (list[str] | None, default: None ) –

    Array of Item ids to return.

  • collections (list[str] | None, default: None ) –

    Array of one or more Collection IDs that each matching Item must be in.

  • max_items (int | None, default: None ) –

    The maximum number of items to iterate through.

  • limit (int | None, default: None ) –

    The page size returned from the server. Use max_items to actually limit the number of items returned from this function.

  • bbox (list[float] | None, default: None ) –

    Requested bounding box.

  • datetime (str | None, default: None ) –

    Single date+time, or a range ('/' separator), formatted to RFC 3339, section 5.6. Use double dots .. for open date ranges.

  • include (list[str]] | None, default: None ) –

    fields to include in the response (see the extension docs) for more on the semantics).

  • exclude (list[str]] | None, default: None ) –

    fields to exclude from the response (see the extension docs) for more on the semantics).

  • sortby (list[str] | None, default: None ) –

    Fields by which to sort results (use -field to sort descending).

  • filter (str | dict[str, Any] | none, default: None ) –

    CQL2 filter expression. Strings will be interpreted as cql2-text, dictionaries as cql2-json.

  • query (dict[str, Any] | None, default: None ) –

    Additional filtering based on properties. It is recommended to use filter instead, if possible.

  • format (str | None, default: None ) –

    The output format. If none, will be inferred from the outfile extension, and if that fails will fall back to compact JSON.

  • options (list[tuple[str, str]] | None, default: None ) –

    Configuration values to pass to the object store backend.

  • use_duckdb (bool | None, default: None ) –

    Query with DuckDB. If None and the href has a 'parquet' or 'geoparquet' extension, will be set to True. Defaults to None.

Returns:

  • int ( int ) –

    The number of items written

Examples:

>>> count = await stacrs.search_to("out.parquet",
...     "https://landsatlook.usgs.gov/stac-server",
...     collections=["landsat-c2l2-sr"],
...     intersects={"type": "Point", "coordinates": [-105.119, 40.173]},
...     sortby="-properties.datetime",
...     max_items=1,
... )