python后端api封装

可以将 Python 脚本作为一个后端服务运行,提供 HTTP API 接口,供 Java 通过 HTTP 请求调用。这样无需使用消息队列,也能保持服务的简洁。以下是具体实现步骤:

  1. 使用 FastAPI 搭建 Python HTTP 服务
    FastAPI 是一个现代的、快速的 Web 框架,非常适合构建高性能 API 服务。

安装 FastAPI 和 Uvicorn
pip install fastapi uvicorn

启动服务
2.uvicorn xxx:app --host 0.0.0.0 --port 8000

posted @ 2024-12-13 21:48  IxXi  阅读(86)  评论(0)    收藏  举报