Skip to content

Commit ec0a2bf

Browse files
authored
Merge pull request #1 from fastapi-startkit/task/fastapi-starkit
Add FastAPI Startkit benchmark
2 parents 11096b8 + 9bb5bca commit ec0a2bf

9 files changed

Lines changed: 91 additions & 0 deletions

File tree

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
[build-system]
3+
build-backend = "flit_core.buildapi"
4+
requires = ["flit_core"]
5+
6+
[project]
7+
name = 'server'
8+
version = '1.0.0'
9+
description = "Simple benchmark implementation"
10+
dependencies = ["fastapi-startkit[fastapi]>=0.46,<0.47"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from fastapi import APIRouter
2+
from starlette.responses import PlainTextResponse
3+
4+
public = APIRouter()
5+
6+
7+
@public.get("/")
8+
async def index():
9+
return PlainTextResponse(content="")
10+
11+
12+
@public.get("/user/{id}")
13+
async def get_user(id: int):
14+
return PlainTextResponse(content=f"{id}".encode())
15+
16+
17+
@public.post("/user")
18+
async def create_user():
19+
return PlainTextResponse(content="")

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ python:
7070
- ahopkins
7171
fastapi:
7272
- tiangolo
73+
fastapi_startkit:
74+
- tmgbedu
7375
tonberry:
7476
- Ayehavgunne
7577
asgineer:

0 commit comments

Comments
 (0)