Version 0.2.0
All checks were successful
Run linters on applied template / Python 3.13 lint and build (push) Successful in 54s

Changes:
- add metrics dispencer
- add basic authentication dependency
- enable GZIP middleware
- add !env() example to deploy section
- update dependencies state attribute name
This commit is contained in:
2025-11-30 16:59:25 +03:00
parent afe5d882ac
commit 34c1347402
16 changed files with 180 additions and 74 deletions

View File

@@ -7,19 +7,21 @@ from {{project_slug}}.db.connection.manager import PostgresConnectionManager
def init_dispencer(app: FastAPI, connection_manager: PostgresConnectionManager) -> None:
"""Initialize PostgresConnectionManager dispencer at app's state."""
if hasattr(app.state, "postgres_connection_manager"):
if not isinstance(app.state.postgres_connection_manager, PostgresConnectionManager):
if hasattr(app.state, "postgres_connection_manager_dep"):
if not isinstance(app.state.postgres_connection_manager_dep, PostgresConnectionManager):
raise ValueError(
"postgres_connection_manager attribute of app's state is already set"
f"with other value ({app.state.postgres_connection_manager})"
"postgres_connection_manager_dep attribute of app's state is already set"
f"with other value ({app.state.postgres_connection_manager_dep})"
)
return
app.state.postgres_connection_manager = connection_manager
app.state.postgres_connection_manager_dep = connection_manager
def obtain(request: Request) -> PostgresConnectionManager:
def obtain(app_or_request: FastAPI | Request) -> PostgresConnectionManager:
"""Get a PostgresConnectionManager from request's app state."""
if not hasattr(request.app.state, "postgres_connection_manager"):
if isinstance(app_or_request, Request):
app_or_request = app_or_request.app
if not hasattr(app_or_request.state, "postgres_connection_manager_dep"):
raise ValueError("PostgresConnectionManager dispencer was not initialized at app preparation")
return request.app.state.postgres_connection_manager
return app_or_request.state.postgres_connection_manager_dep