samgis_web.web package

Submodules

samgis_web.web.exception_handlers module

samgis_web.web.exception_handlers.http_exception_handler(request, exc)[source]

Fastapi exception handler for a generic HTTPException.

Parameters:
  • request (Request) – fastapi request

  • exc (HTTPException) – HTTPException exception

Return type:

JSONResponse

Returns:

fastapi error JSONResponse (500 - HTTP_500_INTERNAL_SERVER_ERROR)

samgis_web.web.exception_handlers.request_validation_exception_handler(request, exc)[source]

Fastapi exception handler for Pydantic RequestValidationError.

Parameters:
  • request (Request) – fastapi request

  • exc (RequestValidationError) – RequestValidationError exception

Return type:

JSONResponse

Returns:

fastapi error JSONResponse (422 - HTTP_422_UNPROCESSABLE_ENTITY)

samgis_web.web.gradio_helpers module

samgis_web.web.middlewares module

async samgis_web.web.middlewares.logging_middleware(request, call_next)[source]

Logging middleware to inject a correlation id in a fastapi application. Requires: - structlog.stdlib logger - setup_logging (samgis_core.utilities.session_logger package) - CorrelationIdMiddleware (asgi_correlation_id package) See tests/web/test_middlewares.py for an example based on a real fastapi application.

Parameters:
  • request (Request) – fastapi Request

  • call_next (Callable) – next callable function

Return type:

Response

Returns:

fastapi Response

samgis_web.web.web_helpers module

web helper functions

samgis_web.web.web_helpers.check_source_type_is_terrain(source)[source]

Check if the given source string or TileProvider is a terrain one, see

Parameters:

source (str | TileProvider) – source string or TileProvider

Return type:

bool

Returns:

a boolean (True if is a DEM/DTM/terrain TileProvider, False otherwise)

samgis_web.web.web_helpers.get_parsed_bbox_points_with_dictlist_prompt(request_input)[source]

Parse the raw input request into bbox, prompt and zoom. If the request is a string this function use ‘model_validate_json()’ method from instance Pydantic BaseModel.

Parameters:

request_input (ApiRequestBody | str) – input dict

Return type:

Dict

Returns:

dict with bounding box, prompt and zoom

samgis_web.web.web_helpers.get_source_name(source)[source]

Return TileProvider.name string based on the output from query_name(). See examples in xyzservices.lib.py, query_name() for details.

Parameters:

source (str | TileProvider) – source string or TileProvider

Return type:

str | bool

Returns:

a string name representing the input TileProvider or source string

samgis_web.web.web_helpers.get_source_tile(source_type)[source]

Return TileProvider instance based on the name query. See examples in xyzservices.lib.py, query_name() for details.

Parameters:

source_type (str) – source name to use in query_name()

Return type:

TileProvider

Returns:

a TileProvider instance

samgis_web.web.web_helpers.get_url_tile(source_type)

Return TileProvider instance based on the name query. See examples in xyzservices.lib.py, query_name() for details.

Parameters:

source_type (str) – source name to use in query_name()

Return type:

TileProvider

Returns:

a TileProvider instance

Module contents