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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
@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
835
836
837
838
839
840
841
842
843
844
@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
774
775
776
777
778
779
780
781
782
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
687
688
689
690
691
692
693
694
695
696
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
698
699
700
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
846
847
848
849
850
851
852
853
854
855
856
857
858
@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
820
821
822
823
824
825
826
827
828
829
830
831
832
833
@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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
@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
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
@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
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
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
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
@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.
    """
    ...

AsyncBaseTransactionsClient

Bases: ABC

Defines a pattern for implementing the STAC transaction extension.

Source code in stac_fastapi/types/core.py
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
321
322
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
@attr.s  # type:ignore
class AsyncBaseTransactionsClient(abc.ABC):
    """Defines a pattern for implementing the STAC transaction extension."""

    @abc.abstractmethod
    async def create_item(
        self,
        collection_id: str,
        item: Union[Item, ItemCollection],
        **kwargs,
    ) -> Optional[Union[stac.Item, Response, None]]:
        """Create a new item.

        Called with `POST /collections/{collection_id}/items`.

        Args:
            item: the item or item collection
            collection_id: the id of the collection from the resource path

        Returns:
            The item that was created or None if item collection.
        """
        ...

    @abc.abstractmethod
    async def update_item(
        self, collection_id: str, item_id: str, item: Item, **kwargs
    ) -> Optional[Union[stac.Item, Response]]:
        """Perform a complete update on an existing item.

        Called with `PUT /collections/{collection_id}/items`. It is expected
        that this item already exists.  The update should do a diff against the
        saved item and perform any necessary updates.  Partial updates are not
        supported by the transactions extension.

        Args:
            item: the item (must be complete)

        Returns:
            The updated item.
        """
        ...

    @abc.abstractmethod
    async def patch_item(
        self,
        collection_id: str,
        item_id: str,
        patch: Union[stac.PartialItem, List[stac.PatchOperation]],
        **kwargs,
    ) -> Optional[Union[stac.Item, Response]]:
        """Update an item from a collection.

        Called with `PATCH /collections/{collection_id}/items/{item_id}`

        example:
            # convert merge patch item to list of operations
            if isinstance(patch, PartialItem):
                patch = patch.operations()

            item = backend.patch_item(collection_id, item_id, patch)

            return item

        Args:
            item_id: id of the item.
            collection_id: id of the collection.
            patch: either the partial item or list of patch operations.

        Returns:
            The patched item.
        """
        ...

    @abc.abstractmethod
    async def delete_item(
        self, item_id: str, collection_id: str, **kwargs
    ) -> Optional[Union[stac.Item, Response]]:
        """Delete an item from a collection.

        Called with `DELETE /collections/{collection_id}/items/{item_id}`

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

        Returns:
            The deleted item.
        """
        ...

    @abc.abstractmethod
    async def create_collection(
        self, collection: Collection, **kwargs
    ) -> Optional[Union[stac.Collection, Response]]:
        """Create a new collection.

        Called with `POST /collections`.

        Args:
            collection: the collection

        Returns:
            The collection that was created.
        """
        ...

    @abc.abstractmethod
    async def update_collection(
        self, collection_id: str, collection: Collection, **kwargs
    ) -> Optional[Union[stac.Collection, Response]]:
        """Perform a complete update on an existing collection.

        Called with `PUT /collections/{collection_id}`. It is expected that this item
        already exists.  The update should do a diff against the saved collection and
        perform any necessary updates.  Partial updates are not supported by the
        transactions extension.

        Args:
            collection_id: id of the existing collection to be updated
            collection: the updated collection (must be complete)

        Returns:
            The updated collection.
        """
        ...

    @abc.abstractmethod
    async def patch_collection(
        self,
        collection_id: str,
        patch: Union[stac.PartialCollection, List[stac.PatchOperation]],
        **kwargs,
    ) -> Optional[Union[stac.Collection, Response]]:
        """Update a collection.

        Called with `PATCH /collections/{collection_id}`

        example:
            # convert merge patch item to list of operations
            if isinstance(patch, PartialCollection):
                patch = patch.operations()

            collection = backend.patch_collection(collection_id, patch)

            return collection

        Args:
            collection_id: id of the collection.
            patch: either the partial collection or list of patch operations.

        Returns:
            The patched collection.
        """
        ...

    @abc.abstractmethod
    async def delete_collection(
        self, collection_id: str, **kwargs
    ) -> Optional[Union[stac.Collection, Response]]:
        """Delete a collection.

        Called with `DELETE /collections/{collection_id}`

        Args:
            collection_id: id of the collection.

        Returns:
            The deleted collection.
        """
        ...

create_collection abstractmethod async

create_collection(collection: Collection, **kwargs) -> Optional[Union[Collection, Response]]

Create a new collection.

Called with POST /collections.

Parameters:

  • collection (Collection) –

    the collection

Returns:

Source code in stac_fastapi/types/core.py
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
@abc.abstractmethod
async def create_collection(
    self, collection: Collection, **kwargs
) -> Optional[Union[stac.Collection, Response]]:
    """Create a new collection.

    Called with `POST /collections`.

    Args:
        collection: the collection

    Returns:
        The collection that was created.
    """
    ...

create_item abstractmethod async

create_item(
    collection_id: str, item: Union[Item, ItemCollection], **kwargs
) -> Optional[Union[Item, Response, None]]

Create a new item.

Called with POST /collections/{collection_id}/items.

Parameters:

  • item (Union[Item, ItemCollection]) –

    the item or item collection

  • collection_id (str) –

    the id of the collection from the resource path

Returns:

Source code in stac_fastapi/types/core.py
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
@abc.abstractmethod
async def create_item(
    self,
    collection_id: str,
    item: Union[Item, ItemCollection],
    **kwargs,
) -> Optional[Union[stac.Item, Response, None]]:
    """Create a new item.

    Called with `POST /collections/{collection_id}/items`.

    Args:
        item: the item or item collection
        collection_id: the id of the collection from the resource path

    Returns:
        The item that was created or None if item collection.
    """
    ...

delete_collection abstractmethod async

delete_collection(collection_id: str, **kwargs) -> Optional[Union[Collection, Response]]

Delete a collection.

Called with DELETE /collections/{collection_id}

Parameters:

  • collection_id (str) –

    id of the collection.

Returns:

Source code in stac_fastapi/types/core.py
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
@abc.abstractmethod
async def delete_collection(
    self, collection_id: str, **kwargs
) -> Optional[Union[stac.Collection, Response]]:
    """Delete a collection.

    Called with `DELETE /collections/{collection_id}`

    Args:
        collection_id: id of the collection.

    Returns:
        The deleted collection.
    """
    ...

delete_item abstractmethod async

delete_item(item_id: str, collection_id: str, **kwargs) -> Optional[Union[Item, Response]]

Delete an item from a collection.

Called with DELETE /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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
@abc.abstractmethod
async def delete_item(
    self, item_id: str, collection_id: str, **kwargs
) -> Optional[Union[stac.Item, Response]]:
    """Delete an item from a collection.

    Called with `DELETE /collections/{collection_id}/items/{item_id}`

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

    Returns:
        The deleted item.
    """
    ...

patch_collection abstractmethod async

patch_collection(
    collection_id: str, patch: Union[PartialCollection, List[PatchOperation]], **kwargs
) -> Optional[Union[Collection, Response]]

Update a collection.

Called with PATCH /collections/{collection_id}

example
convert merge patch item to list of operations

if isinstance(patch, PartialCollection): patch = patch.operations()

collection = backend.patch_collection(collection_id, patch)

return collection

Parameters:

  • collection_id (str) –

    id of the collection.

  • patch (Union[PartialCollection, List[PatchOperation]]) –

    either the partial collection or list of patch operations.

Returns:

Source code in stac_fastapi/types/core.py
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
@abc.abstractmethod
async def patch_collection(
    self,
    collection_id: str,
    patch: Union[stac.PartialCollection, List[stac.PatchOperation]],
    **kwargs,
) -> Optional[Union[stac.Collection, Response]]:
    """Update a collection.

    Called with `PATCH /collections/{collection_id}`

    example:
        # convert merge patch item to list of operations
        if isinstance(patch, PartialCollection):
            patch = patch.operations()

        collection = backend.patch_collection(collection_id, patch)

        return collection

    Args:
        collection_id: id of the collection.
        patch: either the partial collection or list of patch operations.

    Returns:
        The patched collection.
    """
    ...

patch_item abstractmethod async

patch_item(
    collection_id: str, item_id: str, patch: Union[PartialItem, List[PatchOperation]], **kwargs
) -> Optional[Union[Item, Response]]

Update an item from a collection.

Called with PATCH /collections/{collection_id}/items/{item_id}

example
convert merge patch item to list of operations

if isinstance(patch, PartialItem): patch = patch.operations()

item = backend.patch_item(collection_id, item_id, patch)

return item

Parameters:

  • item_id (str) –

    id of the item.

  • collection_id (str) –

    id of the collection.

  • patch (Union[PartialItem, List[PatchOperation]]) –

    either the partial item or list of patch operations.

Returns:

Source code in stac_fastapi/types/core.py
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
@abc.abstractmethod
async def patch_item(
    self,
    collection_id: str,
    item_id: str,
    patch: Union[stac.PartialItem, List[stac.PatchOperation]],
    **kwargs,
) -> Optional[Union[stac.Item, Response]]:
    """Update an item from a collection.

    Called with `PATCH /collections/{collection_id}/items/{item_id}`

    example:
        # convert merge patch item to list of operations
        if isinstance(patch, PartialItem):
            patch = patch.operations()

        item = backend.patch_item(collection_id, item_id, patch)

        return item

    Args:
        item_id: id of the item.
        collection_id: id of the collection.
        patch: either the partial item or list of patch operations.

    Returns:
        The patched item.
    """
    ...

update_collection abstractmethod async

update_collection(
    collection_id: str, collection: Collection, **kwargs
) -> Optional[Union[Collection, Response]]

Perform a complete update on an existing collection.

Called with PUT /collections/{collection_id}. It is expected that this item already exists. The update should do a diff against the saved collection and perform any necessary updates. Partial updates are not supported by the transactions extension.

Parameters:

  • collection_id (str) –

    id of the existing collection to be updated

  • collection (Collection) –

    the updated collection (must be complete)

Returns:

Source code in stac_fastapi/types/core.py
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
@abc.abstractmethod
async def update_collection(
    self, collection_id: str, collection: Collection, **kwargs
) -> Optional[Union[stac.Collection, Response]]:
    """Perform a complete update on an existing collection.

    Called with `PUT /collections/{collection_id}`. It is expected that this item
    already exists.  The update should do a diff against the saved collection and
    perform any necessary updates.  Partial updates are not supported by the
    transactions extension.

    Args:
        collection_id: id of the existing collection to be updated
        collection: the updated collection (must be complete)

    Returns:
        The updated collection.
    """
    ...

update_item abstractmethod async

update_item(
    collection_id: str, item_id: str, item: Item, **kwargs
) -> Optional[Union[Item, Response]]

Perform a complete update on an existing item.

Called with PUT /collections/{collection_id}/items. It is expected that this item already exists. The update should do a diff against the saved item and perform any necessary updates. Partial updates are not supported by the transactions extension.

Parameters:

  • item (Item) –

    the item (must be complete)

Returns:

Source code in stac_fastapi/types/core.py
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
@abc.abstractmethod
async def update_item(
    self, collection_id: str, item_id: str, item: Item, **kwargs
) -> Optional[Union[stac.Item, Response]]:
    """Perform a complete update on an existing item.

    Called with `PUT /collections/{collection_id}/items`. It is expected
    that this item already exists.  The update should do a diff against the
    saved item and perform any necessary updates.  Partial updates are not
    supported by the transactions extension.

    Args:
        item: the item (must be complete)

    Returns:
        The updated item.
    """
    ...

BaseCoreClient

Bases: LandingPageMixin, ABC

Defines a pattern for implementing STAC api core endpoints.

Attributes:

Source code in stac_fastapi/types/core.py
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
@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
624
625
626
627
628
629
630
631
632
633
@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
563
564
565
566
567
568
569
570
571
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
467
468
469
470
471
472
473
474
475
476
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
478
479
480
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
635
636
637
638
639
640
641
642
643
644
645
646
647
@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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
@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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
@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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
@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
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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
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
482
483
484
485
486
487
488
489
490
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
@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.
    """
    ...

BaseTransactionsClient

Bases: ABC

Defines a pattern for implementing the STAC API Transaction Extension.

Source code in stac_fastapi/types/core.py
 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
101
102
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
@attr.s  # type:ignore
class BaseTransactionsClient(abc.ABC):
    """Defines a pattern for implementing the STAC API Transaction Extension."""

    @abc.abstractmethod
    def create_item(
        self,
        collection_id: str,
        item: Union[Item, ItemCollection],
        **kwargs,
    ) -> Optional[Union[stac.Item, Response, None]]:
        """Create a new item.

        Called with `POST /collections/{collection_id}/items`.

        Args:
            item: the item or item collection
            collection_id: the id of the collection from the resource path

        Returns:
            The item that was created or None if item collection.
        """
        ...

    @abc.abstractmethod
    def update_item(
        self, collection_id: str, item_id: str, item: Item, **kwargs
    ) -> Optional[Union[stac.Item, Response]]:
        """Perform a complete update on an existing item.

        Called with `PUT /collections/{collection_id}/items`. It is expected
        that this item already exists.  The update should do a diff against the
        saved item and perform any necessary updates.  Partial updates are not
        supported by the transactions extension.

        Args:
            item: the item (must be complete)
            collection_id: the id of the collection from the resource path

        Returns:
            The updated item.
        """
        ...

    @abc.abstractmethod
    def patch_item(
        self,
        collection_id: str,
        item_id: str,
        patch: Union[stac.PartialItem, List[stac.PatchOperation]],
        **kwargs,
    ) -> Optional[Union[stac.Item, Response]]:
        """Update an item from a collection.

        Called with `PATCH /collections/{collection_id}/items/{item_id}`

        example:
            # convert merge patch item to list of operations
            if isinstance(patch, PartialItem):
                patch = patch.operations()

            item = backend.patch_item(collection_id, item_id, patch)

            return item

        Args:
            item_id: id of the item.
            collection_id: id of the collection.
            patch: either the partial item or list of patch operations.

        Returns:
            The patched item.
        """
        ...

    @abc.abstractmethod
    def delete_item(
        self, item_id: str, collection_id: str, **kwargs
    ) -> Optional[Union[stac.Item, Response]]:
        """Delete an item from a collection.

        Called with `DELETE /collections/{collection_id}/items/{item_id}`

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

        Returns:
            The deleted item.
        """
        ...

    @abc.abstractmethod
    def create_collection(
        self, collection: Collection, **kwargs
    ) -> Optional[Union[stac.Collection, Response]]:
        """Create a new collection.

        Called with `POST /collections`.

        Args:
            collection: the collection

        Returns:
            The collection that was created.
        """
        ...

    @abc.abstractmethod
    def update_collection(
        self, collection_id: str, collection: Collection, **kwargs
    ) -> Optional[Union[stac.Collection, Response]]:
        """Perform a complete update on an existing collection.

        Called with `PUT /collections/{collection_id}`. It is expected that this
        collection already exists.  The update should do a diff against the saved
        collection and perform any necessary updates.  Partial updates are not
        supported by the transactions extension.

        Args:
            collection_id: id of the existing collection to be updated
            collection: the updated collection (must be complete)

        Returns:
            The updated collection.
        """
        ...

    @abc.abstractmethod
    def patch_collection(
        self,
        collection_id: str,
        patch: Union[stac.PartialCollection, List[stac.PatchOperation]],
        **kwargs,
    ) -> Optional[Union[stac.Collection, Response]]:
        """Update a collection.

        Called with `PATCH /collections/{collection_id}`

        example:
            # convert merge patch item to list of operations
            if isinstance(patch, PartialCollection):
                patch = patch.operations()

            collection = backend.patch_collection(collection_id, patch)

            return collection

        Args:
            collection_id: id of the collection.
            patch: either the partial collection or list of patch operations.

        Returns:
            The patched collection.
        """
        ...

    @abc.abstractmethod
    def delete_collection(
        self, collection_id: str, **kwargs
    ) -> Optional[Union[stac.Collection, Response]]:
        """Delete a collection.

        Called with `DELETE /collections/{collection_id}`

        Args:
            collection_id: id of the collection.

        Returns:
            The deleted collection.
        """
        ...

create_collection abstractmethod

create_collection(collection: Collection, **kwargs) -> Optional[Union[Collection, Response]]

Create a new collection.

Called with POST /collections.

Parameters:

  • collection (Collection) –

    the collection

Returns:

Source code in stac_fastapi/types/core.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@abc.abstractmethod
def create_collection(
    self, collection: Collection, **kwargs
) -> Optional[Union[stac.Collection, Response]]:
    """Create a new collection.

    Called with `POST /collections`.

    Args:
        collection: the collection

    Returns:
        The collection that was created.
    """
    ...

create_item abstractmethod

create_item(
    collection_id: str, item: Union[Item, ItemCollection], **kwargs
) -> Optional[Union[Item, Response, None]]

Create a new item.

Called with POST /collections/{collection_id}/items.

Parameters:

  • item (Union[Item, ItemCollection]) –

    the item or item collection

  • collection_id (str) –

    the id of the collection from the resource path

Returns:

Source code in stac_fastapi/types/core.py
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@abc.abstractmethod
def create_item(
    self,
    collection_id: str,
    item: Union[Item, ItemCollection],
    **kwargs,
) -> Optional[Union[stac.Item, Response, None]]:
    """Create a new item.

    Called with `POST /collections/{collection_id}/items`.

    Args:
        item: the item or item collection
        collection_id: the id of the collection from the resource path

    Returns:
        The item that was created or None if item collection.
    """
    ...

delete_collection abstractmethod

delete_collection(collection_id: str, **kwargs) -> Optional[Union[Collection, Response]]

Delete a collection.

Called with DELETE /collections/{collection_id}

Parameters:

  • collection_id (str) –

    id of the collection.

Returns:

Source code in stac_fastapi/types/core.py
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
@abc.abstractmethod
def delete_collection(
    self, collection_id: str, **kwargs
) -> Optional[Union[stac.Collection, Response]]:
    """Delete a collection.

    Called with `DELETE /collections/{collection_id}`

    Args:
        collection_id: id of the collection.

    Returns:
        The deleted collection.
    """
    ...

delete_item abstractmethod

delete_item(item_id: str, collection_id: str, **kwargs) -> Optional[Union[Item, Response]]

Delete an item from a collection.

Called with DELETE /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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
@abc.abstractmethod
def delete_item(
    self, item_id: str, collection_id: str, **kwargs
) -> Optional[Union[stac.Item, Response]]:
    """Delete an item from a collection.

    Called with `DELETE /collections/{collection_id}/items/{item_id}`

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

    Returns:
        The deleted item.
    """
    ...

patch_collection abstractmethod

patch_collection(
    collection_id: str, patch: Union[PartialCollection, List[PatchOperation]], **kwargs
) -> Optional[Union[Collection, Response]]

Update a collection.

Called with PATCH /collections/{collection_id}

example
convert merge patch item to list of operations

if isinstance(patch, PartialCollection): patch = patch.operations()

collection = backend.patch_collection(collection_id, patch)

return collection

Parameters:

  • collection_id (str) –

    id of the collection.

  • patch (Union[PartialCollection, List[PatchOperation]]) –

    either the partial collection or list of patch operations.

Returns:

Source code in stac_fastapi/types/core.py
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
@abc.abstractmethod
def patch_collection(
    self,
    collection_id: str,
    patch: Union[stac.PartialCollection, List[stac.PatchOperation]],
    **kwargs,
) -> Optional[Union[stac.Collection, Response]]:
    """Update a collection.

    Called with `PATCH /collections/{collection_id}`

    example:
        # convert merge patch item to list of operations
        if isinstance(patch, PartialCollection):
            patch = patch.operations()

        collection = backend.patch_collection(collection_id, patch)

        return collection

    Args:
        collection_id: id of the collection.
        patch: either the partial collection or list of patch operations.

    Returns:
        The patched collection.
    """
    ...

patch_item abstractmethod

patch_item(
    collection_id: str, item_id: str, patch: Union[PartialItem, List[PatchOperation]], **kwargs
) -> Optional[Union[Item, Response]]

Update an item from a collection.

Called with PATCH /collections/{collection_id}/items/{item_id}

example
convert merge patch item to list of operations

if isinstance(patch, PartialItem): patch = patch.operations()

item = backend.patch_item(collection_id, item_id, patch)

return item

Parameters:

  • item_id (str) –

    id of the item.

  • collection_id (str) –

    id of the collection.

  • patch (Union[PartialItem, List[PatchOperation]]) –

    either the partial item or list of patch operations.

Returns:

Source code in stac_fastapi/types/core.py
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
@abc.abstractmethod
def patch_item(
    self,
    collection_id: str,
    item_id: str,
    patch: Union[stac.PartialItem, List[stac.PatchOperation]],
    **kwargs,
) -> Optional[Union[stac.Item, Response]]:
    """Update an item from a collection.

    Called with `PATCH /collections/{collection_id}/items/{item_id}`

    example:
        # convert merge patch item to list of operations
        if isinstance(patch, PartialItem):
            patch = patch.operations()

        item = backend.patch_item(collection_id, item_id, patch)

        return item

    Args:
        item_id: id of the item.
        collection_id: id of the collection.
        patch: either the partial item or list of patch operations.

    Returns:
        The patched item.
    """
    ...

update_collection abstractmethod

update_collection(
    collection_id: str, collection: Collection, **kwargs
) -> Optional[Union[Collection, Response]]

Perform a complete update on an existing collection.

Called with PUT /collections/{collection_id}. It is expected that this collection already exists. The update should do a diff against the saved collection and perform any necessary updates. Partial updates are not supported by the transactions extension.

Parameters:

  • collection_id (str) –

    id of the existing collection to be updated

  • collection (Collection) –

    the updated collection (must be complete)

Returns:

Source code in stac_fastapi/types/core.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
@abc.abstractmethod
def update_collection(
    self, collection_id: str, collection: Collection, **kwargs
) -> Optional[Union[stac.Collection, Response]]:
    """Perform a complete update on an existing collection.

    Called with `PUT /collections/{collection_id}`. It is expected that this
    collection already exists.  The update should do a diff against the saved
    collection and perform any necessary updates.  Partial updates are not
    supported by the transactions extension.

    Args:
        collection_id: id of the existing collection to be updated
        collection: the updated collection (must be complete)

    Returns:
        The updated collection.
    """
    ...

update_item abstractmethod

update_item(
    collection_id: str, item_id: str, item: Item, **kwargs
) -> Optional[Union[Item, Response]]

Perform a complete update on an existing item.

Called with PUT /collections/{collection_id}/items. It is expected that this item already exists. The update should do a diff against the saved item and perform any necessary updates. Partial updates are not supported by the transactions extension.

Parameters:

  • item (Item) –

    the item (must be complete)

  • collection_id (str) –

    the id of the collection from the resource path

Returns:

Source code in stac_fastapi/types/core.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
@abc.abstractmethod
def update_item(
    self, collection_id: str, item_id: str, item: Item, **kwargs
) -> Optional[Union[stac.Item, Response]]:
    """Perform a complete update on an existing item.

    Called with `PUT /collections/{collection_id}/items`. It is expected
    that this item already exists.  The update should do a diff against the
    saved item and perform any necessary updates.  Partial updates are not
    supported by the transactions extension.

    Args:
        item: the item (must be complete)
        collection_id: the id of the collection from the resource path

    Returns:
        The updated item.
    """
    ...

LandingPageMixin

Bases: ABC

Create a STAC landing page (GET /).

Source code in stac_fastapi/types/core.py
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
@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