Skip to content

Commit f7a7f71

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
Add STAC_ITEM_LIMIT environment variable for result limiting
This commit introduces the STAC_ITEM_LIMIT environment variable to control the maximum number of items returned by key API endpoints: - GET /collections - Limits collections returned - GET /collections/{collection_id}/items - Limits items in a collection - GET /search - Limits search results
1 parent 51ac649 commit f7a7f71

File tree

1 file changed

+7
-4
lines changed
  • stac_fastapi/core/stac_fastapi/core

1 file changed

+7
-4
lines changed

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Core client."""
22

33
import logging
4+
import os
45
from datetime import datetime as datetime_type
56
from datetime import timezone
67
from enum import Enum
@@ -234,7 +235,7 @@ async def all_collections(self, **kwargs) -> stac_types.Collections:
234235
"""
235236
request = kwargs["request"]
236237
base_url = str(request.base_url)
237-
limit = int(request.query_params.get("limit", 10))
238+
limit = int(request.query_params.get("limit", os.getenv("STAC_ITEM_LIMIT", 10)))
238239
token = request.query_params.get("token")
239240

240241
collections, next_token = await self.database.get_all_collections(
@@ -285,7 +286,7 @@ async def item_collection(
285286
collection_id: str,
286287
bbox: Optional[BBox] = None,
287288
datetime: Optional[str] = None,
288-
limit: Optional[int] = 10,
289+
limit: Optional[int] = None,
289290
token: Optional[str] = None,
290291
**kwargs,
291292
) -> stac_types.ItemCollection:
@@ -295,7 +296,7 @@ async def item_collection(
295296
collection_id (str): The identifier of the collection to read items from.
296297
bbox (Optional[BBox]): The bounding box to filter items by.
297298
datetime (Optional[str]): The datetime range to filter items by.
298-
limit (int): The maximum number of items to return. The default value is 10.
299+
limit (int): The maximum number of items to return.
299300
token (str): A token used for pagination.
300301
request (Request): The incoming request.
301302
@@ -341,6 +342,7 @@ async def item_collection(
341342

342343
search = self.database.apply_bbox_filter(search=search, bbox=bbox)
343344

345+
limit = int(request.query_params.get("limit", os.getenv("STAC_ITEM_LIMIT", 10)))
344346
items, maybe_count, next_token = await self.database.execute_search(
345347
search=search,
346348
limit=limit,
@@ -393,7 +395,7 @@ async def get_search(
393395
ids: Optional[List[str]] = None,
394396
bbox: Optional[BBox] = None,
395397
datetime: Optional[str] = None,
396-
limit: Optional[int] = 10,
398+
limit: Optional[int] = None,
397399
query: Optional[str] = None,
398400
token: Optional[str] = None,
399401
fields: Optional[List[str]] = None,
@@ -426,6 +428,7 @@ async def get_search(
426428
Raises:
427429
HTTPException: If any error occurs while searching the catalog.
428430
"""
431+
limit = int(request.query_params.get("limit", os.getenv("STAC_ITEM_LIMIT", 10)))
429432
base_args = {
430433
"collections": collections,
431434
"ids": ids,

0 commit comments

Comments
 (0)