Skip to content

sort

stac_fastapi.extensions.sort.sort

Sort extension.

CollectionSearchSortExtension

Bases: SortExtension

Collection Search Sort Extension.

Provides sort capabilities for the /collections endpoint.

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
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
@attr.s
class CollectionSearchSortExtension(SortExtension):
    """Collection Search Sort Extension.

    Provides sort capabilities for the `/collections` endpoint.
    """

    conformance_classes: list[str] = attr.ib(
        factory=lambda: [
            SortConformanceClasses.COLLECTION_SEARCH_SORT,
            SortConformanceClasses.COLLECTION_SEARCH_SORTABLES,
        ]
    )

    def register(self, app: FastAPI) -> None:
        """Register the extension with a FastAPI application.

        Args:
            app: target FastAPI application.

        Returns:
            None
        """
        if self.client is None:
            return

        self.router.prefix = app.state.router_prefix

        self.router.add_api_route(
            name="Collections Catalog Sortables",
            path="/collections-sortables",
            methods=["GET"],
            response_model=SortablesSchema,
            response_model_exclude_none=True,
            endpoint=create_async_endpoint(
                self.client.get_collections_sortables, EmptyRequest
            ),
        )

        app.include_router(self.router, tags=["Sort Extension"])

register

register(app: FastAPI) -> None

Register the extension with a FastAPI application.

Parameters:

  • app (FastAPI) –

    target FastAPI application.

Returns:

  • None –

    None

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
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
def register(self, app: FastAPI) -> None:
    """Register the extension with a FastAPI application.

    Args:
        app: target FastAPI application.

    Returns:
        None
    """
    if self.client is None:
        return

    self.router.prefix = app.state.router_prefix

    self.router.add_api_route(
        name="Collections Catalog Sortables",
        path="/collections-sortables",
        methods=["GET"],
        response_model=SortablesSchema,
        response_model_exclude_none=True,
        endpoint=create_async_endpoint(
            self.client.get_collections_sortables, EmptyRequest
        ),
    )

    app.include_router(self.router, tags=["Sort Extension"])

ItemCollectionSortExtension

Bases: SortExtension

Item Collection Sort Extension.

Provides sort capabilities for the /collections/{id}/items endpoint.

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
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
@attr.s
class ItemCollectionSortExtension(SortExtension):
    """Item Collection Sort Extension.

    Provides sort capabilities for the `/collections/{id}/items` endpoint.
    """

    conformance_classes: list[str] = attr.ib(
        factory=lambda: [
            SortConformanceClasses.FEATURES_SORT,
            SortConformanceClasses.FEATURES_SORTABLES,
        ]
    )

    def register(self, app: FastAPI) -> None:
        """Register the extension with a FastAPI application.

        Args:
            app: target FastAPI application.

        Returns:
            None
        """
        if self.client is None:
            return

        self.router.prefix = app.state.router_prefix

        self.router.add_api_route(
            name="Collection Sortables",
            path="/collections/{collection_id}/sortables",
            methods=["GET"],
            response_model=SortablesSchema,
            response_model_exclude_none=True,
            endpoint=create_async_endpoint(
                self.client.get_collection_sortables, CollectionUri
            ),
        )

        app.include_router(self.router, tags=["Sort Extension"])

register

register(app: FastAPI) -> None

Register the extension with a FastAPI application.

Parameters:

  • app (FastAPI) –

    target FastAPI application.

Returns:

  • None –

    None

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
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
def register(self, app: FastAPI) -> None:
    """Register the extension with a FastAPI application.

    Args:
        app: target FastAPI application.

    Returns:
        None
    """
    if self.client is None:
        return

    self.router.prefix = app.state.router_prefix

    self.router.add_api_route(
        name="Collection Sortables",
        path="/collections/{collection_id}/sortables",
        methods=["GET"],
        response_model=SortablesSchema,
        response_model_exclude_none=True,
        endpoint=create_async_endpoint(
            self.client.get_collection_sortables, CollectionUri
        ),
    )

    app.include_router(self.router, tags=["Sort Extension"])

SearchSortExtension

Bases: SortExtension

Item Search Sort Extension.

Provides sort capabilities for the /search endpoint.

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
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
@attr.s
class SearchSortExtension(SortExtension):
    """Item Search Sort Extension.

    Provides sort capabilities for the `/search` endpoint.
    """

    conformance_classes: list[str] = attr.ib(
        factory=lambda: [
            SortConformanceClasses.ITEM_SEARCH_SORT,
            SortConformanceClasses.ITEM_SEARCH_SORTABLES,
        ]
    )

    def register(self, app: FastAPI) -> None:
        """Register the extension with a FastAPI application.

        Args:
            app: target FastAPI application.

        Returns:
            None
        """
        if self.client is None:
            return

        self.router.prefix = app.state.router_prefix

        self.router.add_api_route(
            name="Sortables",
            path="/sortables",
            methods=["GET"],
            response_model=SortablesSchema,
            response_model_exclude_none=True,
            endpoint=create_async_endpoint(self.client.get_sortables, EmptyRequest),
        )

        app.include_router(self.router, tags=["Sort Extension"])

register

register(app: FastAPI) -> None

Register the extension with a FastAPI application.

Parameters:

  • app (FastAPI) –

    target FastAPI application.

Returns:

  • None –

    None

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def register(self, app: FastAPI) -> None:
    """Register the extension with a FastAPI application.

    Args:
        app: target FastAPI application.

    Returns:
        None
    """
    if self.client is None:
        return

    self.router.prefix = app.state.router_prefix

    self.router.add_api_route(
        name="Sortables",
        path="/sortables",
        methods=["GET"],
        response_model=SortablesSchema,
        response_model_exclude_none=True,
        endpoint=create_async_endpoint(self.client.get_sortables, EmptyRequest),
    )

    app.include_router(self.router, tags=["Sort Extension"])

SortConformanceClasses

Bases: StrEnum

Conformance classes for the Sort v1.1.0 extension.

See stac-api-extensions/sort

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
class SortConformanceClasses(StrEnum):
    """Conformance classes for the Sort v1.1.0 extension.

    See https://github.com/stac-api-extensions/sort
    """

    ITEM_SEARCH_SORT = "https://api.stacspec.org/v1.1.0/item-search#sort"
    ITEM_SEARCH_SORTABLES = "https://api.stacspec.org/v1.1.0/item-search#sortables"

    FEATURES_SORT = "https://api.stacspec.org/v1.1.0/ogcapi-features#sort"
    FEATURES_SORTABLES = (
        "http://www.opengis.net/spec/ogcapi-features-5/1.0/conf/sortables"
    )

    COLLECTION_SEARCH_SORT = "https://api.stacspec.org/v1.1.0/collection-search#sort"
    COLLECTION_SEARCH_SORTABLES = (
        "https://api.stacspec.org/v1.1.0/collection-search#sortables"
    )

SortExtension

Bases: ApiExtension

Sort Extension.

The Sort extension adds the sortby parameter to search endpoints and provides sortables endpoints for discovering available sort fields. stac-api-extensions/sort

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
 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
@attr.s
class SortExtension(ApiExtension):
    """Sort Extension.

    The Sort extension adds the `sortby` parameter to search endpoints and provides
    sortables endpoints for discovering available sort fields.
    https://github.com/stac-api-extensions/sort
    """

    GET: type[APIRequest] = SortExtensionGetRequest
    POST: type[BaseModel] = SortExtensionPostRequest
    client: AsyncBaseSortablesClient | BaseSortablesClient | None = attr.ib(default=None)
    router: APIRouter = attr.ib(
        factory=lambda: APIRouter(default_response_class=JSONSchemaResponse)
    )

    conformance_classes: list[str] = attr.ib(
        factory=lambda: [
            SortConformanceClasses.ITEM_SEARCH_SORT,
            SortConformanceClasses.ITEM_SEARCH_SORTABLES,
            SortConformanceClasses.FEATURES_SORT,
            SortConformanceClasses.FEATURES_SORTABLES,
            SortConformanceClasses.COLLECTION_SEARCH_SORT,
            SortConformanceClasses.COLLECTION_SEARCH_SORTABLES,
        ]
    )

    def __attrs_post_init__(self):
        """Remove sortables conformance classes when no client is provided.

        Without a client the sortables endpoints cannot be served, so the
        associated conformance URIs are removed from the advertised list.
        """
        if self.client is None:
            self.conformance_classes = [
                c for c in self.conformance_classes if c not in SORTABLES_CONFORMANCE_URIS
            ]

    def register(self, app: FastAPI) -> None:
        """Register the extension with a FastAPI application.

        Args:
            app: target FastAPI application.

        Returns:
            None
        """
        if self.client is None:
            return

        self.router.prefix = app.state.router_prefix

        self.router.add_api_route(
            name="Sortables",
            path="/sortables",
            methods=["GET"],
            response_model=SortablesSchema,
            response_model_exclude_none=True,
            endpoint=create_async_endpoint(self.client.get_sortables, EmptyRequest),
        )

        self.router.add_api_route(
            name="Collection Sortables",
            path="/collections/{collection_id}/sortables",
            methods=["GET"],
            response_model=SortablesSchema,
            response_model_exclude_none=True,
            endpoint=create_async_endpoint(
                self.client.get_collection_sortables, CollectionUri
            ),
        )

        self.router.add_api_route(
            name="Collections Catalog Sortables",
            path="/collections-sortables",
            methods=["GET"],
            response_model=SortablesSchema,
            response_model_exclude_none=True,
            endpoint=create_async_endpoint(
                self.client.get_collections_sortables, EmptyRequest
            ),
        )

        app.include_router(self.router, tags=["Sort Extension"])

__attrs_post_init__

__attrs_post_init__()

Remove sortables conformance classes when no client is provided.

Without a client the sortables endpoints cannot be served, so the associated conformance URIs are removed from the advertised list.

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
109
110
111
112
113
114
115
116
117
118
def __attrs_post_init__(self):
    """Remove sortables conformance classes when no client is provided.

    Without a client the sortables endpoints cannot be served, so the
    associated conformance URIs are removed from the advertised list.
    """
    if self.client is None:
        self.conformance_classes = [
            c for c in self.conformance_classes if c not in SORTABLES_CONFORMANCE_URIS
        ]

register

register(app: FastAPI) -> None

Register the extension with a FastAPI application.

Parameters:

  • app (FastAPI) –

    target FastAPI application.

Returns:

  • None –

    None

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
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
def register(self, app: FastAPI) -> None:
    """Register the extension with a FastAPI application.

    Args:
        app: target FastAPI application.

    Returns:
        None
    """
    if self.client is None:
        return

    self.router.prefix = app.state.router_prefix

    self.router.add_api_route(
        name="Sortables",
        path="/sortables",
        methods=["GET"],
        response_model=SortablesSchema,
        response_model_exclude_none=True,
        endpoint=create_async_endpoint(self.client.get_sortables, EmptyRequest),
    )

    self.router.add_api_route(
        name="Collection Sortables",
        path="/collections/{collection_id}/sortables",
        methods=["GET"],
        response_model=SortablesSchema,
        response_model_exclude_none=True,
        endpoint=create_async_endpoint(
            self.client.get_collection_sortables, CollectionUri
        ),
    )

    self.router.add_api_route(
        name="Collections Catalog Sortables",
        path="/collections-sortables",
        methods=["GET"],
        response_model=SortablesSchema,
        response_model_exclude_none=True,
        endpoint=create_async_endpoint(
            self.client.get_collections_sortables, EmptyRequest
        ),
    )

    app.include_router(self.router, tags=["Sort Extension"])

SortablesSchema

Bases: BaseModel

Pydantic model for the Sortables JSON Schema response.

Source code in stac_fastapi/extensions/stac_fastapi/extensions/sort/sort.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class SortablesSchema(BaseModel):
    """Pydantic model for the Sortables JSON Schema response."""

    schema_url: str = Field(
        default="https://json-schema.org/draft/2020-12/schema", alias="$schema"
    )
    id_url: str = Field(alias="$id")
    type: str = "object"
    title: str | None = "Sortables"
    properties: dict[str, Any] = Field(default_factory=dict)
    additionalProperties: bool = True

    model_config = {
        "populate_by_name": True,
        "json_schema_extra": {
            "example": {
                "$schema": "https://json-schema.org/draft/2020-12/schema",
                "$id": "https://example.com/sortables",
                "title": "Sortables",
                "type": "object",
                "properties": {
                    "id": {"type": "string"},
                    "datetime": {"type": "string", "format": "date-time"},
                },
                "additionalProperties": True,
            }
        },
    }