python_template_server.routers

Routers for the FastAPI server.

class python_template_server.routers.BaseRouter(prefix)[source]

Abstract base class for API routers.

__init__(prefix)[source]

Initialize the base router.

abstractmethod setup_routes()[source]

Abstract method to set up API routes.

Return type:

None

configure(hashed_token, limiter, rate_limit)[source]

Configure the router with shared dependencies.

Parameters:
  • hashed_token (str) – The hashed token for API key verification

  • limiter (Limiter | None) – The rate limiter instance to use for this router

  • rate_limit (str) – The rate limit string to apply to limited routes

Return type:

None

add_route(endpoint, handler_function, response_model, methods, limited, authentication_required)[source]

Add an API route.

Parameters:
  • endpoint (str) – The API endpoint path

  • handler_function (Callable) – The handler function for the endpoint

  • response_model (type[BaseModel] | None) – The Pydantic model for the response

  • methods (list[str]) – The HTTP methods for the endpoint

  • limited (bool) – Whether to apply rate limiting to this route

  • authentication_required (bool) – Whether authentication is required for this route

Return type:

None

class python_template_server.routers.TemplateServerRouter(prefix)[source]

Router for the template server with health and login endpoints.

setup_routes()[source]

Set up the API routes for the template server.

Return type:

None

async get_health(request)[source]

Get server health.

Parameters:

request (Request) – The incoming HTTP request

Return GetHealthResponse:

Health status response

Raises:

HTTPException – If the server token is not configured

Return type:

GetHealthResponse

async get_login(request)[source]

Handle user login and return a success response.

Parameters:

request (Request) – The incoming HTTP request

Return GetLoginResponse:

Login success response

Raises:

HTTPException – If the server token is not configured

Return type:

GetLoginResponse

Modules

base_router

Base router for the FastAPI server.

template_server_router

Template server router with health and login endpoints.