python_template_server.template_server¶
Template FastAPI server module.
Classes
|
Template FastAPI server. |
- class python_template_server.template_server.TemplateServer(package_name='python-template-server', api_prefix='/api', api_key_header_name='X-API-Key', config_filepath=PosixPath('/home/runner/work/python-template-server/python-template-server/configuration/config.json'), config=None, static_dir=PosixPath('/home/runner/work/python-template-server/python-template-server/static'))[source]¶
Template FastAPI server.
This class provides a template for building FastAPI servers with common features such as request logging, security headers and rate limiting.
Ensure you implement the routers property and validate_config method in subclasses.
- __init__(package_name='python-template-server', api_prefix='/api', api_key_header_name='X-API-Key', config_filepath=PosixPath('/home/runner/work/python-template-server/python-template-server/configuration/config.json'), config=None, static_dir=PosixPath('/home/runner/work/python-template-server/python-template-server/static'))[source]¶
Initialize the TemplateServer.
- Parameters:
api_prefix (
str) – The API prefix for the serverapi_key_header_name (
str) – The API key header nameconfig_filepath (
Path) – Path to the configuration fileconfig (
TemplateServerConfig|None) – Optional pre-loaded configuration
- property static_dir_exists: bool¶
Check if the static directory exists.
- Return bool:
True if the static directory exists, False otherwise
- abstract property routers: list[BaseRouter]¶
List of BaseRouter instances to include in the server.
- Return list[BaseRouter]:
List of BaseRouter instances
- abstractmethod validate_config(config_data)[source]¶
Validate configuration data against the TemplateServerConfig model.
- load_config(config_filepath)[source]¶
Load configuration from the specified json file.
- Parameters:
config_filepath (
Path) – Path to the configuration file- Return TemplateServerConfig:
The validated configuration model
- Raises:
SystemExit – If configuration file is missing, invalid JSON, or fails validation
- Return type: