stac-fastapi.pgstac 7.2.2__tar.gz → 7.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/PKG-INFO +2 -2
  2. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/pyproject.toml +6 -5
  3. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/core.py +16 -0
  4. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/catalogs/catalogs_client.py +31 -20
  5. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/catalogs/catalogs_database_logic.py +10 -2
  6. stac_fastapi_pgstac-7.3.0/stac_fastapi/pgstac/extensions/catalogs/types.py +48 -0
  7. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/models/extensions.py +49 -3
  8. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/version.py +1 -1
  9. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/.gitignore +0 -0
  10. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/LICENSE +0 -0
  11. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/README.md +0 -0
  12. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/__init__.py +0 -0
  13. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/app.py +0 -0
  14. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/config.py +0 -0
  15. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/db.py +0 -0
  16. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/__init__.py +0 -0
  17. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/catalogs/__init__.py +0 -0
  18. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/catalogs/catalogs_links.py +0 -0
  19. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/filter.py +0 -0
  20. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/free_text.py +0 -0
  21. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/extensions/query.py +0 -0
  22. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/models/__init__.py +0 -0
  23. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/models/links.py +0 -0
  24. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/transactions.py +0 -0
  25. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/types/base_item_cache.py +0 -0
  26. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/types/search.py +0 -0
  27. {stac_fastapi_pgstac-7.2.2 → stac_fastapi_pgstac-7.3.0}/stac_fastapi/pgstac/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: stac-fastapi-pgstac
3
- Version: 7.2.2
3
+ Version: 7.3.0
4
4
  Summary: An implementation of STAC API based on the FastAPI framework and using the pgstac backend.
5
5
  Project-URL: Homepage, https://github.com/stac-utils/stac-fastapi-pgstac
6
6
  Author-email: David Bitner <david@developmentseed.org>
@@ -33,7 +33,7 @@ Requires-Dist: stac-fastapi-api<8.0,>=7.0
33
33
  Requires-Dist: stac-fastapi-extensions<8.0,>=7.0
34
34
  Requires-Dist: stac-fastapi-types<8.0,>=7.0
35
35
  Provides-Extra: catalogs
36
- Requires-Dist: stac-fastapi-catalogs-extension<2.0,>=1.0.0; extra == 'catalogs'
36
+ Requires-Dist: stac-fastapi-catalogs-extension<2.0,>=1.1.0; extra == 'catalogs'
37
37
  Provides-Extra: metrics
38
38
  Requires-Dist: stac-fastapi-api[metrics]; extra == 'metrics'
39
39
  Provides-Extra: server
@@ -58,7 +58,7 @@ server = [
58
58
  "uvicorn[standard]==0.38.0"
59
59
  ]
60
60
  catalogs = [
61
- "stac-fastapi-catalogs-extension>=1.0.0,<2.0",
61
+ "stac-fastapi-catalogs-extension>=1.1.0,<2.0",
62
62
  ]
63
63
  metrics = [
64
64
  "stac-fastapi-api[metrics]",
@@ -72,15 +72,16 @@ dev = [
72
72
  "mirakuru>=2.0,<3.0",
73
73
  "pytest",
74
74
  "pytest-cov",
75
- "pytest-asyncio>=0.17,<1.3",
75
+ "pytest-asyncio>=1.5,<2",
76
76
  # tests only: ships the migrations to install every pgstac in the test matrix
77
77
  "pypgstac>=0.10,<0.11",
78
78
  "requests",
79
- "stac-fastapi-catalogs-extension>=1.0.0,<2.0",
79
+ "stac-fastapi-catalogs-extension>=1.1.0,<2.0",
80
80
  "stac-fastapi-api[metrics]",
81
81
  "httpx",
82
82
  "psycopg[pool,binary]==3.2.*",
83
83
  "pre-commit",
84
+ "pytest-xdist>=3.6",
84
85
  ]
85
86
  docs = [
86
87
  "black>=23.10.1",
@@ -114,7 +115,7 @@ publish-url = "https://test.pypi.org/legacy/"
114
115
  explicit = true
115
116
 
116
117
  [tool.pytest.ini_options]
117
- addopts = "-sv"
118
+ addopts = "-sv -n auto"
118
119
  testpaths = [
119
120
  "tests"
120
121
  ]
@@ -150,7 +151,7 @@ ignore = [
150
151
  ]
151
152
 
152
153
  [tool.bumpversion]
153
- current_version = "7.2.2"
154
+ current_version = "7.3.0"
154
155
  parse = """(?x)
155
156
  (?P<major>\\d+)\\.
156
157
  (?P<minor>\\d+)\\.
@@ -125,6 +125,8 @@ class CoreCrudClient(AsyncBaseCoreClient):
125
125
  # When CollectionSearchExtension is disabled, use a high limit to return all collections
126
126
  clean_args = {"limit": limit or 10000, "offset": offset or 0}
127
127
 
128
+ reject_collection_parent_ids_sort(clean_args)
129
+
128
130
  # Add filter to ensure only Collections are returned (not Catalogs)
129
131
  # This is needed because catalogs are also stored in the collections table
130
132
  # pgstac rejects a `query` + `filter` payload, so the type constraint is
@@ -726,6 +728,19 @@ def join_free_text_query(args: dict[str, Any]) -> None:
726
728
  args["q"] = " OR ".join(q) if isinstance(q, list) else q
727
729
 
728
730
 
731
+ def reject_collection_parent_ids_sort(clean_args: dict[str, Any]) -> None:
732
+ """Reject `parent_ids` as a collection sort field.
733
+
734
+ `parent_ids` is pgstac-internal catalog metadata, not a collection
735
+ sortable, but pgstac accepts it silently.
736
+ """
737
+ for sort in clean_args.get("sortby") or []:
738
+ if sort.get("field") == "parent_ids":
739
+ raise InvalidQueryParameter(
740
+ "Sorting collections by 'parent_ids' is not supported."
741
+ )
742
+
743
+
729
744
  def clean_collection_search_args(
730
745
  base_args: dict[str, Any],
731
746
  **kwargs: Any,
@@ -733,6 +748,7 @@ def clean_collection_search_args(
733
748
  """Clean up collection search arguments to match `collection_search()`"""
734
749
  clean = clean_search_args(base_args, **kwargs)
735
750
  join_free_text_query(clean)
751
+ reject_collection_parent_ids_sort(clean)
736
752
  return clean
737
753
 
738
754
 
@@ -12,7 +12,6 @@ from stac_fastapi.types.requests import get_base_url
12
12
  from stac_fastapi.types.stac import ItemCollection
13
13
  from stac_fastapi_catalogs_extension import (
14
14
  CATALOGS_CORE_CONFORMANCE,
15
- CATALOGS_TRANSACTION_CONFORMANCE,
16
15
  )
17
16
  from stac_fastapi_catalogs_extension.client import AsyncBaseCatalogsClient
18
17
  from stac_fastapi_catalogs_extension.types import Children
@@ -64,6 +63,7 @@ class CatalogsClient(AsyncBaseCatalogsClient):
64
63
  """
65
64
 
66
65
  database: CatalogsDatabaseLogic = attr.ib()
66
+ scoped_conformance_classes: list[str] = attr.ib(factory=list, kw_only=True)
67
67
 
68
68
  @staticmethod
69
69
  async def _add_catalog_links(
@@ -441,12 +441,6 @@ class CatalogsClient(AsyncBaseCatalogsClient):
441
441
  "title": "Queryables",
442
442
  "href": base_url + f"/collections/{collection_id}/queryables",
443
443
  },
444
- {
445
- "rel": "http://www.opengis.net/def/rel/ogc/1.0/sortables",
446
- "type": "application/schema+json",
447
- "title": "Sortables",
448
- "href": base_url + f"/collections/{collection_id}/sortables",
449
- },
450
444
  ]
451
445
 
452
446
  @staticmethod
@@ -518,6 +512,8 @@ class CatalogsClient(AsyncBaseCatalogsClient):
518
512
  limit: int | None = None,
519
513
  token: str | None = None,
520
514
  request: Request | None = None,
515
+ bbox: list[float] | None = None,
516
+ datetime: str | None = None,
521
517
  fields: list[str] | None = None,
522
518
  sortby: list[str] | None = None,
523
519
  q: list[str] | None = None,
@@ -535,6 +531,8 @@ class CatalogsClient(AsyncBaseCatalogsClient):
535
531
  limit: The maximum number of collections to return.
536
532
  token: The pagination token.
537
533
  request: The FastAPI request object.
534
+ bbox: Bounding box matching the collection spatial extents.
535
+ datetime: Datetime matching the collection temporal extents.
538
536
  fields: Fields extension include/exclude list.
539
537
  sortby: Sort extension fields, prefixed with `+` or `-`.
540
538
  q: Free text search terms.
@@ -548,7 +546,8 @@ class CatalogsClient(AsyncBaseCatalogsClient):
548
546
  limit, token = CatalogsClient._extract_limit_and_token(limit, token, request)
549
547
 
550
548
  search = clean_collection_search_args(
551
- base_args={},
549
+ base_args={"bbox": bbox},
550
+ datetime=datetime,
552
551
  fields=fields,
553
552
  sortby=sortby,
554
553
  q=q,
@@ -902,6 +901,8 @@ class CatalogsClient(AsyncBaseCatalogsClient):
902
901
  limit: int | None = None,
903
902
  token: str | None = None,
904
903
  request: Request | None = None,
904
+ bbox: list[float] | None = None,
905
+ datetime: str | None = None,
905
906
  **kwargs,
906
907
  ) -> ItemCollection:
907
908
  """Get items from a collection in a catalog.
@@ -914,6 +915,8 @@ class CatalogsClient(AsyncBaseCatalogsClient):
914
915
  limit: The maximum number of items to return.
915
916
  token: The pagination token.
916
917
  request: The FastAPI request object.
918
+ bbox: Bounding box to filter items.
919
+ datetime: Datetime to filter items.
917
920
  **kwargs: Additional keyword arguments.
918
921
 
919
922
  Returns:
@@ -945,8 +948,13 @@ class CatalogsClient(AsyncBaseCatalogsClient):
945
948
  "limit": limit,
946
949
  }
947
950
 
948
- if token:
949
- search_query["token"] = token
951
+ for key, value in (
952
+ ("token", token),
953
+ ("bbox", bbox),
954
+ ("datetime", datetime),
955
+ ):
956
+ if value:
957
+ search_query[key] = value
950
958
 
951
959
  # Execute search and get full item collection with links
952
960
  async with request.app.state.get_connection(request, "r") as conn:
@@ -1099,16 +1107,21 @@ class CatalogsClient(AsyncBaseCatalogsClient):
1099
1107
 
1100
1108
  async def get_catalog_conformance(
1101
1109
  self, catalog_id: str, request: Request | None = None, **kwargs
1102
- ) -> JSONResponse:
1110
+ ) -> dict[str, Any]:
1103
1111
  """Get conformance classes for a catalog.
1104
1112
 
1113
+ Returns a dict rather than a Response so the extension merges in the
1114
+ conformance classes registered on `app.state.catalogs_conformance_classes`
1115
+ (core, marker, and transaction classes when the transaction extension is
1116
+ registered).
1117
+
1105
1118
  Args:
1106
1119
  catalog_id: The ID of the catalog.
1107
1120
  request: The FastAPI request object.
1108
1121
  **kwargs: Additional keyword arguments.
1109
1122
 
1110
1123
  Returns:
1111
- JSONResponse containing conformance classes.
1124
+ Dictionary containing conformance classes.
1112
1125
 
1113
1126
  Raises:
1114
1127
  NotFoundError: If the catalog does not exist.
@@ -1117,14 +1130,12 @@ class CatalogsClient(AsyncBaseCatalogsClient):
1117
1130
  if request:
1118
1131
  await self.database.find_catalog(catalog_id, request=request)
1119
1132
 
1120
- return JSONResponse(
1121
- content={
1122
- "conformsTo": [
1123
- *CATALOGS_CORE_CONFORMANCE,
1124
- *CATALOGS_TRANSACTION_CONFORMANCE,
1125
- ]
1126
- }
1127
- )
1133
+ return {
1134
+ "conformsTo": [
1135
+ *CATALOGS_CORE_CONFORMANCE,
1136
+ *self.scoped_conformance_classes,
1137
+ ]
1138
+ }
1128
1139
 
1129
1140
  async def get_catalog_queryables(
1130
1141
  self, catalog_id: str, request: Request | None = None, **kwargs
@@ -406,7 +406,8 @@ class CatalogsDatabaseLogic:
406
406
  request: The FastAPI request object.
407
407
  sort: Sort order. Takes precedence over `search["sortby"]`.
408
408
  search: Collection search parameters in `collection_search()` form.
409
- Only `filter` (CQL2-JSON), `fields`, `sortby`, `q` and `filter_lang` are used.
409
+ Only `filter` (CQL2-JSON), `bbox`, `datetime`, `fields`, `sortby`, `q`
410
+ and `filter_lang` are used.
410
411
  `filter` is ANDed onto the catalog scoping clauses, so it can only narrow the result.
411
412
 
412
413
  Returns:
@@ -448,7 +449,14 @@ class CatalogsDatabaseLogic:
448
449
  # ANDed onto the scoping so it can't return Catalogs or another catalog's collections
449
450
  if search.get("filter") is not None:
450
451
  filter_args.append(search["filter"])
451
- for key in ("fields", "sortby", "q", "filter_lang"):
452
+ for key in (
453
+ "bbox",
454
+ "datetime",
455
+ "fields",
456
+ "sortby",
457
+ "q",
458
+ "filter_lang",
459
+ ):
452
460
  if key in search:
453
461
  search_query[key] = search[key]
454
462
 
@@ -0,0 +1,48 @@
1
+ """Request types for the catalogs extension."""
2
+
3
+ from typing import Annotated
4
+
5
+ import attr
6
+ from fastapi import Query
7
+ from stac_fastapi.types.search import (
8
+ DateTimeQueryType,
9
+ _bbox_converter,
10
+ _validate_datetime,
11
+ )
12
+ from stac_fastapi_catalogs_extension.types import (
13
+ CatalogCollectionItemsRequest,
14
+ CatalogCollectionsRequest,
15
+ )
16
+ from stac_pydantic.shared import BBox
17
+
18
+
19
+ @attr.s
20
+ class PgstacCatalogCollectionsRequest(CatalogCollectionsRequest):
21
+ """Request model for `GET /catalogs/{catalog_id}/collections`.
22
+
23
+ Adds the Collection Search `bbox` and `datetime` parameters on top of the
24
+ library's pagination primitives so the scoped listing can claim the
25
+ `multi-tenant-catalogs#collection-search` marker, which requires the
26
+ Collection Search Basics.
27
+ """
28
+
29
+ bbox: Annotated[
30
+ BBox | None,
31
+ Query(description="Bounding box to filter collections [minx, miny, maxx, maxy]"),
32
+ ] = attr.ib(
33
+ default=None,
34
+ converter=lambda x: _bbox_converter(x) if x is not None else None,
35
+ )
36
+ datetime: DateTimeQueryType = attr.ib(default=None, validator=_validate_datetime)
37
+
38
+
39
+ @attr.s
40
+ class PgstacCatalogCollectionItemsRequest(CatalogCollectionItemsRequest):
41
+ """Request model for `GET /catalogs/{catalog_id}/collections/{collection_id}/items`.
42
+
43
+ Re-declares the library's `datetime` parameter with the same RFC 3339
44
+ validator `GET /collections/{collection_id}/items` uses, so invalid values
45
+ are rejected with a 400 instead of reaching pgstac and erroring with a 500.
46
+ """
47
+
48
+ datetime: DateTimeQueryType = attr.ib(default=None, validator=_validate_datetime)
@@ -13,6 +13,7 @@ from stac_fastapi.extensions import (
13
13
  TokenPaginationExtension,
14
14
  TransactionExtension,
15
15
  )
16
+ from stac_fastapi.extensions.collection_search import CollectionSearchConformanceClasses
16
17
  from stac_fastapi.extensions.fields import FieldsConformanceClasses
17
18
  from stac_fastapi.extensions.filter import FilterConformanceClasses
18
19
  from stac_fastapi.extensions.free_text import FreeTextConformanceClasses
@@ -86,6 +87,10 @@ def get_default_extensions_map(key: str) -> dict[str, ApiExtension]:
86
87
  return extensions
87
88
 
88
89
 
90
+ CATALOGS_COLLECTION_SEARCH_MARKER = (
91
+ "https://api.stacspec.org/v1.0.0/multi-tenant-catalogs#collection-search"
92
+ )
93
+
89
94
  logger = logging.getLogger(__name__)
90
95
 
91
96
 
@@ -169,7 +174,7 @@ class Extensions:
169
174
  if self.settings.enable_catalogs_extension:
170
175
  try:
171
176
  from stac_fastapi_catalogs_extension import (
172
- CatalogCollectionsRequest,
177
+ CATALOGS_CORE_CONFORMANCE,
173
178
  CatalogsExtension,
174
179
  CatalogsTransactionExtension,
175
180
  )
@@ -188,6 +193,10 @@ class Extensions:
188
193
  from stac_fastapi.pgstac.extensions.catalogs.catalogs_database_logic import (
189
194
  CatalogsDatabaseLogic,
190
195
  )
196
+ from stac_fastapi.pgstac.extensions.catalogs.types import (
197
+ PgstacCatalogCollectionItemsRequest,
198
+ PgstacCatalogCollectionsRequest,
199
+ )
191
200
 
192
201
  # No Query or pagination, the route pages with token/offset and has no `query`
193
202
  enabled_keys = self.settings.enabled_extensions
@@ -199,13 +208,41 @@ class Extensions:
199
208
  ]
200
209
  catalog_collections_get_request_model = create_request_model(
201
210
  model_name="CatalogCollectionsRequest",
202
- base_model=CatalogCollectionsRequest,
211
+ base_model=PgstacCatalogCollectionsRequest,
203
212
  extensions=catalog_collections_extensions,
204
213
  request_type="GET",
205
214
  )
206
215
 
216
+ # The marker binds the scoped listing to the root's Collection Search
217
+ # class. Only declare it when collection search is on: the
218
+ # v1.0.0/collection-search base in the library's
219
+ # CATALOGS_COLLECTION_SEARCH_CONFORMANCE is not used here because the
220
+ # CollectionSearchExtension already registers the v1.0.0-rc.1 base.
221
+ collection_search_enabled = (
222
+ enabled_keys is None or "collection_search" in enabled_keys
223
+ )
224
+ scoped_collection_search_classes = (
225
+ [
226
+ CATALOGS_COLLECTION_SEARCH_MARKER,
227
+ CollectionSearchConformanceClasses.COLLECTIONSEARCH.value,
228
+ CollectionSearchConformanceClasses.BASIS.value,
229
+ *(
230
+ uri
231
+ for ext in catalog_collections_extensions
232
+ for uri in ext.conformance_classes
233
+ ),
234
+ ]
235
+ if collection_search_enabled
236
+ else []
237
+ )
238
+
207
239
  try:
208
- catalogs_client = CatalogsClient(database=CatalogsDatabaseLogic())
240
+ catalogs_client = CatalogsClient(
241
+ database=CatalogsDatabaseLogic(),
242
+ scoped_conformance_classes=list(
243
+ dict.fromkeys(scoped_collection_search_classes)
244
+ ),
245
+ )
209
246
 
210
247
  # Register the read-only catalogs extension
211
248
  catalogs_extension = CatalogsExtension(
@@ -213,8 +250,17 @@ class Extensions:
213
250
  settings={
214
251
  "enable_response_models": self.settings.enable_response_models
215
252
  },
253
+ conformance_classes=[
254
+ *CATALOGS_CORE_CONFORMANCE,
255
+ *(
256
+ [CATALOGS_COLLECTION_SEARCH_MARKER]
257
+ if collection_search_enabled
258
+ else []
259
+ ),
260
+ ],
216
261
  hide_alternate_parents=self.settings.hide_alternate_parents,
217
262
  catalog_collections_get_request_model=catalog_collections_get_request_model,
263
+ catalog_collection_items_get_request_model=PgstacCatalogCollectionItemsRequest,
218
264
  )
219
265
  logger.info("CatalogsExtension (read-only) enabled successfully.")
220
266
 
@@ -1,3 +1,3 @@
1
1
  """library version."""
2
2
 
3
- __version__ = "7.2.2"
3
+ __version__ = "7.3.0"