Expert scaffolding for Python FastAPI projects. Enforces the use of Pydantic V2, Async Database patterns, and Dependency Injection.
When scaffolding a new API:
app/
├── api/
│ ├── v1/
│ │ ├── endpoints/
│ │ └── api.py
│ └── deps.py
├── core/ (config, security)
├── db/ (session, base_class)
├── models/ (SQLAlchemy models)
├── schemas/ (Pydantic models)
├── services/ (Business logic)
└── main.py
model_config and Field.
from pydantic import BaseModel, ConfigDict, Field
class UserCreate(BaseModel):
model_config = ConfigDict(from_attributes=True)
username: str = Field(..., min_length=3)
email: str
response_model in route decorators to prevent data leaks.Depends.
@router.post("/", response_model=ShowUser)
async def create_user(
user_in: UserCreate,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_active_user)
):
return await UserService.create(db, user_in)
AsyncSession and select.
result = await db.execute(select(User).where(User.id == user_id))
user = result.scalars().first()
alembic for migrations.HTTPException with clear detail messages.main.py for global errors.