Fast Api

FastApi基础入门

FastApi基础框架

安装FastApi

pip install fastapi[all]

如果是uv

uv add fastapi[all]

创建项目

from fastapi import FastAPI # 创建 FastAPI 实例 app = FastAPI() @app.get("/") async def root(): return {"message": "Hello World888"} # 访问 /hello 响应结果 msg: 你好 FastAPI @app.get("/hello") async def get_hello(): return {"msg": "你好 FastAPI"}

运行项目

# --reload:更改代码后自动重启服务器,其中“project”是python入口文件名 uvicorn project:app --reload