Skip to content

Commit 7afdbb6

Browse files
tmgbeduclaude
andauthored
feat: update fastapi-app example (#75)
* feat: update fastapi-app example Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Refresh fastapi-app example: robust base_path, FastAPI 0.139, config conventions - bootstrap: derive base_path from Path(__file__).parent.parent so the app root (config/, storage/, routes/) resolves independently of the working directory instead of Path.cwd(). - Bump the framework fastapi extra and dev pin to fastapi[standard] 0.139.x (was capped <0.125.0) and relock both the framework and the example. - Rewrite config/logging.py to the current LoggingConfig dataclass using the typed StackChannel/DailyChannel/TerminalChannel channels, and register it via (LogProvider, LoggingConfig) so the example's config is actually loaded. - Add the FastAPIConfig docstring to match the framework default. * Align fastapi-app example config; keep framework fastapi dependency unchanged --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 16d15b7 commit 7afdbb6

6 files changed

Lines changed: 36 additions & 29 deletions

File tree

example/fastapi-app/bootstrap/application.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
from fastapi_startkit.logging import LogProvider
55
from providers.fastapi_provider import FastAPIProvider
66
from config.fastapi import FastAPIConfig
7+
from config.logging import LoggingConfig
78

89
app: Application = Application(
9-
base_path=str(Path.cwd()), # This always gives path relative to the execution.
10+
base_path=str(Path(__file__).parent.parent),
1011
providers=[
11-
LogProvider,
12+
(LogProvider, LoggingConfig),
1213
(FastAPIProvider, FastAPIConfig),
13-
]
14+
],
1415
)

example/fastapi-app/config/fastapi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
@dataclasses.dataclass
77
class FastAPIConfig:
8-
app_url: str = dataclasses.field(default_factory=lambda: env("APP_URL", "http://localhost"))
9-
host: str = dataclasses.field(default_factory=lambda: env("APP_HOST", "127.0.0.1"))
10-
port: int = dataclasses.field(default_factory=lambda: env("APP_PORT", 8000))
8+
app_url: str = dataclasses.field(default_factory=lambda: env("APP_URL", "http://127.0.0.1:8000"))
119
reload: bool = dataclasses.field(default_factory=lambda: env("APP_RELOAD", True))
1210
reload_dirs: list | None = None
1311
reload_excludes: list = dataclasses.field(
Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
# config/logging.py
2-
DEFAULT = 'stack'
1+
import dataclasses
32

4-
CHANNELS = {
5-
'daily': {
6-
'driver': 'daily',
7-
'level': 'debug',
8-
'path': 'storage/logs'
9-
},
10-
'terminal': {
11-
'driver': 'terminal',
12-
'level': 'info',
13-
},
14-
'stack': {
15-
'driver': 'stack',
16-
'channels': ['daily', 'terminal']
17-
}
18-
}
3+
from fastapi_startkit.environment import env
4+
from fastapi_startkit.logging.config import DailyChannel, StackChannel, TerminalChannel
5+
6+
7+
@dataclasses.dataclass
8+
class LoggingConfig:
9+
default: str = dataclasses.field(default_factory=lambda: env("LOG_CHANNEL", "stack"))
10+
11+
channels: dict = dataclasses.field(
12+
default_factory=lambda: {
13+
"stack": StackChannel(driver="stack", channels=["daily", "terminal"]),
14+
"daily": DailyChannel(
15+
level=env("LOG_DAILY_LEVEL", "debug"),
16+
path=env("LOG_DAILY_PATH", "storage/logs"),
17+
),
18+
"terminal": TerminalChannel(
19+
level=env("LOG_TERMINAL_LEVEL", "info"),
20+
),
21+
}
22+
)

example/fastapi-app/providers/fastapi_provider.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from fastapi_startkit.fastapi import FastAPIProvider as BaseFastapiProvider
22
from routes.api import public
33

4+
45
class FastAPIProvider(BaseFastapiProvider):
56
def boot(self) -> None:
67
super().boot()

example/fastapi-app/routes/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
public = APIRouter()
66

7+
78
@public.get("/")
89
async def index():
910
Logger.info("Welcome to FastAPI StartKit!")
@@ -13,9 +14,10 @@ async def index():
1314
return {
1415
"message": "Welcome to FastAPI StartKit!",
1516
"version": "1.0.0",
16-
"docs": "/docs"
17+
"docs": "/docs",
1718
}
1819

20+
1921
@public.get("/health")
2022
async def health():
2123
Logger.info("Health check passed")

example/fastapi-app/uv.lock

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)