Skip to content

core

stac_fastapi.types.core

Base clients.

AsyncBaseCoreClient

Bases: LandingPageMixin, ABC

Defines a pattern for implementing STAC api core endpoints.

Attributes:

Source code in stac_fastapi/types/core.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
@attr.s  # type:ignore
class AsyncBaseCoreClient(LandingPageMixin, abc.ABC):
    """Defines a pattern for implementing STAC api core endpoints.

    Attributes:
        extensions: list of registered api extensions.
    """

    base_conformance_classes: List[str] = attr.ib(
        factory=lambda: BASE_CONFORMANCE_CLASSES
    )
    extensions: List[ApiExtension] = attr.ib(default=attr.Factory(list))

    def conformance_classes(self) -> List[str]:
        """Generate conformance classes by adding extension conformance to base
        conformance classes."""
        conformance_classes = self.base_conformance_classes.copy()

        for extension in self.extensions:
            extension_classes = getattr(extension, "conformance_classes", [])
            conformance_classes.extend(extension_classes)

        return sorted(list(set(conformance_classes)))

    def extension_is_enabled(self, extension: str) -> bool:
        """Check if an api extension is enabled."""
        return any([type(ext).__name__ == extension for ext in self.extensions])

    async def landing_page(self, **kwargs) -> stac.LandingPage:
        """Landing page.

        Called with `GET /`.

        Returns:
            API landing page, serving as an entry point to the API.
        """
        request: Request = kwargs["request"]
        base_url = get_base_url(request)

        landing_page = self._landing_page(
            base_url=base_url,
            conformance_classes=self.conformance_classes(),
            extension_schemas=[],
        )

        # Add Queryables link
        if self.extension_is_enabled("FilterExtension") or self.extension_is_enabled(
            "SearchFilterExtension"
        ):
            landing_page["links"].append(
                {
                    "rel": Relations.queryables.value,
                    "type": MimeTypes.jsonschema.value,
                    "title": "Queryables available for this Catalog",
                    "href": urljoin(base_url, "queryables"),
                    "method": "GET",
                }
            )

        # Add Aggregation links
        if self.extension_is_enabled("AggregationExtension"):
            landing_page["links"].extend(
                [
                    {
                        "rel": "aggregate",
                        "type": "application/json",
                        "title": "Aggregate",
                        "href": urljoin(base_url, "aggregate"),
                    },
                    {
                        "rel": "aggregations",
                        "type": "application/json",
                        "title": "Aggregations",
                        "href": urljoin(base_url, "aggregations"),
                    },
                ]
            )

        # Add OpenAPI URL
        landing_page["links"].append(
            {
                "rel": Relations.service_desc.value,
                "type": MimeTypes.openapi.value,
                "title": "OpenAPI service description",
                "href": str(request.url_for("openapi")),
            }
        )

        # Add human readable service-doc
        landing_page["links"].append(
            {
                "rel": Relations.service_doc.value,
                "type": MimeTypes.html.value,
                "title": "OpenAPI service documentation",
                "href": str(request.url_for("swagger_ui_html")),
            }
        )

        return stac.LandingPage(**landing_page)

    async def conformance(self, **kwargs) -> stac.Conformance:
        """Conformance classes.

        Called with `GET /conformance`.

        Returns:
            Conformance classes which the server conforms to.
        """
        return stac.Conformance(conformsTo=self.conformance_classes())

    @abc.abstractmethod
    async def post_search(
        self, search_request: BaseSearchPostRequest, **kwargs
    ) -> stac.ItemCollection:
        """Cross catalog search (POST).

        Called with `POST /search`.

        Args:
            search_request: search request parameters.

        Returns:
            ItemCollection containing items which match the search criteria.
        """
        ...

    @abc.abstractmethod
    async def get_search(
        self,
        collections: Optional[List[str]] = None,
        ids: Optional[List[str]] = None,
        bbox: Optional[BBox] = None,
        intersects: Optional[Geometry] = None,
        datetime: Optional[str] = None,
        limit: Optional[int] = 10,
        **kwargs,
    ) -> stac.ItemCollection:
        """Cross catalog search (GET).

        Called with `GET /search`.

        Returns:
            ItemCollection containing items which match the search criteria.
        """
        ...

    @abc.abstractmethod
    async def get_item(self, item_id: str, collection_id: str, **kwargs) -> stac.Item:
        """Get item by id.

        Called with `GET /collections/{collection_id}/items/{item_id}`.

        Args:
            item_id: Id of the item.
            collection_id: Id of the collection.

        Returns:
            Item.
        """
        ...

    @abc.abstractmethod
    async def all_collections(self, **kwargs) -> stac.Collections:
        """Get all available collections.

        Called with `GET /collections`.

        Returns:
            A list of collections.
        """
        ...

    @abc.abstractmethod
    async def get_collection(self, collection_id: str, **kwargs) -> stac.Collection:
        """Get collection by id.

        Called with `GET /collections/{collection_id}`.

        Args:
            collection_id: Id of the collection.

        Returns:
            Collection.
        """
        ...

    @abc.abstractmethod
    async def item_collection(
        self,
        collection_id: str,
        bbox: Optional[BBox] = None,
        datetime: Optional[str] = None,
        limit: int = 10,
        token: Optional[str] = None,
        **kwargs,
    ) -> stac.ItemCollection:
        """Get all items from a specific collection.

        Called with `GET /collections/{collection_id}/items`

        Args:
            collection_id: id of the collection.
            limit: number of items to return.
            token: pagination token.

        Returns:
            An ItemCollection.
        """
        ...

all_collections abstractmethod async

all_collections(**kwargs) -> Collections

Get all available collections.

Called with GET /collections.

Returns:

Source code in stac_fastapi/types/core.py
484
485
486
487
488
489
490
491
492
493
@abc.abstractmethod
async def all_collections(self, **kwargs) -> stac.Collections:
    """Get all available collections.

    Called with `GET /collections`.

    Returns:
        A list of collections.
    """
    ...

conformance async

conformance(**kwargs) -> Conformance

Conformance classes.

Called with GET /conformance.

Returns:

  • Conformance

    Conformance classes which the server conforms to.

Source code in stac_fastapi/types/core.py
423
424
425
426
427
428
429
430
431
async def conformance(self, **kwargs) -> stac.Conformance:
    """Conformance classes.

    Called with `GET /conformance`.

    Returns:
        Conformance classes which the server conforms to.
    """
    return stac.Conformance(conformsTo=self.conformance_classes())

conformance_classes

conformance_classes() -> List[str]

Generate conformance classes by adding extension conformance to base conformance classes.

Source code in stac_fastapi/types/core.py
336
337
338
339
340
341
342
343
344
345
def conformance_classes(self) -> List[str]:
    """Generate conformance classes by adding extension conformance to base
    conformance classes."""
    conformance_classes = self.base_conformance_classes.copy()

    for extension in self.extensions:
        extension_classes = getattr(extension, "conformance_classes", [])
        conformance_classes.extend(extension_classes)

    return sorted(list(set(conformance_classes)))

extension_is_enabled

extension_is_enabled(extension: str) -> bool

Check if an api extension is enabled.

Source code in stac_fastapi/types/core.py
347
348
349
def extension_is_enabled(self, extension: str) -> bool:
    """Check if an api extension is enabled."""
    return any([type(ext).__name__ == extension for ext in self.extensions])

get_collection abstractmethod async

get_collection(collection_id: str, **kwargs) -> Collection

Get collection by id.

Called with GET /collections/{collection_id}.

Parameters:

  • collection_id (str) –

    Id of the collection.

Returns:

Source code in stac_fastapi/types/core.py
495
496
497
498
499
500
501
502
503
504
505
506
507
@abc.abstractmethod
async def get_collection(self, collection_id: str, **kwargs) -> stac.Collection:
    """Get collection by id.

    Called with `GET /collections/{collection_id}`.

    Args:
        collection_id: Id of the collection.

    Returns:
        Collection.
    """
    ...

get_item abstractmethod async

get_item(item_id: str, collection_id: str, **kwargs) -> Item

Get item by id.

Called with GET /collections/{collection_id}/items/{item_id}.

Parameters:

  • item_id (str) –

    Id of the item.

  • collection_id (str) –

    Id of the collection.

Returns:

Source code in stac_fastapi/types/core.py
469
470
471
472
473
474
475
476
477
478
479
480
481
482
@abc.abstractmethod
async def get_item(self, item_id: str, collection_id: str, **kwargs) -> stac.Item:
    """Get item by id.

    Called with `GET /collections/{collection_id}/items/{item_id}`.

    Args:
        item_id: Id of the item.
        collection_id: Id of the collection.

    Returns:
        Item.
    """
    ...
get_search(
    collections: Optional[List[str]] = None,
    ids: Optional[List[str]] = None,
    bbox: Optional[BBox] = None,
    intersects: Optional[Geometry] = None,
    datetime: Optional[str] = None,
    limit: Optional[int] = 10,
    **kwargs
) -> ItemCollection

Cross catalog search (GET).

Called with GET /search.

Returns:

  • ItemCollection

    ItemCollection containing items which match the search criteria.

Source code in stac_fastapi/types/core.py
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
@abc.abstractmethod
async def get_search(
    self,
    collections: Optional[List[str]] = None,
    ids: Optional[List[str]] = None,
    bbox: Optional[BBox] = None,
    intersects: Optional[Geometry] = None,
    datetime: Optional[str] = None,
    limit: Optional[int] = 10,
    **kwargs,
) -> stac.ItemCollection:
    """Cross catalog search (GET).

    Called with `GET /search`.

    Returns:
        ItemCollection containing items which match the search criteria.
    """
    ...

item_collection abstractmethod async

item_collection(
    collection_id: str,
    bbox: Optional[BBox] = None,
    datetime: Optional[str] = None,
    limit: int = 10,
    token: Optional[str] = None,
    **kwargs
) -> ItemCollection

Get all items from a specific collection.

Called with GET /collections/{collection_id}/items

Parameters:

  • collection_id (str) –

    id of the collection.

  • limit (int, default: 10 ) –

    number of items to return.

  • token (Optional[str], default: None ) –

    pagination token.

Returns:

Source code in stac_fastapi/types/core.py
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
@abc.abstractmethod
async def item_collection(
    self,
    collection_id: str,
    bbox: Optional[BBox] = None,
    datetime: Optional[str] = None,
    limit: int = 10,
    token: Optional[str] = None,
    **kwargs,
) -> stac.ItemCollection:
    """Get all items from a specific collection.

    Called with `GET /collections/{collection_id}/items`

    Args:
        collection_id: id of the collection.
        limit: number of items to return.
        token: pagination token.

    Returns:
        An ItemCollection.
    """
    ...

landing_page async

landing_page(**kwargs) -> LandingPage

Landing page.

Called with GET /.

Returns:

  • LandingPage

    API landing page, serving as an entry point to the API.

Source code in stac_fastapi/types/core.py
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
async def landing_page(self, **kwargs) -> stac.LandingPage:
    """Landing page.

    Called with `GET /`.

    Returns:
        API landing page, serving as an entry point to the API.
    """
    request: Request = kwargs["request"]
    base_url = get_base_url(request)

    landing_page = self._landing_page(
        base_url=base_url,
        conformance_classes=self.conformance_classes(),
        extension_schemas=[],
    )

    # Add Queryables link
    if self.extension_is_enabled("FilterExtension") or self.extension_is_enabled(
        "SearchFilterExtension"
    ):
        landing_page["links"].append(
            {
                "rel": Relations.queryables.value,
                "type": MimeTypes.jsonschema.value,
                "title": "Queryables available for this Catalog",
                "href": urljoin(base_url, "queryables"),
                "method": "GET",
            }
        )

    # Add Aggregation links
    if self.extension_is_enabled("AggregationExtension"):
        landing_page["links"].extend(
            [
                {
                    "rel": "aggregate",
                    "type": "application/json",
                    "title": "Aggregate",
                    "href": urljoin(base_url, "aggregate"),
                },
                {
                    "rel": "aggregations",
                    "type": "application/json",
                    "title": "Aggregations",
                    "href": urljoin(base_url, "aggregations"),
                },
            ]
        )

    # Add OpenAPI URL
    landing_page["links"].append(
        {
            "rel": Relations.service_desc.value,
            "type": MimeTypes.openapi.value,
            "title": "OpenAPI service description",
            "href": str(request.url_for("openapi")),
        }
    )

    # Add human readable service-doc
    landing_page["links"].append(
        {
            "rel": Relations.service_doc.value,
            "type": MimeTypes.html.value,
            "title": "OpenAPI service documentation",
            "href": str(request.url_for("swagger_ui_html")),
        }
    )

    return stac.LandingPage(**landing_page)
post_search(search_request: BaseSearchPostRequest, **kwargs) -> ItemCollection

Cross catalog search (POST).

Called with POST /search.

Parameters:

Returns:

  • ItemCollection

    ItemCollection containing items which match the search criteria.

Source code in stac_fastapi/types/core.py
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
@abc.abstractmethod
async def post_search(
    self, search_request: BaseSearchPostRequest, **kwargs
) -> stac.ItemCollection:
    """Cross catalog search (POST).

    Called with `POST /search`.

    Args:
        search_request: search request parameters.

    Returns:
        ItemCollection containing items which match the search criteria.
    """
    ...

BaseCoreClient

Bases: LandingPageMixin, ABC

Defines a pattern for implementing STAC api core endpoints.

Attributes:

Source code in stac_fastapi/types/core.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
@attr.s  # type:ignore
class BaseCoreClient(LandingPageMixin, abc.ABC):
    """Defines a pattern for implementing STAC api core endpoints.

    Attributes:
        extensions: list of registered api extensions.
    """

    base_conformance_classes: List[str] = attr.ib(
        factory=lambda: BASE_CONFORMANCE_CLASSES
    )
    extensions: List[ApiExtension] = attr.ib(default=attr.Factory(list))

    def conformance_classes(self) -> List[str]:
        """Generate conformance classes by adding extension conformance to base
        conformance classes."""
        base_conformance_classes = self.base_conformance_classes.copy()

        for extension in self.extensions:
            extension_classes = getattr(extension, "conformance_classes", [])
            base_conformance_classes.extend(extension_classes)

        return sorted(list(set(base_conformance_classes)))

    def extension_is_enabled(self, extension: str) -> bool:
        """Check if an api extension is enabled."""
        return any([type(ext).__name__ == extension for ext in self.extensions])

    def list_conformance_classes(self):
        """Return a list of conformance classes, including implemented extensions."""
        base_conformance = BASE_CONFORMANCE_CLASSES

        for extension in self.extensions:
            extension_classes = getattr(extension, "conformance_classes", [])
            base_conformance.extend(extension_classes)

        return base_conformance

    def landing_page(self, **kwargs) -> stac.LandingPage:
        """Landing page.

        Called with `GET /`.

        Returns:
            API landing page, serving as an entry point to the API.
        """
        request: Request = kwargs["request"]
        base_url = get_base_url(request)

        landing_page = self._landing_page(
            base_url=base_url,
            conformance_classes=self.conformance_classes(),
            extension_schemas=[],
        )

        # Add Queryables link
        if self.extension_is_enabled("FilterExtension") or self.extension_is_enabled(
            "SearchFilterExtension"
        ):
            landing_page["links"].append(
                {
                    "rel": Relations.queryables.value,
                    "type": MimeTypes.jsonschema.value,
                    "title": "Queryables available for this Catalog",
                    "href": urljoin(base_url, "queryables"),
                }
            )

        # Add Aggregation links
        if self.extension_is_enabled("AggregationExtension"):
            landing_page["links"].extend(
                [
                    {
                        "rel": "aggregate",
                        "type": "application/json",
                        "title": "Aggregate",
                        "href": urljoin(base_url, "aggregate"),
                    },
                    {
                        "rel": "aggregations",
                        "type": "application/json",
                        "title": "Aggregations",
                        "href": urljoin(base_url, "aggregations"),
                    },
                ]
            )

        # Add OpenAPI URL
        landing_page["links"].append(
            {
                "rel": Relations.service_desc.value,
                "type": MimeTypes.openapi.value,
                "title": "OpenAPI service description",
                "href": str(request.url_for("openapi")),
            }
        )

        # Add human readable service-doc
        landing_page["links"].append(
            {
                "rel": Relations.service_doc.value,
                "type": MimeTypes.html.value,
                "title": "OpenAPI service documentation",
                "href": str(request.url_for("swagger_ui_html")),
            }
        )

        return stac.LandingPage(**landing_page)

    def conformance(self, **kwargs) -> stac.Conformance:
        """Conformance classes.

        Called with `GET /conformance`.

        Returns:
            Conformance classes which the server conforms to.
        """
        return stac.Conformance(conformsTo=self.conformance_classes())

    @abc.abstractmethod
    def post_search(
        self, search_request: BaseSearchPostRequest, **kwargs
    ) -> stac.ItemCollection:
        """Cross catalog search (POST).

        Called with `POST /search`.

        Args:
            search_request: search request parameters.

        Returns:
            ItemCollection containing items which match the search criteria.
        """
        ...

    @abc.abstractmethod
    def get_search(
        self,
        collections: Optional[List[str]] = None,
        ids: Optional[List[str]] = None,
        bbox: Optional[BBox] = None,
        intersects: Optional[Geometry] = None,
        datetime: Optional[str] = None,
        limit: Optional[int] = 10,
        **kwargs,
    ) -> stac.ItemCollection:
        """Cross catalog search (GET).

        Called with `GET /search`.

        Returns:
            ItemCollection containing items which match the search criteria.
        """
        ...

    @abc.abstractmethod
    def get_item(self, item_id: str, collection_id: str, **kwargs) -> stac.Item:
        """Get item by id.

        Called with `GET /collections/{collection_id}/items/{item_id}`.

        Args:
            item_id: Id of the item.
            collection_id: Id of the collection.

        Returns:
            Item.
        """
        ...

    @abc.abstractmethod
    def all_collections(self, **kwargs) -> stac.Collections:
        """Get all available collections.

        Called with `GET /collections`.

        Returns:
            A list of collections.
        """
        ...

    @abc.abstractmethod
    def get_collection(self, collection_id: str, **kwargs) -> stac.Collection:
        """Get collection by id.

        Called with `GET /collections/{collection_id}`.

        Args:
            collection_id: Id of the collection.

        Returns:
            Collection.
        """
        ...

    @abc.abstractmethod
    def item_collection(
        self,
        collection_id: str,
        bbox: Optional[BBox] = None,
        datetime: Optional[str] = None,
        limit: int = 10,
        token: Optional[str] = None,
        **kwargs,
    ) -> stac.ItemCollection:
        """Get all items from a specific collection.

        Called with `GET /collections/{collection_id}/items`

        Args:
            collection_id: id of the collection.
            limit: number of items to return.
            token: pagination token.

        Returns:
            An ItemCollection.
        """
        ...

all_collections abstractmethod

all_collections(**kwargs) -> Collections

Get all available collections.

Called with GET /collections.

Returns:

Source code in stac_fastapi/types/core.py
273
274
275
276
277
278
279
280
281
282
@abc.abstractmethod
def all_collections(self, **kwargs) -> stac.Collections:
    """Get all available collections.

    Called with `GET /collections`.

    Returns:
        A list of collections.
    """
    ...

conformance

conformance(**kwargs) -> Conformance

Conformance classes.

Called with GET /conformance.

Returns:

  • Conformance

    Conformance classes which the server conforms to.

Source code in stac_fastapi/types/core.py
212
213
214
215
216
217
218
219
220
def conformance(self, **kwargs) -> stac.Conformance:
    """Conformance classes.

    Called with `GET /conformance`.

    Returns:
        Conformance classes which the server conforms to.
    """
    return stac.Conformance(conformsTo=self.conformance_classes())

conformance_classes

conformance_classes() -> List[str]

Generate conformance classes by adding extension conformance to base conformance classes.

Source code in stac_fastapi/types/core.py
116
117
118
119
120
121
122
123
124
125
def conformance_classes(self) -> List[str]:
    """Generate conformance classes by adding extension conformance to base
    conformance classes."""
    base_conformance_classes = self.base_conformance_classes.copy()

    for extension in self.extensions:
        extension_classes = getattr(extension, "conformance_classes", [])
        base_conformance_classes.extend(extension_classes)

    return sorted(list(set(base_conformance_classes)))

extension_is_enabled

extension_is_enabled(extension: str) -> bool

Check if an api extension is enabled.

Source code in stac_fastapi/types/core.py
127
128
129
def extension_is_enabled(self, extension: str) -> bool:
    """Check if an api extension is enabled."""
    return any([type(ext).__name__ == extension for ext in self.extensions])

get_collection abstractmethod

get_collection(collection_id: str, **kwargs) -> Collection

Get collection by id.

Called with GET /collections/{collection_id}.

Parameters:

  • collection_id (str) –

    Id of the collection.

Returns:

Source code in stac_fastapi/types/core.py
284
285
286
287
288
289
290
291
292
293
294
295
296
@abc.abstractmethod
def get_collection(self, collection_id: str, **kwargs) -> stac.Collection:
    """Get collection by id.

    Called with `GET /collections/{collection_id}`.

    Args:
        collection_id: Id of the collection.

    Returns:
        Collection.
    """
    ...

get_item abstractmethod

get_item(item_id: str, collection_id: str, **kwargs) -> Item

Get item by id.

Called with GET /collections/{collection_id}/items/{item_id}.

Parameters:

  • item_id (str) –

    Id of the item.

  • collection_id (str) –

    Id of the collection.

Returns:

Source code in stac_fastapi/types/core.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
@abc.abstractmethod
def get_item(self, item_id: str, collection_id: str, **kwargs) -> stac.Item:
    """Get item by id.

    Called with `GET /collections/{collection_id}/items/{item_id}`.

    Args:
        item_id: Id of the item.
        collection_id: Id of the collection.

    Returns:
        Item.
    """
    ...
get_search(
    collections: Optional[List[str]] = None,
    ids: Optional[List[str]] = None,
    bbox: Optional[BBox] = None,
    intersects: Optional[Geometry] = None,
    datetime: Optional[str] = None,
    limit: Optional[int] = 10,
    **kwargs
) -> ItemCollection

Cross catalog search (GET).

Called with GET /search.

Returns:

  • ItemCollection

    ItemCollection containing items which match the search criteria.

Source code in stac_fastapi/types/core.py
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
@abc.abstractmethod
def get_search(
    self,
    collections: Optional[List[str]] = None,
    ids: Optional[List[str]] = None,
    bbox: Optional[BBox] = None,
    intersects: Optional[Geometry] = None,
    datetime: Optional[str] = None,
    limit: Optional[int] = 10,
    **kwargs,
) -> stac.ItemCollection:
    """Cross catalog search (GET).

    Called with `GET /search`.

    Returns:
        ItemCollection containing items which match the search criteria.
    """
    ...

item_collection abstractmethod

item_collection(
    collection_id: str,
    bbox: Optional[BBox] = None,
    datetime: Optional[str] = None,
    limit: int = 10,
    token: Optional[str] = None,
    **kwargs
) -> ItemCollection

Get all items from a specific collection.

Called with GET /collections/{collection_id}/items

Parameters:

  • collection_id (str) –

    id of the collection.

  • limit (int, default: 10 ) –

    number of items to return.

  • token (Optional[str], default: None ) –

    pagination token.

Returns:

Source code in stac_fastapi/types/core.py
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
@abc.abstractmethod
def item_collection(
    self,
    collection_id: str,
    bbox: Optional[BBox] = None,
    datetime: Optional[str] = None,
    limit: int = 10,
    token: Optional[str] = None,
    **kwargs,
) -> stac.ItemCollection:
    """Get all items from a specific collection.

    Called with `GET /collections/{collection_id}/items`

    Args:
        collection_id: id of the collection.
        limit: number of items to return.
        token: pagination token.

    Returns:
        An ItemCollection.
    """
    ...

landing_page

landing_page(**kwargs) -> LandingPage

Landing page.

Called with GET /.

Returns:

  • LandingPage

    API landing page, serving as an entry point to the API.

Source code in stac_fastapi/types/core.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def landing_page(self, **kwargs) -> stac.LandingPage:
    """Landing page.

    Called with `GET /`.

    Returns:
        API landing page, serving as an entry point to the API.
    """
    request: Request = kwargs["request"]
    base_url = get_base_url(request)

    landing_page = self._landing_page(
        base_url=base_url,
        conformance_classes=self.conformance_classes(),
        extension_schemas=[],
    )

    # Add Queryables link
    if self.extension_is_enabled("FilterExtension") or self.extension_is_enabled(
        "SearchFilterExtension"
    ):
        landing_page["links"].append(
            {
                "rel": Relations.queryables.value,
                "type": MimeTypes.jsonschema.value,
                "title": "Queryables available for this Catalog",
                "href": urljoin(base_url, "queryables"),
            }
        )

    # Add Aggregation links
    if self.extension_is_enabled("AggregationExtension"):
        landing_page["links"].extend(
            [
                {
                    "rel": "aggregate",
                    "type": "application/json",
                    "title": "Aggregate",
                    "href": urljoin(base_url, "aggregate"),
                },
                {
                    "rel": "aggregations",
                    "type": "application/json",
                    "title": "Aggregations",
                    "href": urljoin(base_url, "aggregations"),
                },
            ]
        )

    # Add OpenAPI URL
    landing_page["links"].append(
        {
            "rel": Relations.service_desc.value,
            "type": MimeTypes.openapi.value,
            "title": "OpenAPI service description",
            "href": str(request.url_for("openapi")),
        }
    )

    # Add human readable service-doc
    landing_page["links"].append(
        {
            "rel": Relations.service_doc.value,
            "type": MimeTypes.html.value,
            "title": "OpenAPI service documentation",
            "href": str(request.url_for("swagger_ui_html")),
        }
    )

    return stac.LandingPage(**landing_page)

list_conformance_classes

list_conformance_classes()

Return a list of conformance classes, including implemented extensions.

Source code in stac_fastapi/types/core.py
131
132
133
134
135
136
137
138
139
def list_conformance_classes(self):
    """Return a list of conformance classes, including implemented extensions."""
    base_conformance = BASE_CONFORMANCE_CLASSES

    for extension in self.extensions:
        extension_classes = getattr(extension, "conformance_classes", [])
        base_conformance.extend(extension_classes)

    return base_conformance
post_search(search_request: BaseSearchPostRequest, **kwargs) -> ItemCollection

Cross catalog search (POST).

Called with POST /search.

Parameters:

Returns:

  • ItemCollection

    ItemCollection containing items which match the search criteria.

Source code in stac_fastapi/types/core.py
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
@abc.abstractmethod
def post_search(
    self, search_request: BaseSearchPostRequest, **kwargs
) -> stac.ItemCollection:
    """Cross catalog search (POST).

    Called with `POST /search`.

    Args:
        search_request: search request parameters.

    Returns:
        ItemCollection containing items which match the search criteria.
    """
    ...

LandingPageMixin

Bases: ABC

Create a STAC landing page (GET /).

Source code in stac_fastapi/types/core.py
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
@attr.s
class LandingPageMixin(abc.ABC):
    """Create a STAC landing page (GET /)."""

    stac_version: str = attr.ib(default=STAC_VERSION)
    landing_page_id: str = attr.ib(default=api_settings.stac_fastapi_landing_id)
    title: str = attr.ib(default=api_settings.stac_fastapi_title)
    description: str = attr.ib(default=api_settings.stac_fastapi_description)

    def _landing_page(
        self,
        base_url: str,
        conformance_classes: List[str],
        extension_schemas: List[str],
    ) -> stac.LandingPage:
        landing_page = stac.LandingPage(
            type="Catalog",
            id=self.landing_page_id,
            title=self.title,
            description=self.description,
            stac_version=self.stac_version,
            conformsTo=conformance_classes,
            links=[
                {
                    "rel": Relations.self.value,
                    "type": MimeTypes.json.value,
                    "title": "This document",
                    "href": base_url,
                },
                {
                    "rel": Relations.root.value,
                    "type": MimeTypes.json.value,
                    "title": "Root",
                    "href": base_url,
                },
                {
                    "rel": Relations.data.value,
                    "type": MimeTypes.json.value,
                    "title": "Collections available for this Catalog",
                    "href": urljoin(base_url, "collections"),
                },
                {
                    "rel": Relations.conformance.value,
                    "type": MimeTypes.json.value,
                    "title": "STAC/OGC conformance classes implemented by this server",
                    "href": urljoin(base_url, "conformance"),
                },
                {
                    "rel": Relations.search.value,
                    "type": MimeTypes.geojson.value,
                    "title": "STAC search [GET]",
                    "href": urljoin(base_url, "search"),
                    "method": "GET",
                },
                {
                    "rel": Relations.search.value,
                    "type": MimeTypes.geojson.value,
                    "title": "STAC search [POST]",
                    "href": urljoin(base_url, "search"),
                    "method": "POST",
                },
            ],
            stac_extensions=extension_schemas,
        )

        return landing_page