stac
STAC-specific utilities.
ensure_type(data: dict[str, Any], key: str, expected_type: type[T], default_factory: Callable[[], T] | None = None) -> T
¶
Ensure a dictionary value conforms to the expected type.
If the value doesn't exist or is not an instance of the expected type, it will be replaced with the default value from default_factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
The dictionary containing the value |
required |
key
|
str
|
The key to check |
required |
expected_type
|
type[T]
|
The expected type class |
required |
default_factory
|
Callable[[], T] | None
|
Optional callable that returns the default value. If not provided, expected_type will be called with no arguments. |
None
|
Returns:
| Type | Description |
|---|---|
T
|
The value from the dictionary if it's the correct type, otherwise the default value |
Example
data = {"stac_extensions": None} extensions = ensure_type(data, "stac_extensions", list)
extensions is now [] and data["stac_extensions"] is []¶
data = {"items": "invalid"} items = ensure_type(data, "items", list, lambda: ["default"])
items is now ["default"] with custom factory¶
Source code in src/stac_auth_proxy/utils/stac.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
get_links(data: dict) -> chain[dict]
¶
Get all links from a STAC response.
Source code in src/stac_auth_proxy/utils/stac.py
61 62 63 64 65 66 67 68 69 70 71 72 73 | |