Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]

### Added

- `id`, `title`, `description` and `api_version` fields can be customized via env variables

## [2.4.9] - 2023-11-17

### Added
Expand Down
9 changes: 9 additions & 0 deletions docs/tips-and-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ from stac_fastapi.extensions.core.context import ContextExtension
```

and then edit the `api = StacApi(...` call to add `ContextExtension()` to the list given as the `extensions` parameter.

## Set API title, description and version

For the landing page, you can set the API title, description and version using environment variables.

- `STAC_FASTAPI_VERSION` (string) is the version number of your API instance (this is not the STAC version).
- `STAC FASTAPI_TITLE` (string) should be a self-explanatory title for your API.
- `STAC FASTAPI_DESCRIPTION` (string) should be a good description for your API. It can contain CommonMark.
- `STAC_FASTAPI_ID` (string) is a unique identifier for your API.
9 changes: 6 additions & 3 deletions stac_fastapi/api/stac_fastapi/api/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Fastapi app creation."""
import os
from typing import Any, Dict, List, Optional, Tuple, Type, Union

import attr
Expand Down Expand Up @@ -83,10 +84,12 @@ class StacApi:
converter=update_openapi,
)
router: APIRouter = attr.ib(default=attr.Factory(APIRouter))
title: str = attr.ib(default="stac-fastapi")
api_version: str = attr.ib(default="0.1")
title: str = attr.ib(default=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi"))
api_version: str = attr.ib(default=os.getenv("STAC_FASTAPI_VERSION", "0.1"))
stac_version: str = attr.ib(default=STAC_VERSION)
description: str = attr.ib(default="stac-fastapi")
description: str = attr.ib(
default=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi")
)
search_get_request_model: Type[BaseSearchGetRequest] = attr.ib(
default=BaseSearchGetRequest
)
Expand Down
9 changes: 6 additions & 3 deletions stac_fastapi/types/stac_fastapi/types/core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Base clients."""
import abc
import os
from datetime import datetime
from typing import Any, Dict, List, Optional, Union
from urllib.parse import urljoin
Expand Down Expand Up @@ -253,9 +254,11 @@ class LandingPageMixin(abc.ABC):
"""Create a STAC landing page (GET /)."""

stac_version: str = attr.ib(default=STAC_VERSION)
landing_page_id: str = attr.ib(default="stac-fastapi")
title: str = attr.ib(default="stac-fastapi")
description: str = attr.ib(default="stac-fastapi")
landing_page_id: str = attr.ib(default=os.getenv("STAC_FASTAPI_ID", "0.1"))
title: str = attr.ib(default=os.getenv("STAC_FASTAPI_TITLE", "stac-fastapi"))
description: str = attr.ib(
default=os.getenv("STAC_FASTAPI_DESCRIPTION", "stac-fastapi")
)

def _landing_page(
self,
Expand Down