Skip to content

Commit 07c890e

Browse files
move filter client from types to extensions (#704)
* move filter client from types to extensions * update changelog
1 parent fc41f8f commit 07c890e

File tree

4 files changed

+87
-51
lines changed

4 files changed

+87
-51
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased] - TBD
44

5+
### Changed
6+
7+
* moved `AsyncBaseFiltersClient` and `BaseFiltersClient` classes in `stac_fastapi.extensions.core.filter.client` submodule ([#704](https://github.com/stac-utils/stac-fastapi/pull/704))
8+
59
## [3.0.0a2] - 2024-05-31
610

711
### Fixed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""Filter extensions clients."""
2+
3+
import abc
4+
from typing import Any, Dict, Optional
5+
6+
import attr
7+
8+
9+
@attr.s
10+
class AsyncBaseFiltersClient(abc.ABC):
11+
"""Defines a pattern for implementing the STAC filter extension."""
12+
13+
async def get_queryables(
14+
self, collection_id: Optional[str] = None, **kwargs
15+
) -> Dict[str, Any]:
16+
"""Get the queryables available for the given collection_id.
17+
18+
If collection_id is None, returns the intersection of all queryables over all
19+
collections.
20+
21+
This base implementation returns a blank queryable schema. This is not allowed
22+
under OGC CQL but it is allowed by the STAC API Filter Extension
23+
https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables
24+
"""
25+
return {
26+
"$schema": "https://json-schema.org/draft/2019-09/schema",
27+
"$id": "https://example.org/queryables",
28+
"type": "object",
29+
"title": "Queryables for Example STAC API",
30+
"description": "Queryable names for the example STAC API Item Search filter.",
31+
"properties": {},
32+
}
33+
34+
35+
@attr.s
36+
class BaseFiltersClient(abc.ABC):
37+
"""Defines a pattern for implementing the STAC filter extension."""
38+
39+
def get_queryables(
40+
self, collection_id: Optional[str] = None, **kwargs
41+
) -> Dict[str, Any]:
42+
"""Get the queryables available for the given collection_id.
43+
44+
If collection_id is None, returns the intersection of all queryables over all
45+
collections.
46+
47+
This base implementation returns a blank queryable schema. This is not allowed
48+
under OGC CQL but it is allowed by the STAC API Filter Extension
49+
https://github.com/stac-api-extensions/filter#queryables
50+
"""
51+
return {
52+
"$schema": "https://json-schema.org/draft/2019-09/schema",
53+
"$id": "https://example.org/queryables",
54+
"type": "object",
55+
"title": "Queryables for Example STAC API",
56+
"description": "Queryable names for the example STAC API Item Search filter.",
57+
"properties": {},
58+
}

stac_fastapi/extensions/stac_fastapi/extensions/core/filter/filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
from stac_fastapi.api.models import CollectionUri, EmptyRequest, JSONSchemaResponse
1111
from stac_fastapi.api.routes import create_async_endpoint
12-
from stac_fastapi.types.core import AsyncBaseFiltersClient, BaseFiltersClient
1312
from stac_fastapi.types.extension import ApiExtension
1413

14+
from .client import AsyncBaseFiltersClient, BaseFiltersClient
1515
from .request import FilterExtensionGetRequest, FilterExtensionPostRequest
1616

1717

stac_fastapi/types/stac_fastapi/types/core.py

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Base clients."""
22

3-
43
import abc
4+
import importlib
5+
import warnings
56
from typing import Any, Dict, List, Optional, Union
67
from urllib.parse import urljoin
78

@@ -22,6 +23,16 @@
2223
from stac_fastapi.types.rfc3339 import DateTimeType
2324
from stac_fastapi.types.search import BaseSearchPostRequest
2425

26+
__all__ = [
27+
"NumType",
28+
"StacType",
29+
"BaseTransactionsClient",
30+
"AsyncBaseTransactionsClient",
31+
"LandingPageMixin",
32+
"BaseCoreClient",
33+
"AsyncBaseCoreClient",
34+
]
35+
2536
NumType = Union[float, int]
2637
StacType = Dict[str, Any]
2738

@@ -737,53 +748,16 @@ async def item_collection(
737748
...
738749

739750

740-
@attr.s
741-
class AsyncBaseFiltersClient(abc.ABC):
742-
"""Defines a pattern for implementing the STAC filter extension."""
743-
744-
async def get_queryables(
745-
self, collection_id: Optional[str] = None, **kwargs
746-
) -> Dict[str, Any]:
747-
"""Get the queryables available for the given collection_id.
748-
749-
If collection_id is None, returns the intersection of all queryables over all
750-
collections.
751-
752-
This base implementation returns a blank queryable schema. This is not allowed
753-
under OGC CQL but it is allowed by the STAC API Filter Extension
754-
https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables
755-
"""
756-
return {
757-
"$schema": "https://json-schema.org/draft/2019-09/schema",
758-
"$id": "https://example.org/queryables",
759-
"type": "object",
760-
"title": "Queryables for Example STAC API",
761-
"description": "Queryable names for the example STAC API Item Search filter.",
762-
"properties": {},
763-
}
764-
765-
766-
@attr.s
767-
class BaseFiltersClient(abc.ABC):
768-
"""Defines a pattern for implementing the STAC filter extension."""
769-
770-
def get_queryables(
771-
self, collection_id: Optional[str] = None, **kwargs
772-
) -> Dict[str, Any]:
773-
"""Get the queryables available for the given collection_id.
774-
775-
If collection_id is None, returns the intersection of all queryables over all
776-
collections.
751+
# TODO: remove for 3.0.0 final release
752+
def __getattr__(name: str) -> Any:
753+
if name in ["AsyncBaseFiltersClient", "BaseFiltersClient"]:
754+
warnings.warn(
755+
f"""importing {name} from `stac_fastapi.types.core` is deprecated,
756+
please import it from `stac_fastapi.extensions.core.filter.client`.""",
757+
DeprecationWarning,
758+
stacklevel=2,
759+
)
760+
clients = importlib.import_module("stac_fastapi.extensions.core.filter.client")
761+
return getattr(clients, name)
777762

778-
This base implementation returns a blank queryable schema. This is not allowed
779-
under OGC CQL but it is allowed by the STAC API Filter Extension
780-
https://github.com/stac-api-extensions/filter#queryables
781-
"""
782-
return {
783-
"$schema": "https://json-schema.org/draft/2019-09/schema",
784-
"$id": "https://example.org/queryables",
785-
"type": "object",
786-
"title": "Queryables for Example STAC API",
787-
"description": "Queryable names for the example STAC API Item Search filter.",
788-
"properties": {},
789-
}
763+
raise AttributeError(f"module {__name__} has no attribute {name}")

0 commit comments

Comments
 (0)