Skip to content

Commit 9bb5bca

Browse files
committed
Add FastAPI Startkit benchmark
Replace the initial placeholder with a benchmark for the real FastAPI Startkit framework (fastapi-startkit) under python/fastapi_startkit. The app is bootstrapped through the framework's provider/container system (bootstrap/application.py + providers/fastapi_provider.py + config/fastapi.py), mirroring the framework's own example app. Routes are registered via the provider boot phase and return plain-text responses matching the benchmark spec. server.py exposes the framework-produced ASGI app as server:app for the standard uvicorn/hypercorn/daphne/granian engines. Verified with docker build + the .spec route suite (6 examples, 0 failures): GET / -> empty, GET /user/{id} -> id, POST /user -> empty.
1 parent 49eae1e commit 9bb5bca

10 files changed

Lines changed: 68 additions & 21 deletions

File tree

python/fastapi_starkit/config.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

python/fastapi_startkit/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.pyc
2+
__pycache__/
3+
.env
4+
.env.*
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
from pathlib import Path
3+
4+
from fastapi_startkit import Application
5+
6+
from config.fastapi import FastAPIConfig
7+
from providers.fastapi_provider import FastAPIProvider
8+
9+
# The framework resolves its runtime environment from APP_ENV (or a .env file);
10+
# the benchmark ships neither, so pin a default before the app boots.
11+
os.environ.setdefault("APP_ENV", "production")
12+
13+
app: Application = Application(
14+
base_path=str(Path(__file__).resolve().parent.parent),
15+
providers=[
16+
(FastAPIProvider, FastAPIConfig),
17+
],
18+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
framework:
2+
website: fastapi-startkit.github.io
3+
github: fastapi-startkit/fastapi-startkit-framework
4+
version: 0.46
5+
6+
engines:
7+
- uvicorn
8+
- hypercorn
9+
- daphne
10+
- granian
11+
12+
language:
13+
version: 3.13
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import dataclasses
2+
3+
from fastapi_startkit.environment import env
4+
5+
6+
@dataclasses.dataclass
7+
class FastAPIConfig:
8+
app_url: str = dataclasses.field(default_factory=lambda: env("APP_URL", "http://0.0.0.0:3000"))
9+
host: str = dataclasses.field(default_factory=lambda: env("APP_HOST", "0.0.0.0"))
10+
port: int = dataclasses.field(default_factory=lambda: env("APP_PORT", 3000))
11+
reload: bool = dataclasses.field(default_factory=lambda: env("APP_RELOAD", False))
12+
reload_dirs: list | None = None
13+
reload_excludes: list = dataclasses.field(default_factory=list)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from fastapi_startkit.fastapi import FastAPIProvider as BaseFastAPIProvider
2+
3+
from routes.api import public
4+
5+
6+
class FastAPIProvider(BaseFastAPIProvider):
7+
def boot(self) -> None:
8+
super().boot()
9+
self.app.include_router(public)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ requires = ["flit_core"]
77
name = 'server'
88
version = '1.0.0'
99
description = "Simple benchmark implementation"
10-
dependencies = ["fastapi>=0.139,<0.140"]
10+
dependencies = ["fastapi-startkit[fastapi]>=0.46,<0.47"]
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
from fastapi import APIRouter, FastAPI
1+
from fastapi import APIRouter
22
from starlette.responses import PlainTextResponse
33

4-
router = APIRouter()
4+
public = APIRouter()
55

66

7-
@router.get("/")
7+
@public.get("/")
88
async def index():
99
return PlainTextResponse(content="")
1010

1111

12-
@router.get("/user/{id}")
12+
@public.get("/user/{id}")
1313
async def get_user(id: int):
1414
return PlainTextResponse(content=f"{id}".encode())
1515

1616

17-
@router.post("/user")
17+
@public.post("/user")
1818
async def create_user():
1919
return PlainTextResponse(content="")
20-
21-
22-
app = FastAPI()
23-
app.include_router(router)

python/fastapi_startkit/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from bootstrap.application import app as application
2+
3+
app = application.fastapi

reviewers.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ python:
7070
- ahopkins
7171
fastapi:
7272
- tiangolo
73-
fastapi_starkit:
74-
- tiangolo
73+
fastapi_startkit:
74+
- tmgbedu
7575
tonberry:
7676
- Ayehavgunne
7777
asgineer:

0 commit comments

Comments
 (0)