Skip to content

Commit

Permalink
move filter client from types to extensions (#704)
Browse files Browse the repository at this point in the history
* move filter client from types to extensions

* update changelog
  • Loading branch information
vincentsarago authored Jun 6, 2024
1 parent fc41f8f commit 07c890e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased] - TBD

### Changed

* moved `AsyncBaseFiltersClient` and `BaseFiltersClient` classes in `stac_fastapi.extensions.core.filter.client` submodule ([#704](https://github.com/stac-utils/stac-fastapi/pull/704))

## [3.0.0a2] - 2024-05-31

### Fixed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Filter extensions clients."""

import abc
from typing import Any, Dict, Optional

import attr


@attr.s
class AsyncBaseFiltersClient(abc.ABC):
"""Defines a pattern for implementing the STAC filter extension."""

async def get_queryables(
self, collection_id: Optional[str] = None, **kwargs
) -> Dict[str, Any]:
"""Get the queryables available for the given collection_id.
If collection_id is None, returns the intersection of all queryables over all
collections.
This base implementation returns a blank queryable schema. This is not allowed
under OGC CQL but it is allowed by the STAC API Filter Extension
https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables
"""
return {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://example.org/queryables",
"type": "object",
"title": "Queryables for Example STAC API",
"description": "Queryable names for the example STAC API Item Search filter.",
"properties": {},
}


@attr.s
class BaseFiltersClient(abc.ABC):
"""Defines a pattern for implementing the STAC filter extension."""

def get_queryables(
self, collection_id: Optional[str] = None, **kwargs
) -> Dict[str, Any]:
"""Get the queryables available for the given collection_id.
If collection_id is None, returns the intersection of all queryables over all
collections.
This base implementation returns a blank queryable schema. This is not allowed
under OGC CQL but it is allowed by the STAC API Filter Extension
https://github.com/stac-api-extensions/filter#queryables
"""
return {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://example.org/queryables",
"type": "object",
"title": "Queryables for Example STAC API",
"description": "Queryable names for the example STAC API Item Search filter.",
"properties": {},
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from stac_fastapi.api.models import CollectionUri, EmptyRequest, JSONSchemaResponse
from stac_fastapi.api.routes import create_async_endpoint
from stac_fastapi.types.core import AsyncBaseFiltersClient, BaseFiltersClient
from stac_fastapi.types.extension import ApiExtension

from .client import AsyncBaseFiltersClient, BaseFiltersClient
from .request import FilterExtensionGetRequest, FilterExtensionPostRequest


Expand Down
74 changes: 24 additions & 50 deletions stac_fastapi/types/stac_fastapi/types/core.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Base clients."""


import abc
import importlib
import warnings
from typing import Any, Dict, List, Optional, Union
from urllib.parse import urljoin

Expand All @@ -22,6 +23,16 @@
from stac_fastapi.types.rfc3339 import DateTimeType
from stac_fastapi.types.search import BaseSearchPostRequest

__all__ = [
"NumType",
"StacType",
"BaseTransactionsClient",
"AsyncBaseTransactionsClient",
"LandingPageMixin",
"BaseCoreClient",
"AsyncBaseCoreClient",
]

NumType = Union[float, int]
StacType = Dict[str, Any]

Expand Down Expand Up @@ -737,53 +748,16 @@ async def item_collection(
...


@attr.s
class AsyncBaseFiltersClient(abc.ABC):
"""Defines a pattern for implementing the STAC filter extension."""

async def get_queryables(
self, collection_id: Optional[str] = None, **kwargs
) -> Dict[str, Any]:
"""Get the queryables available for the given collection_id.
If collection_id is None, returns the intersection of all queryables over all
collections.
This base implementation returns a blank queryable schema. This is not allowed
under OGC CQL but it is allowed by the STAC API Filter Extension
https://github.com/radiantearth/stac-api-spec/tree/master/fragments/filter#queryables
"""
return {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://example.org/queryables",
"type": "object",
"title": "Queryables for Example STAC API",
"description": "Queryable names for the example STAC API Item Search filter.",
"properties": {},
}


@attr.s
class BaseFiltersClient(abc.ABC):
"""Defines a pattern for implementing the STAC filter extension."""

def get_queryables(
self, collection_id: Optional[str] = None, **kwargs
) -> Dict[str, Any]:
"""Get the queryables available for the given collection_id.
If collection_id is None, returns the intersection of all queryables over all
collections.
# TODO: remove for 3.0.0 final release
def __getattr__(name: str) -> Any:
if name in ["AsyncBaseFiltersClient", "BaseFiltersClient"]:
warnings.warn(
f"""importing {name} from `stac_fastapi.types.core` is deprecated,
please import it from `stac_fastapi.extensions.core.filter.client`.""",
DeprecationWarning,
stacklevel=2,
)
clients = importlib.import_module("stac_fastapi.extensions.core.filter.client")
return getattr(clients, name)

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

0 comments on commit 07c890e

Please sign in to comment.