hasansezertasan/a2wsgi-examples · 文件 下载 ZIP
文件最后提交记录最后更新时间
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈
a2wsgi 示例
本项目的目的是提供示例,展示如何使用 a2wsgi 将不同的 Python Web 框架集成在一起。
为什么
谁喜欢迁移呢?但在某些情况下,这是必要的。a2wsgi 帮助我们将会 ASGI 应用程序转换为 WSGI,或反之。
一个场景(我曾遇到过的):你有一个 Flask 应用程序,想要将其迁移到 FastAPI。你有两个选择:
- 从头重写整个应用程序,并在准备好后部署。
- 使用 a2wsgi 通过 a2wsgi 将你的 Flask 应用程序转换为 WSGI,然后将其集成(挂载)到你的 FastAPI 应用程序中并部署。在此期间,你可以逐步重写你的应用程序。
进度
框架
| 框架 | 挂载 | 协议 | 备注 |
|---|---|---|---|
| Flask | :white_check_mark: | WSGI | 包含 cookie 端点的完整应用 |
| FastAPI | :white_check_mark: | ASGI | 包含 cookie 端点的完整应用 |
| Django | :white_check_mark: | WSGI | |
| Starlette | :white_check_mark: | ASGI | |
| Litestar | :white_check_mark: | ASGI | |
| BlackSheep | :white_check_mark: | ASGI | ASGI 垫片 — 需要自身生命周期以挂载完整应用 |
| Quart | :white_check_mark: | ASGI | |
| Falcon | :white_check_mark: | WSGI | |
| Sanic | :white_check_mark: | ASGI | ASGI 垫片 — 管理自身事件循环 |
| Connexion | :white_check_mark: | ASGI | 未安装时的回退垫片 |
| Bottle | :white_check_mark: | WSGI | |
| Robyn | :white_check_mark: | WSGI | WSGI 垫片 — 无可用 WSGI/ASGI 适配器 |
| HUG | :white_check_mark: | WSGI | |
| Tornado | :white_check_mark: | WSGI | WSGI shim — 运行自身的 IOLoop,无适配器 |
| Pyramid | :white_check_mark: | WSGI | |
| webapp2 | :white_check_mark: | WSGI | 未安装时的回退 shim |
| aiohttp | :white_check_mark: | ASGI | ASGI shim — 不支持原生 ASGI 子应用挂载 |
其他工具
| 框架 | 挂载状态 |
|---|---|
| Gradio | :white_check_mark: |
| PyWebIO | :white_check_mark: |
| Flet | :white_check_mark: |
| NiceGUI | :construction: |
| Reflex | :construction: |
| Streamlit | :white_square_button: |
| Plotly Dash | :white_square_button: |
Emoji 图例:
- :white_check_mark:: 已完成
- :white_square_button:: 尚未尝试
- :x:: 尝试过但失败
- :construction:: 进行中
- :warning:: 不确定是否可行
如何运行
要求
- Python 3.10+
- uv
- Docker & Docker Compose(可选)
本地开发
uv sync
uv run uvicorn app.main:app --reload
Docker
docker compose up --build
前往 http://localhost:8000/docs 查看 API 文档。
运行测试
uv run pytest tests/ -v
贡献
如果您希望为本项目做出贡献,请提交一个 issue 或 pull request。
延伸阅读
- Frameworks that run on WSGI — WSGI.org
- Implementations — ASGI 3.0 documentation
- Application Dispatching — Flask Documentation (3.0.x)
- Sub Applications - Mounts - FastAPI
作者
- hasansezertasan, 就是我 :wave:
许可证
本项目基于 MIT License 授权 - 详见 LICENSE 文件。