- src/ 按域组织骨架,示例域 items 双后端实现(SQLAlchemy2.0 async / Beanie 2.x) - DB_BACKEND 环境变量切换,router 只依赖 Repo Protocol - alembic 迁移(含初始 items 迁移)、uv 依赖管理、ruff、pytest 异步测试 - Dockerfile + docker-compose(app/mysql/mongo) - AGENTS.md 重写为本模板开发规范;原最佳实践文档归档 docs/ - 验证:mongodb/mysql 双后端 pytest 全绿 + uvicorn 真实冒烟通过
51 lines
1.2 KiB
TOML
51 lines
1.2 KiB
TOML
[project]
|
||
name = "fastapi-template"
|
||
version = "0.1.0"
|
||
description = "开箱即用的 FastAPI 模板:MySQL(SQLAlchemy2.0 async) / MongoDB(Beanie) 可切换"
|
||
requires-python = ">=3.11"
|
||
dependencies = [
|
||
"fastapi>=0.115",
|
||
"uvicorn[standard]>=0.30",
|
||
"pydantic>=2.7",
|
||
"pydantic-settings>=2.4",
|
||
# MySQL backend
|
||
"sqlalchemy[asyncio]>=2.0",
|
||
"aiomysql>=0.2.0",
|
||
"alembic>=1.13",
|
||
# MongoDB backend
|
||
"beanie>=2.0",
|
||
"pymongo>=4.9",
|
||
"cryptography>=50.0.0",
|
||
]
|
||
|
||
[dependency-groups]
|
||
dev = [
|
||
"pytest>=8.0",
|
||
"pytest-asyncio>=0.23",
|
||
"httpx>=0.27",
|
||
"ruff>=0.6",
|
||
]
|
||
|
||
[tool.ruff]
|
||
line-length = 100
|
||
target-version = "py311"
|
||
|
||
[tool.ruff.lint]
|
||
select = ["E", "F", "I", "UP", "B", "ASYNC", "RUF"]
|
||
ignore = [
|
||
"RUF001", "RUF002", "RUF003", # 中文文档字符串里的全角标点是有意的
|
||
]
|
||
|
||
[tool.ruff.lint.per-file-ignores]
|
||
"alembic/env.py" = ["E402", "F401"] # 需要先 fileConfig 再 import 应用模块
|
||
"alembic/versions/*" = ["I001"] # 迁移文件是自动生成物,不整理 import
|
||
"tests/conftest.py" = ["E402"] # 需要先设环境变量再 import app
|
||
|
||
[tool.pytest.ini_options]
|
||
asyncio_mode = "auto"
|
||
testpaths = ["tests"]
|
||
pythonpath = ["."]
|
||
|
||
[tool.uv]
|
||
package = false
|