Skip to content

Module stac_fastapi.api.app

Fastapi app creation.

Variables

DEFAULT_STATUS_CODES
STAC_VERSION

Classes

StacApi

class StacApi(
    settings: stac_fastapi.types.config.ApiSettings,
    client: Union[stac_fastapi.types.core.AsyncBaseCoreClient, stac_fastapi.types.core.BaseCoreClient],
    extensions: List[stac_fastapi.types.extension.ApiExtension] = NOTHING,
    exceptions: Dict[Type[Exception], int] = NOTHING,
    app: fastapi.applications.FastAPI = NOTHING,
    router: fastapi.routing.APIRouter = NOTHING,
    title: str = NOTHING,
    api_version: str = NOTHING,
    stac_version: str = '1.0.0',
    description: str = NOTHING,
    search_get_request_model: Type[stac_fastapi.types.search.BaseSearchGetRequest] = <class 'stac_fastapi.types.search.BaseSearchGetRequest'>,
    search_post_request_model: Type[stac_fastapi.types.search.BaseSearchPostRequest] = <class 'stac_fastapi.types.search.BaseSearchPostRequest'>,
    collections_get_request_model: Type[stac_fastapi.types.search.APIRequest] = <class 'stac_fastapi.api.models.EmptyRequest'>,
    collection_get_request_model: Type[stac_fastapi.types.search.APIRequest] = <class 'stac_fastapi.api.models.CollectionUri'>,
    items_get_request_model: Type[stac_fastapi.types.search.APIRequest] = <class 'stac_fastapi.api.models.ItemCollectionUri'>,
    item_get_request_model: Type[stac_fastapi.types.search.APIRequest] = <class 'stac_fastapi.api.models.ItemUri'>,
    response_class: Type[starlette.responses.Response] = <class 'starlette.responses.JSONResponse'>,
    middlewares: List[starlette.middleware.Middleware] = NOTHING,
    route_dependencies: List[Tuple[List[stac_fastapi.api.routes.Scope], List[fastapi.params.Depends]]] = []
)

StacApi factory.

Factory for creating a STAC-compliant FastAPI application. After instantation, the application is accessible from the StacApi.app attribute.

Attributes

Name Type Description Default
settings None API settings and configuration, potentially using environment
variables. See pydantic-docs.helpmanual.io/usage/settings/.
None
client None A subclass of stac_api.clients.BaseCoreClient. Defines the
application logic which is injected into the API.
None
extensions None API extensions to include with the application. This may include
official STAC extensions as well as third-party add ons.
None
exceptions None Defines a global mapping between exceptions and status codes,
allowing configuration of response behavior on certain exceptions
(fastapi.tiangolo.com/tutorial/handling-errors/#install-custom-exception-handlers).
None
app None The FastAPI application, defaults to a fresh application. None
route_dependencies None List of tuples of route scope dicts (eg {'path':<br>'/collections', 'method': 'POST'}) and list of dependencies (e.g.
[Depends(oauth2_scheme)])). Applies specified dependencies to
specified routes. This is useful
for applying custom auth requirements to routes defined elsewhere in
the application.
None

Methods

add_health_check

def add_health_check(
    self
)

Add a health check.

add_route_dependencies

def add_route_dependencies(
    self,
    scopes: List[stac_fastapi.api.routes.Scope],
    dependencies=typing.List[fastapi.params.Depends]
) -> None

Add custom dependencies to routes.

Parameters:

Name Type Description Default
scopes None list of scopes. Each scope should be a dict with a path
and method property.
None
dependencies None list of FastAPI
dependencies

to apply to each scope.
None

Returns:

Type Description
None None

customize_openapi

def customize_openapi(
    self
) -> Optional[Dict[str, Any]]

Customize openapi schema.

get_extension

def get_extension(
    self,
    extension: Type[stac_fastapi.types.extension.ApiExtension]
) -> Optional[stac_fastapi.types.extension.ApiExtension]

Get an extension.

Parameters:

Name Type Description Default
extension None extension to check for. None

Returns:

Type Description
None The extension instance, if it exists.

register_conformance_classes

def register_conformance_classes(
    self
)

Register conformance classes (GET /conformance).

Returns:

Type Description
None None

register_core

def register_core(
    self
)

Register core STAC endpoints.

GET / GET /conformance GET /collections GET /collections/{collection_id} GET /collections/{collection_id}/items GET /collection/{collection_id}/items/{item_id} GET /search POST /search

Injects application logic (StacApi.client) into the API layer.

Returns:

Type Description
None None

register_get_collection

def register_get_collection(
    self
)

Register get collection endpoint (GET /collection/{collection_id}).

Returns:

Type Description
None None

register_get_collections

def register_get_collections(
    self
)

Register get collections endpoint (GET /collections).

Returns:

Type Description
None None

register_get_item

def register_get_item(
    self
)

Register get item endpoint (GET /collections/{collection_id}/items/{item_id}).

Returns:

Type Description
None None

register_get_item_collection

def register_get_item_collection(
    self
)

Register get item collection endpoint (GET /collection/{collection_id}/items).

Returns:

Type Description
None None
def register_get_search(
    self
)

Register search endpoint (GET /search).

Returns:

Type Description
None None

register_landing_page

def register_landing_page(
    self
)

Register landing page (GET /).

Returns:

Type Description
None None

register_post_search

def register_post_search(
    self
)

Register search endpoint (POST /search).

Returns:

Type Description
None None