FastAPI + LangGraph 从零开发智能实验室预约系统

本集视频在 B 站 BV13hbP6zEUd · P5

去 B 站看本集

04. 搭建后端FastAPI工程

软件

打开文件的地址栏 输入 %AppData%

Pip 国内镜像(阿里云):

text
https://mirrors.aliyun.com/pypi/simple/

pip.ini

bash
[global]
index-url=https://mirrors.aliyun.com/pypi/simple

创建后端工程 FastAPI

设置虚拟环境 并激活

bash
py -m venv .venv
.venv\Scripts\Activate.ps1

安装依赖 requirements.txt

text
fastapi==0.115.13
uvicorn==0.34.0
sqlalchemy==2.0.41
pymysql==1.1.1
pydantic-settings==2.7.1

安装指令:

bash
pip install -r requirements.txt

VsCode 安装相关的插件

Python:显示 python 的语法高亮

Black Formatter:格式化代码

写第一个接口 并测试

python
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def root():
    return {"message": "Hello FastAPI"}

启动测试

bash
uvicorn app.main:app --reload --port 8000 --host 127.0.0.1