-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
28 lines (21 loc) · 679 Bytes
/
main.py
File metadata and controls
28 lines (21 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import contextlib
from typing import AsyncIterator
import uvicorn
from fastapi import FastAPI
import orm
from api import user
from app.settings import settings
@contextlib.asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
orm.db_manager.init(settings.database_url)
yield
await orm.db_manager.close()
app = FastAPI(title="Very simple example", lifespan=lifespan)
app.include_router(user.router, prefix="/api/users", tags=["users"])
if __name__ == "__main__":
# There are a lot of parameters for uvicorn, you should check the docs
uvicorn.run(
app,
host=settings.app_host,
port=settings.app_port,
)