About python-api-endpoint-creator
A development skill for creating layered FastAPI REST endpoints, aimed at developers building endpoints or domain modules. It scaffolds routers, services, repositories, and tests while prescribing patterns such as async handling and soft deletion.
Key features
- 01Generate Pydantic schemas and SQLAlchemy models
- 02Set up async CRUD repositories and services
- 03Create dependencies and thin routers
- 04Generate httpx AsyncClient tests
- 05Apply soft-delete and response-model rules
Use cases
- 01Create a REST API endpoint from scratch
- 02Add CRUD operations for a domain entity
- 03Build a layered module with tests
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ c0x12c/ ai-toolkit --skill python-api-endpoint-creatorAfter installing, type/python-api-endpoint-creatorin Claude Code to confirm it loaded.
Bundled filescode-patterns.md
Details
From the project READMEPython API Endpoint Creator
Creates complete FastAPI endpoints following strict layered architecture patterns.
When to Use
- Creating a new REST API endpoint from scratch
- Adding CRUD operations for a new domain entity
- Setting up the full stack: Router → Service → Repository → Tests
- Scaffolding a new domain module
Process
- Pydantic Schemas — Create/Update/Response in
schemas.py - SQLAlchemy Model — with SoftDeleteMixin in
models.py - Repository — async CRUD with soft delete in
repository.py - Service — business logic, HTTPException for errors in
service.py - Dependencies —
get_db,get_serviceindependencies.py - Router — thin endpoints, Depends() for everything in
router.py - Tests — httpx AsyncClient tests in
tests/
See code-patterns.md for complete templates for each file.
Architecture
Router (APIRouter) → Service → Repository → Database
↓ ↓ ↓
Depends() Business logic SQLAlchemy
Pydantic schemas HTTPException AsyncSession
Status codes Validation Soft delete
Hard Rules
- POST for all mutations — GET for reads, POST for create/update/delete
- Query params for IDs —
?id=xxx, never path params/{id} - Routers are thin — just delegation, no business logic
- Services raise HTTPException — for expected errors (404, 409, 422)
- Repositories handle soft delete — filter
deleted_at.is_(None)in all queries async deffor all endpoints — unless CPU-bound
Gotchas
-
Forgetting
response_modelmakes your API leak internal fields. Always setresponse_model=YourSchemaon endpoints. Without it, FastAPI serializes the raw return value, which may includehashed_password,deleted_at, or other internal fields from your SQLAlchemy model. -
Depends()creates a new instance per request — not a singleton. If your service holds state, it will be lost between requests. Services should be stateless. If you need shared state, use app state or a cache. -
await db.commit()in the dependency, not in the repository. Theget_dbdependency handles commit/rollback. If you also commit inside the repository, you get double-commit bugs or premature commits before all operations complete. -
422 errors from Pydantic are opaque by default. Override the
RequestValidationErrorhandler to return field-level errors. The default just says "validation error" with no useful detail for the frontend. -
Missing
status_code=201on create endpoints. FastAPI defaults to 200. Explicitly setstatus_code=status.HTTP_201_CREATEDon POST create routes andstatus_code=status.HTTP_204_NO_CONTENTon delete routes.