-
-
Save ItaruTran/7f7420931594cc5863ee0403055b4d35 to your computer and use it in GitHub Desktop.
High performance Fastapi on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[tool.poetry] | |
name = "test" | |
version = "0.1.0" | |
description = "" | |
[tool.poetry.dependencies] | |
python = "^3.7" | |
fastapi = {extras = ["all"], version = "^0.52.0"} | |
uvicorn = "^0.11.5" | |
orjson = "^3.2.2" | |
[build-system] | |
requires = ["poetry>=0.12"] | |
build-backend = "poetry.masonry.api" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import FastAPI | |
from fastapi.responses import ORJSONResponse | |
app = FastAPI( | |
default_response_class=ORJSONResponse | |
) | |
@app.get("/") | |
def root(): | |
return {"message": "Hello World"} | |
app.on_event('startup')(lambda: print('startup')) | |
app.on_event('shutdown')(lambda: print('shutdown')) | |
if __name__ == "__main__": | |
from asyncio import ProactorEventLoop, set_event_loop, get_event_loop | |
from uvicorn import Config, Server | |
set_event_loop(ProactorEventLoop()) | |
server = Server(config=Config(app=app)) | |
get_event_loop().run_until_complete(server.serve()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment