python_template_server.models

Pydantic models for the server.

Classes

BaseResponse(**data)

Base response model for all API endpoints.

CORSConfigModel(**data)

CORS (Cross-Origin Resource Sharing) configuration model.

CertificateConfigModel(**data)

Certificate configuration model.

CustomJSONResponse(content[, status_code, ...])

Custom JSONResponse with configurable rendering options.

GetHealthResponse(**data)

Response model for the health endpoint.

GetLoginResponse(**data)

Response model for login endpoint.

JSONResponseConfigModel(**data)

JSON response rendering configuration model.

RateLimitConfigModel(**data)

Rate limit configuration model.

ResponseCode(*values)

HTTP response codes for API endpoints.

SecurityConfigModel(**data)

Security headers configuration model.

TemplateServerConfig(**data)

Template server configuration.

class python_template_server.models.SecurityConfigModel(**data)[source]

Security headers configuration model.

hsts_max_age: int
content_security_policy: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.CORSConfigModel(**data)[source]

CORS (Cross-Origin Resource Sharing) configuration model.

enabled: bool
allow_origins: list[str]
allow_credentials: bool
allow_methods: list[str]
allow_headers: list[str]
expose_headers: list[str]
max_age: int
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.RateLimitConfigModel(**data)[source]

Rate limit configuration model.

enabled: bool
rate_limit: str
storage_uri: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.CertificateConfigModel(**data)[source]

Certificate configuration model.

directory: str
ssl_keyfile: str
ssl_certfile: str
days_valid: int
property ssl_key_file_path: Path

Get the full path to the SSL key file.

property ssl_cert_file_path: Path

Get the full path to the SSL certificate file.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.JSONResponseConfigModel(**data)[source]

JSON response rendering configuration model.

ensure_ascii: bool
allow_nan: bool
indent: int | None
media_type: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.TemplateServerConfig(**data)[source]

Template server configuration.

security: SecurityConfigModel
cors: CORSConfigModel
rate_limit: RateLimitConfigModel
certificate: CertificateConfigModel
json_response: JSONResponseConfigModel
save_to_file(filepath)[source]

Save the configuration to a JSON file.

Parameters:

filepath (Path) – Path to the configuration file

Return type:

None

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.CustomJSONResponse(content, status_code=200, headers=None, media_type=None, background=None)[source]

Custom JSONResponse with configurable rendering options.

classmethod configure(json_response_config)[source]

Configure class-level JSON rendering options.

Return type:

None

render(content)[source]

Render content to JSON with configured options.

Return type:

bytes

class python_template_server.models.ResponseCode(*values)[source]

HTTP response codes for API endpoints.

OK = 200
CREATED = 201
ACCEPTED = 202
NO_CONTENT = 204
BAD_REQUEST = 400
UNAUTHORIZED = 401
FORBIDDEN = 403
NOT_FOUND = 404
CONFLICT = 409
INTERNAL_SERVER_ERROR = 500
SERVICE_UNAVAILABLE = 503
class python_template_server.models.BaseResponse(**data)[source]

Base response model for all API endpoints.

message: str
timestamp: str
static current_timestamp()[source]

Get the current timestamp in ISO 8601 format.

Return type:

str

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.GetHealthResponse(**data)[source]

Response model for the health endpoint.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class python_template_server.models.GetLoginResponse(**data)[source]

Response model for login endpoint.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].