Initial commit
Some checks failed
Run linters on applied template / Python 3.13 lint and build (push) Failing after 32s

This is a FastAPI backend microservice template used with `copier` utility.

Features of applied template are:
- Configuration file processing logic
- Metrics and tracing (both optional) configuration available
- Debug endpoints
- Database migration commands, prepared Alembic environment
- Database usage example in ping_db endpoint
- gitea sanity check pipeline
This commit is contained in:
2025-11-29 21:42:27 +03:00
commit 1a5b71b692
52 changed files with 4563 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
"""Database configuration class is defined here."""
from dataclasses import dataclass
from typing import Any
from {{project_slug}}.utils.secrets import SecretStr
@dataclass
class DBConfig:
host: str
port: int
database: str
user: str
password: SecretStr
pool_size: int
def __post_init__(self):
self.password = SecretStr(self.password)
@dataclass
class MultipleDBsConfig:
master: DBConfig
replicas: list[DBConfig] | None = None
def __post_init__(self):
_dict_to_dataclass(self, "master", DBConfig)
if self.replicas is not None:
_list_dict_to_dataclasses(self, "replicas", DBConfig)
def _list_dict_to_dataclasses(config_entry: Any, field_name: str, need_type: type) -> None:
list_dict = getattr(config_entry, field_name)
for i in range(len(list_dict)): # pylint: disable=consider-using-enumerate
if isinstance(list_dict[i], dict):
list_dict[i] = need_type(**list_dict[i])
def _dict_to_dataclass(config_entry: Any, field_name: str, need_type: type) -> None:
value = getattr(config_entry, field_name)
if isinstance(value, dict):
setattr(config_entry, field_name, need_type(**value))