FastAPI 是一个用于构建 API 的现代、快速(高性能)的 web 框架
优点:
- 快速
- 高效编码
- 更少Bug
- 智能
- 简单
- 简短
- 健壮
- 标准化
安装
Python3.6及更高版本
使用pip安装即可
pip install fastapi
ASGI服务器,可以选择使用Uvicorn或者Hypercorn
这里使用Uvicorn
pip install uvicorn
示例程序:Hello World
from fastapi import FastAPI
import uvicorn
app = FastAPI()
@app.get('/')
async def main():
return {"message": "Hello FastAPI!"}
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=8080)