config
Configuration loading for the end-user name generator web application.
The application supports a small INI file so end users can set runtime values
without changing Python code. The most important setting is port; when it
is omitted the server auto-selects a free port in the 8000 range.
The canonical INI section name is [webapp]. For backward compatibility,
[server] is accepted as a fallback when [webapp] is not present.
Attributes
Classes
Server runtime settings. |
Functions
|
Load server settings from an INI file. |
|
Apply command-line overrides over loaded settings. |
Module Contents
- config.DEFAULT_HOST = '127.0.0.1'
- config.DEFAULT_DB_PATH
- config.DEFAULT_FAVORITES_DB_PATH
- config.DEFAULT_DB_EXPORT_PATH: pathlib.Path | None = None
- config.DEFAULT_DB_BACKUP_PATH: pathlib.Path | None = None
- class config.ServerSettings
Server runtime settings.
- host
Interface to bind (default localhost)
- port
Optional explicit port.
Nonemeans auto-select.
- db_path
SQLite database file path
- favorites_db_path
SQLite database file path for user favorites
- verbose
Print startup/runtime messages when True
- serve_ui
When
True, serve UI/static routes in addition to the API.
- db_path: pathlib.Path
- favorites_db_path: pathlib.Path
- db_export_path: pathlib.Path | None = None
- db_backup_path: pathlib.Path | None = None
- config.load_server_settings(config_path)
Load server settings from an INI file.
The parser reads a
[webapp]section (preferred) or[server]section (backward-compatible fallback) with the following optional keys:host,port,db_path,favorites_db_path,verbose, andserve_ui. An optionalapi_onlyflag can be used to force API-only mode and overridesserve_uiwhen set.- Parameters:
config_path (pathlib.Path | None) – Path to INI file. If missing/None, defaults are used.
- Returns:
Parsed
ServerSettingsinstance- Raises:
ValueError – If a setting is syntactically invalid
- Return type:
- config.apply_runtime_overrides(settings, host, port, db_path, favorites_db_path, db_export_path, db_backup_path, verbose, serve_ui)
Apply command-line overrides over loaded settings.
- Parameters:
settings (ServerSettings) – Base settings (typically from INI)
host (str | None) – Optional host override
port (int | None) – Optional port override
db_path (pathlib.Path | None) – Optional database path override
favorites_db_path (pathlib.Path | None) – Optional favorites database path override
verbose (bool | None) – Optional verbose override
serve_ui (bool | None) – Optional UI routing override
- Returns:
Updated settings with overrides applied
- Return type: