技能 fastapi-app
📦
fastapi-app
低风险 ⚡
包含脚本📁
文件系统访问
建構 FastAPI 後端應用程式
FastAPI 技能可幫助開發人員建立穩健的 Python Web API,具備自動文件生成、驗證和依賴注入功能。本技能提供專家指導,協助建構生產就緒的 FastAPI 應用程式,包括路由處理器、CORS 配置和 Pydantic v2 模型。
支持: Claude Codex Code(CC)
1
下载技能 ZIP
2
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
3
开启并开始使用
测试它
正在使用“fastapi-app”。 Create a FastAPI app with student endpoints
预期结果:
- Generated main.py with FastAPI initialization, CORS configuration, and lifespan events
- Created routers/students.py with CRUD endpoints and authentication dependencies
- Added dependencies/database.py for async SQLAlchemy session management
- Generated Pydantic schemas in schemas/student.py with validation rules
正在使用“fastapi-app”。 Add JWT authentication to the API
预期结果:
- Created dependencies/auth.py with JWT token creation and validation
- Implemented get_current_user dependency using HTTPBearer scheme
- Added role-based access control with get_admin_user dependency
- Configured environment variable loading for JWT_SECRET_KEY
安全审计
低风险v6 • 1/21/2026
All static findings are false positives. The skill provides legitimate FastAPI development guidance. Pattern detections (C2 keywords, weak crypto, command execution) are misidentifications of standard code examples and documentation URLs in the SKILL.md file.
2
已扫描文件
1,766
分析行数
3
发现项
6
审计总数
低风险问题 (1)
Documentation references detected as patterns
Static scanner flagged documentation URLs (fastapi.tiangolo.com, docs.pydantic.dev) as network targets. These are legitimate documentation references in the SKILL.md References section.
风险因素
⚡ 包含脚本 (1)
📁 文件系统访问 (1)
审计者: claude 查看审计历史 →
质量评分
38
架构
100
可维护性
87
内容
20
社区
88
安全
87
规范符合性
你能构建什么
後端 API 開發
為學生管理、費用追蹤或出勤系統建立新的 FastAPI 端點,配備適當的認證和驗證功能。
API 安全性實作
為現有的 FastAPI 應用程式新增 JWT 認證、角色型存取控制和安全的 CORS 配置。
資料驗證設定
為 API 請求和回應結構定義具有欄位驗證、電子郵件模式和 ORM 相容性的 Pydantic v2 模型。
试试这些提示
建立 FastAPI 應用程式結構
Create a FastAPI application with lifespan events, CORS middleware allowing localhost:3000 and localhost:5173, and include routers for /api/v1/auth, /api/v1/students, and /api/v1/fees with proper tags and dependencies.
建構 CRUD 端點
Generate APIRouter with GET, POST, PUT, and DELETE endpoints for a student resource. Include pagination with skip/limit, response models using Pydantic, and dependency injection for database session and current user authentication.
新增 JWT 認證
Create dependencies for JWT authentication including create_access_token function, get_current_user dependency with HTTPBearer, and get_admin_user for role-based access control. Use HS256 algorithm and environment variables for secrets.
定義 Pydantic 結構
Create Pydantic v2 models for a student entity including StudentBase, StudentCreate, StudentUpdate, and StudentResponse. Include Field validators for name length, EmailStr for email, and ConfigDict for ORM compatibility.
最佳实践
- 使用具有內容管理器的非同步 SQLAlchemy 會話,以防止連線洩漏
- 始終為 API 回應返回適當的 HTTP 狀態碼(200、201、204、400、401、403、404)
- 使用 os.getenv() 將機密資訊儲存在環境變數中,並為開發環境設定合理的預設值
避免
- 不要在原始碼檔案中直接硬編碼機密資訊或密碼
- 不要在非同步 FastAPI 路由處理器中使用同步資料庫呼叫
- 不要停用 Pydantic 驗證或在端點中省略回應模型
常见问题
本技能支援哪些 FastAPI 功能?
本技能支援 FastAPI 應用程式初始化、APIRouter 模組化路由、Depends() 依賴注入、CORS 中介軟體配置、Pydantic v2 模型和非同步 SQLAlchemy 整合。
本技能會產生認證程式碼嗎?
是的,它使用 HS256 演算法透過 python-jose 產生 JWT 認證,包括令牌建立、驗證依賴和角色型存取控制裝飾器。
本技能可以建立資料庫模型嗎?
本技能提供 SQLAlchemy 非同步引擎設定和會話管理的指導。對於資料庫模型,它會產生 Pydantic 結構來進行請求/回應驗證,而非 ORM 模型定義。
Pydantic v2 支援哪些驗證功能?
Pydantic v2 支援用於最小/最大長度的 Field 驗證器、用於電子郵件驗證的 EmailStr、使用正規表示法的模式比對、用於數值的 gt/lt,以及用於 ORM 相容性的 ConfigDict。
CORS 配置如何運作?
本技能使用 allow_origins 設定特定前端 URL 的 CORSMiddleware,使用 allow_credentials 處理 Cookie/認證標頭,並使用 allow_methods/allow_headers 處理跨來源請求。
本技能是否處理部署或 Docker 相關事項?
不,本技能專注於應用程式程式碼產生。對於部署,它提供基本的 uvicorn 執行指令,但不會產生 Dockerfiles、docker-compose 或 CI/CD 配置。