https://blog.csdn.net/m0_68255105/article/details/123958466
FastAPI 是一个现代、快速(高性能)的 Web 框架,用于基于 Python 的标准类型提示在 Python 3.6 及更高版本中构建 API。 FastAPI 能够自动生成 Swagger UI 和 ReDoc 样式文档。
pip install fastapi
from fastapi import FastAPI
# Swagger文档 http://localhost:8000/docs
# 随后可参考 https://cloud.tencent.com/developer/article/1827065
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/hello/{name}")
async def say_hello(name: str):
return {"message": f"Hello {name}"}
@app.post("/user")
async def psm_predict(data, version):
user_id = data.user_id
print(version)
if user_id == 1:
res = {'id': user_id, 'name': '张三', 'msg': 'ok'}
else:
res = {'msg': 'id is not exist'}
return res
uvicorn
pip install uvicorn