Skip to content

API

The stac-hash Python API. The Rust API docs live on docs.rs.

stac_hash.Hasher

Hasher(
    start_datetime: datetime,
    end_datetime: datetime,
    bbox: tuple[float, float, float, float] | None = None,
)

Creates sortable spatio-temporal hashes.

The hasher is built from a datetime range and, optionally, a bounding box. Without a bbox the hasher covers the whole world.

hash

hash(datetime: datetime, longitude: float, latitude: float) -> int

Hashes a datetime and a point into an int.

hash_all

hash_all(
    datetimes: Sequence[datetime],
    longitudes: Sequence[float],
    latitudes: Sequence[float],
    skip_invalid: Literal[False] = False,
) -> list[int]
hash_all(
    datetimes: Sequence[datetime],
    longitudes: Sequence[float],
    latitudes: Sequence[float],
    skip_invalid: Literal[True],
) -> list[int | None]
hash_all(
    datetimes: Sequence[datetime],
    longitudes: Sequence[float],
    latitudes: Sequence[float],
    skip_invalid: bool,
) -> list[int | None]
hash_all(
    datetimes: Sequence[datetime],
    longitudes: Sequence[float],
    latitudes: Sequence[float],
    skip_invalid: bool = False,
) -> list[int] | list[int | None]

Hashes parallel sequences of datetimes, longitudes, and latitudes.

Raises a ValueError if the sequences are not the same length, or if any item falls outside the hasher's extent. Pass skip_invalid=True to get None for out-of-extent items instead of raising.

hash_all_clamped

hash_all_clamped(
    datetimes: Sequence[datetime],
    longitudes: Sequence[float],
    latitudes: Sequence[float],
) -> list[int]

Hashes parallel sequences, clamping onto the hasher's boundary.

Raises a ValueError only if the sequences are not the same length. No item can fall outside the extent, so there is no skip_invalid.

hash_clamped

hash_clamped(datetime: datetime, longitude: float, latitude: float) -> int

Hashes a datetime and a point, clamping onto the hasher's boundary.

Unlike hash, this never raises for out-of-extent input. A datetime before the hasher's start hashes as that start, a longitude west of the minimum hashes as that minimum, and so on.