Skip to content

search

stac_fastapi.types.search

stac_fastapi.types.search module.

APIRequest

Generic API Request base class.

Source code in stac_fastapi/types/search.py
131
132
133
134
135
136
137
138
@attr.s
class APIRequest:
    """Generic API Request base class."""

    def kwargs(self) -> Dict:
        """Transform api request params into format which matches the signature of the
        endpoint."""
        return self.__dict__

kwargs

kwargs() -> Dict

Transform api request params into format which matches the signature of the endpoint.

Source code in stac_fastapi/types/search.py
135
136
137
138
def kwargs(self) -> Dict:
    """Transform api request params into format which matches the signature of the
    endpoint."""
    return self.__dict__

BaseSearchGetRequest

Bases: APIRequest, DatetimeMixin

Base arguments for GET Request.

Source code in stac_fastapi/types/search.py
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
@attr.s
class BaseSearchGetRequest(APIRequest, DatetimeMixin):
    """Base arguments for GET Request."""

    collections: Optional[List[str]] = attr.ib(
        default=None, converter=_collection_converter
    )
    ids: Optional[List[str]] = attr.ib(default=None, converter=_ids_converter)
    bbox: Optional[BBox] = attr.ib(default=None, converter=_bbox_converter)
    intersects: Annotated[
        Optional[str],
        Query(
            description="""Only return items intersecting this GeoJSON Geometry. Mutually exclusive with **bbox**. \n
*Remember to URL encode the GeoJSON geometry when using GET request*.""",  # noqa: E501
            openapi_examples={
                "user-provided": {"value": None},
                "madrid": {
                    "value": {
                        "type": "Feature",
                        "properties": {},
                        "geometry": {
                            "coordinates": [
                                [
                                    [-3.8549260500072933, 40.54923557897152],
                                    [-3.8549260500072933, 40.29428000041938],
                                    [-3.516597069715033, 40.29428000041938],
                                    [-3.516597069715033, 40.54923557897152],
                                    [-3.8549260500072933, 40.54923557897152],
                                ]
                            ],
                            "type": "Polygon",
                        },
                    },
                },
                "new-york": {
                    "value": {
                        "type": "Feature",
                        "properties": {},
                        "geometry": {
                            "coordinates": [
                                [
                                    [-74.50117532354284, 41.128266394414055],
                                    [-74.50117532354284, 40.35633909727355],
                                    [-73.46713183168603, 40.35633909727355],
                                    [-73.46713183168603, 41.128266394414055],
                                    [-74.50117532354284, 41.128266394414055],
                                ]
                            ],
                            "type": "Polygon",
                        },
                    },
                },
            },
        ),
    ] = attr.ib(default=None)
    datetime: DateTimeQueryType = attr.ib(default=None, validator=_validate_datetime)
    limit: Annotated[
        Optional[Limit],
        Query(
            description="Limits the number of results that are included in each page of the response (capped to 10_000)."  # noqa: E501
        ),
    ] = attr.ib(default=10)

BaseSearchPostRequest

Bases: Search

Base arguments for POST Request.

Source code in stac_fastapi/types/search.py
234
235
236
237
238
239
240
class BaseSearchPostRequest(Search):
    """Base arguments for POST Request."""

    limit: Optional[Limit] = Field(
        10,
        description="Limits the number of results that are included in each page of the response (capped to 10_000).",  # noqa: E501
    )

DatetimeMixin

Datetime Mixin.

Source code in stac_fastapi/types/search.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
@attr.s
class DatetimeMixin:
    """Datetime Mixin."""

    datetime: DateTimeQueryType = attr.ib(default=None, validator=_validate_datetime)

    def parse_datetime(self) -> Optional[DateTimeType]:
        """Return Datetime objects."""
        return str_to_interval(self.datetime)

    @property
    def start_date(self) -> Optional[dt]:
        """Start Date."""
        parsed = self.parse_datetime()
        if parsed is None:
            return None

        return parsed[0] if isinstance(parsed, tuple) else parsed

    @property
    def end_date(self) -> Optional[dt]:
        """End Date."""
        parsed = self.parse_datetime()
        if parsed is None:
            return None

        return parsed[1] if isinstance(parsed, tuple) else None

end_date property

end_date: Optional[datetime]

End Date.

start_date property

start_date: Optional[datetime]

Start Date.

parse_datetime

parse_datetime() -> Optional[DateTimeType]

Return Datetime objects.

Source code in stac_fastapi/types/search.py
147
148
149
def parse_datetime(self) -> Optional[DateTimeType]:
    """Return Datetime objects."""
    return str_to_interval(self.datetime)

crop

Crop value to 10,000.

Source code in stac_fastapi/types/search.py
18
19
20
21
22
23
def crop(v: PositiveInt) -> PositiveInt:
    """Crop value to 10,000."""
    limit = 10_000
    if v > limit:
        v = limit
    return v

str2bbox

str2bbox(x: str) -> Optional[BBox]

Convert string to BBox based on , delimiter.

Source code in stac_fastapi/types/search.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def str2bbox(x: str) -> Optional[BBox]:
    """Convert string to BBox based on , delimiter."""
    if x:
        try:
            t = tuple(float(v) for v in x.split(","))
        except ValueError:
            raise HTTPException(status_code=400, detail=f"invalid bbox: {x}")

        if len(t) not in (4, 6):
            raise HTTPException(
                status_code=400, detail=f"BBox '{x}' must have 4 or 6 values."
            )

        return t

    return None

str2list

str2list(x: str) -> Optional[List[str]]

Convert string to list base on , delimiter.

Source code in stac_fastapi/types/search.py
26
27
28
29
30
31
def str2list(x: str) -> Optional[List[str]]:
    """Convert string to list base on , delimiter."""
    if x:
        return x.split(",")

    return None