我是FastAPI和WebSocket的新手。似乎可以将一些Dataframe输出发布到localhost并将其用于另一个进程。目前,我正在使用xlwings进行此操作,这稍微慢一点。有人可以建议如何使用FastAPI和WebSocket实现这一点吗?我试着按照FastAPI文档来做,但是我不太清楚。
zed5wv101#
尝试from fastapi import FastAPI from fastapi.responses import JSONResponse from pydantic import BaseModel import pandas as pd app = FastAPI() class DataFrameInput(BaseModel):#使用Pydantic BaseModel数据定义DataFrame输入的结构:pd.DataFrame @ app.post(“/receive_rame”)c def receive_rame(rame_input:DataFrameInput):received_rame = rame_input.data #处理收到的rame或保存以备将来使用return JSONResponse(content={“message”:“Dataframe received successfully”})
from fastapi import FastAPI from fastapi.responses import JSONResponse from pydantic import BaseModel import pandas as pd app = FastAPI() class DataFrameInput(BaseModel):#使用Pydantic BaseModel数据定义DataFrame输入的结构:pd.DataFrame @ app.post(“/receive_rame”)c def receive_rame(rame_input:DataFrameInput):received_rame = rame_input.data #处理收到的rame或保存以备将来使用return JSONResponse(content={“message”:“Dataframe received successfully”})
1条答案
按热度按时间zed5wv101#
尝试
from fastapi import FastAPI from fastapi.responses import JSONResponse from pydantic import BaseModel import pandas as pd app = FastAPI() class DataFrameInput(BaseModel):#使用Pydantic BaseModel数据定义DataFrame输入的结构:pd.DataFrame @ app.post(“/receive_rame”)c def receive_rame(rame_input:DataFrameInput):received_rame = rame_input.data #处理收到的rame或保存以备将来使用return JSONResponse(content={“message”:“Dataframe received successfully”})