py-web
Installation
SKILL.md
Python Web/API 工程
目標與邊界
用此 skill 建立輸入經驗證、權限清楚、transaction 安全、資源可關閉且可觀測的 Web 服務。
若任務主要是自訂 TCP/UDP 協議,使用 py-network;若主要是 LLM/RAG orchestration,以 py-ai 為主、py-web 負責 API 邊界。
執行流程
- 定義 API 契約:method、path、request/response schema、status、錯誤、auth、idempotency 與版本策略。
- 盤點信任邊界:browser、mobile、service-to-service、proxy、tenant、上傳檔案與外部 URL。
- 分離層次:route 解析 HTTP,service 執行 use case,repository/adapter 處理 I/O。
- 設計 transaction:每個 use case 的 commit/rollback 邊界清楚,不讓 repository 自行 commit。
- 建立 lifecycle resource:DB engine、HTTP client、cache、model 與 worker 在 lifespan 建立/關閉。
- 加入安全控制:認證、授權、CORS allowlist、CSRF/SSRF、rate limit、body limit 與秘密管理。
- 處理故障:timeout、取消、retry、duplicate request、partial failure 與 graceful shutdown。
- 測試與觀測:unit、integration、contract、trace、metrics、structured logs 與 deployment smoke test。