diff --git a/example/fastapi-app/bootstrap/application.py b/example/fastapi-app/bootstrap/application.py index deda77d9..59f59f78 100644 --- a/example/fastapi-app/bootstrap/application.py +++ b/example/fastapi-app/bootstrap/application.py @@ -4,11 +4,12 @@ from fastapi_startkit.logging import LogProvider from providers.fastapi_provider import FastAPIProvider from config.fastapi import FastAPIConfig +from config.logging import LoggingConfig app: Application = Application( - base_path=str(Path.cwd()), # This always gives path relative to the execution. + base_path=str(Path(__file__).parent.parent), providers=[ - LogProvider, + (LogProvider, LoggingConfig), (FastAPIProvider, FastAPIConfig), - ] + ], ) diff --git a/example/fastapi-app/config/fastapi.py b/example/fastapi-app/config/fastapi.py index 718195d1..5289e42b 100644 --- a/example/fastapi-app/config/fastapi.py +++ b/example/fastapi-app/config/fastapi.py @@ -5,9 +5,7 @@ @dataclasses.dataclass class FastAPIConfig: - app_url: str = dataclasses.field(default_factory=lambda: env("APP_URL", "http://localhost")) - host: str = dataclasses.field(default_factory=lambda: env("APP_HOST", "127.0.0.1")) - port: int = dataclasses.field(default_factory=lambda: env("APP_PORT", 8000)) + app_url: str = dataclasses.field(default_factory=lambda: env("APP_URL", "http://127.0.0.1:8000")) reload: bool = dataclasses.field(default_factory=lambda: env("APP_RELOAD", True)) reload_dirs: list | None = None reload_excludes: list = dataclasses.field( diff --git a/example/fastapi-app/config/logging.py b/example/fastapi-app/config/logging.py index 906dcd88..d651cf71 100644 --- a/example/fastapi-app/config/logging.py +++ b/example/fastapi-app/config/logging.py @@ -1,18 +1,22 @@ -# config/logging.py -DEFAULT = 'stack' +import dataclasses -CHANNELS = { - 'daily': { - 'driver': 'daily', - 'level': 'debug', - 'path': 'storage/logs' - }, - 'terminal': { - 'driver': 'terminal', - 'level': 'info', - }, - 'stack': { - 'driver': 'stack', - 'channels': ['daily', 'terminal'] - } -} +from fastapi_startkit.environment import env +from fastapi_startkit.logging.config import DailyChannel, StackChannel, TerminalChannel + + +@dataclasses.dataclass +class LoggingConfig: + default: str = dataclasses.field(default_factory=lambda: env("LOG_CHANNEL", "stack")) + + channels: dict = dataclasses.field( + default_factory=lambda: { + "stack": StackChannel(driver="stack", channels=["daily", "terminal"]), + "daily": DailyChannel( + level=env("LOG_DAILY_LEVEL", "debug"), + path=env("LOG_DAILY_PATH", "storage/logs"), + ), + "terminal": TerminalChannel( + level=env("LOG_TERMINAL_LEVEL", "info"), + ), + } + ) diff --git a/example/fastapi-app/providers/fastapi_provider.py b/example/fastapi-app/providers/fastapi_provider.py index 483f3fc2..66e91dba 100644 --- a/example/fastapi-app/providers/fastapi_provider.py +++ b/example/fastapi-app/providers/fastapi_provider.py @@ -1,6 +1,7 @@ from fastapi_startkit.fastapi import FastAPIProvider as BaseFastapiProvider from routes.api import public + class FastAPIProvider(BaseFastapiProvider): def boot(self) -> None: super().boot() diff --git a/example/fastapi-app/routes/api.py b/example/fastapi-app/routes/api.py index 149ed599..11b63d46 100644 --- a/example/fastapi-app/routes/api.py +++ b/example/fastapi-app/routes/api.py @@ -4,6 +4,7 @@ public = APIRouter() + @public.get("/") async def index(): Logger.info("Welcome to FastAPI StartKit!") @@ -13,9 +14,10 @@ async def index(): return { "message": "Welcome to FastAPI StartKit!", "version": "1.0.0", - "docs": "/docs" + "docs": "/docs", } + @public.get("/health") async def health(): Logger.info("Health check passed") diff --git a/example/fastapi-app/uv.lock b/example/fastapi-app/uv.lock index d98c77d9..2c9ed8dc 100644 --- a/example/fastapi-app/uv.lock +++ b/example/fastapi-app/uv.lock @@ -299,7 +299,7 @@ wheels = [ [[package]] name = "fastapi-startkit" -version = "0.43.0" +version = "0.48.0" source = { editable = "../../fastapi_startkit" } dependencies = [ { name = "cleo" }, @@ -321,20 +321,19 @@ fastapi = [ requires-dist = [ { name = "aiomysql", marker = "extra == 'mysql'", specifier = ">=0.2.0" }, { name = "aiosqlite", marker = "extra == 'sqlite'", specifier = ">=0.22.1" }, - { name = "anthropic", marker = "extra == 'ai'", specifier = ">=0.49.0" }, { name = "asyncpg", marker = "extra == 'postgres'", specifier = ">=0.29.0" }, { name = "cleo", specifier = ">=2.1.0,<3.0.0" }, { name = "dotenv", specifier = ">=0.9.9" }, { name = "dotty-dict", specifier = ">=1.3.1" }, { name = "faker", marker = "extra == 'database'", specifier = ">=40.13.0" }, - { name = "fastapi", extras = ["standard"], marker = "extra == 'fastapi'", specifier = ">=0.124.4,<0.125.0" }, - { name = "google-generativeai", marker = "extra == 'ai'", specifier = ">=0.8.0" }, + { name = "fastapi", extras = ["standard"], marker = "extra == 'fastapi'", specifier = ">=0.124.4" }, { name = "inflection", specifier = ">=0.5.1" }, { name = "itsdangerous", marker = "extra == 'fastapi'", specifier = ">=2.2.0" }, { name = "jinja2", marker = "extra == 'inertia'", specifier = ">=3.1" }, { name = "jinja2", marker = "extra == 'vite'", specifier = ">=3.1" }, + { name = "langchain", marker = "extra == 'ai'", specifier = ">=1.0.0" }, + { name = "langchain-core", marker = "extra == 'ai'", specifier = ">=1.0.0" }, { name = "markupsafe", marker = "extra == 'inertia'", specifier = ">=2.0" }, - { name = "openai", marker = "extra == 'ai'", specifier = ">=1.0.0" }, { name = "pendulum", specifier = ">=3.1.0,<4.0.0" }, { name = "pydantic", specifier = ">=2.12.5" }, { name = "requests", specifier = ">=2.32.5,<3.0.0" }, @@ -351,6 +350,8 @@ dev = [ { name = "faker", specifier = ">=40.13.0" }, { name = "fastapi", extras = ["standard"], specifier = ">=0.124.4" }, { name = "itsdangerous", specifier = ">=2.2.0" }, + { name = "langchain", specifier = ">=1.0.0" }, + { name = "langchain-core", specifier = ">=1.0.0" }, { name = "pytest", specifier = ">=9.0.3" }, { name = "pytest-asyncio", specifier = ">=1.3.0" }, { name = "pytest-cov", specifier = ">=6.0.0" }, diff --git a/fastapi_startkit/uv.lock b/fastapi_startkit/uv.lock index 7057c468..47fe08ab 100644 --- a/fastapi_startkit/uv.lock +++ b/fastapi_startkit/uv.lock @@ -527,7 +527,7 @@ wheels = [ [[package]] name = "fastapi-startkit" -version = "0.47.0" +version = "0.48.0" source = { editable = "." } dependencies = [ { name = "cleo" },