ComeOnOliver/skillshub / skills/aiskillstore/marketplace/0xdarkmatter/python-fastapi-patterns
python-fastapi-patterns
VerifiedFastAPI web framework patterns. Triggers on: fastapi, api endpoint, dependency injection, pydantic model, openapi, swagger, starlette, async api, rest api, uvicorn.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.2 KB |
| assets/fastapi-template.py | script | 4.9 KB |
| references/background-tasks.md | markdown | 8.4 KB |
| references/dependency-injection.md | markdown | 7.2 KB |
| references/middleware-patterns.md | markdown | 8.8 KB |
| references/validation-serialization.md | markdown | 7.3 KB |
| scripts/scaffold-api.sh | script | 4.1 KB |
| skill-report.json | config | 11.8 KB |
skill-report.json
View on GitHub{
"schema_version": "2.0",
"meta": {
"generated_at": "2026-01-16T14:11:02.125Z",
"slug": "0xdarkmatter-python-fastapi-patterns",
"source_url": "https://github.com/0xDarkMatter/claude-mods/tree/main/skills/python-fastapi-patterns",
"source_ref": "main",
"model": "claude",
"analysis_version": "3.0.0",
"source_type": "community",
"content_hash": "a3cfdab053c34f441d99d664a12d20025e0855c85810b23c8a5d0ea136d45b13",
"tree_hash": "7d6c17f8b7687579dd664c7edcba06f261647391623660712ec46a306b71541a"
},
"skill": {
"name": "python-fastapi-patterns",
"description": "FastAPI web framework patterns. Triggers on: fastapi, api endpoint, dependency injection, pydantic model, openapi, swagger, starlette, async api, rest api, uvicorn.",
"summary": "FastAPI web framework patterns. Triggers on: fastapi, api endpoint, dependency injection, pydantic m...",
"icon": "🐍",
"version": "1.0.0",
"author": "0xDarkMatter",
"license": "MIT",
"category": "coding",
"tags": [
"fastapi",
"python",
"api",
"web",
"async"
],
"supported_tools": [
"claude",
"codex",
"claude-code"
],
"risk_factors": [
"scripts",
"env_access"
]
},
"security_audit": {
"risk_level": "low",
"is_blocked": false,
"safe_to_publish": true,
"summary": "This is a documentation and code generation skill containing educational FastAPI patterns. The bash script generates boilerplate code without executing dangerous operations. All static findings are false positives: environment access patterns use standard pydantic-settings, shell backticks are markdown code fences, and cryptographic alerts are misidentified patterns. No malicious behavior detected.",
"risk_factor_evidence": [
{
"factor": "scripts",
"evidence": [
{
"file": "scripts/scaffold-api.sh",
"line_start": 1,
"line_end": 122
}
]
},
{
"factor": "env_access",
"evidence": [
{
"file": "assets/fastapi-template.py",
"line_start": 23,
"line_end": 32
}
]
}
],
"critical_findings": [],
"high_findings": [],
"medium_findings": [],
"low_findings": [
{
"title": "Bash script for code generation",
"description": "scripts/scaffold-api.sh generates FastAPI boilerplate using standard string manipulation and heredoc. Takes resource name argument, outputs code templates to stdout. No file writes, network calls, or credential access.",
"locations": [
{
"file": "scripts/scaffold-api.sh",
"line_start": 1,
"line_end": 122
}
]
},
{
"title": "Environment variable configuration",
"description": "fastapi-template.py uses pydantic-settings for configuration management. This is legitimate 12-factor app pattern where developers explicitly provide their own .env file.",
"locations": [
{
"file": "assets/fastapi-template.py",
"line_start": 23,
"line_end": 32
}
]
}
],
"dangerous_patterns": [],
"files_scanned": 8,
"total_lines": 2073,
"audit_model": "claude",
"audited_at": "2026-01-16T14:11:02.125Z"
},
"content": {
"user_title": "Build REST APIs with FastAPI patterns",
"value_statement": "FastAPI is a modern Python web framework for building APIs. This skill provides ready-to-use patterns for dependency injection, validation, middleware, and background tasks. Developers can quickly implement production-ready APIs without searching through documentation.",
"seo_keywords": [
"FastAPI patterns",
"Python API development",
"FastAPI tutorial",
"REST API Python",
"FastAPI dependency injection",
"Pydantic validation",
"API design patterns",
"async Python API",
"Claude Code",
"Codex"
],
"actual_capabilities": [
"Create FastAPI applications with lifespan management for startup and shutdown",
"Define Pydantic models with field validation, custom validators, and serialization",
"Implement dependency injection for databases, caches, and authentication",
"Add middleware for logging, CORS, security headers, and rate limiting",
"Handle background tasks with Celery, APScheduler, and Redis queues",
"Generate CRUD endpoint boilerplate using the scaffold script"
],
"limitations": [
"Does not include database ORM integration code",
"No built-in authentication implementation",
"Requires separate setup for production deployment",
"Background task examples use placeholder functions"
],
"use_cases": [
{
"target_user": "Backend developers",
"title": "Build production REST APIs",
"description": "Create REST APIs with proven patterns for routing, validation, error handling, and async processing"
},
{
"target_user": "Full-stack developers",
"title": "Generate API boilerplate",
"description": "Quickly scaffold CRUD endpoints for new resources using the scaffold-api.sh script"
},
{
"target_user": "Python learners",
"title": "Learn FastAPI patterns",
"description": "Understand dependency injection, middleware chains, and async patterns through examples"
}
],
"prompt_templates": [
{
"title": "Basic API setup",
"scenario": "Creating a new FastAPI application",
"prompt": "Create a FastAPI application with lifespan management for database and cache startup and shutdown"
},
{
"title": "Pydantic models",
"scenario": "Defining request/response models",
"prompt": "Create a Pydantic model for user registration with email validation, password strength checks, and confirm password matching"
},
{
"title": "Dependency injection",
"scenario": "Implementing database and auth dependencies",
"prompt": "Set up dependency injection for an async database session and a JWT-authenticated current user"
},
{
"title": "Middleware chain",
"scenario": "Adding security and logging middleware",
"prompt": "Add middleware for request logging, security headers, and rate limiting to a FastAPI app"
}
],
"output_examples": [
{
"input": "Create a FastAPI endpoint that creates a user with email validation",
"output": [
"from pydantic import BaseModel, EmailStr, Field",
"from fastapi import FastAPI, HTTPException, status",
"from datetime import datetime",
"",
"class UserCreate(BaseModel):",
" name: str = Field(..., min_length=1, max_length=100)",
" email: EmailStr",
" age: int = Field(..., ge=18, le=120)",
"",
"class UserResponse(BaseModel):",
" id: int",
" name: str",
" email: EmailStr",
" created_at: datetime",
" model_config = {'from_attributes': True}",
"",
"@app.post('/users', response_model=UserResponse, status_code=status.HTTP_201_CREATED)",
"async def create_user(user: UserCreate):",
" db_user = await create_user_in_db(user)",
" return db_user"
]
},
{
"input": "Add CORS middleware to allow requests from my frontend at localhost:3000",
"output": [
"from fastapi.middleware.cors import CORSMiddleware",
"",
"app.add_middleware(",
" CORSMiddleware,",
" allow_origins=['http://localhost:3000'],",
" allow_credentials=True,",
" allow_methods=['*'],",
" allow_headers=['*'],",
")"
]
},
{
"input": "Create a dependency that provides a database session for each request",
"output": [
"from fastapi import Depends, FastAPI",
"from typing import Annotated",
"",
"async def get_db():",
" async with AsyncSessionLocal() as session:",
" try:",
" yield session",
" finally:",
" await session.close()",
"",
"DB = Annotated[AsyncSession, Depends(get_db)]",
"",
"@app.get('/items')",
"async def list_items(db: DB):",
" return await db.execute(select(Item))"
]
}
],
"best_practices": [
"Use Pydantic models for all request validation and response serialization to ensure type safety",
"Implement dependency injection for shared resources like databases, caches, and authentication",
"Add middleware early in the stack for CORS, security headers, and request logging"
],
"anti_patterns": [
"Do not use bare Exception handlers that expose internal error details to clients",
"Avoid hardcoding credentials or API keys in source code - use environment variables",
"Do not skip validation by using arbitrary JSON response types instead of Pydantic models"
],
"faq": [
{
"question": "What Python version is required?",
"answer": "FastAPI 0.100+ requires Python 3.10 or higher with Pydantic v2 support"
},
{
"question": "Does this skill handle database connections?",
"answer": "Patterns show async database session setup via dependency injection but require your own ORM integration"
},
{
"question": "Can I use this with SQLAlchemy?",
"answer": "Yes. The dependency injection patterns work with any async database library including SQLAlchemy async"
},
{
"question": "Is the data I process secure?",
"answer": "This skill only provides patterns. All data processing happens in your application code with full control"
},
{
"question": "How do I debug validation errors?",
"answer": "Use RequestValidationError exception handler to format validation error details with field locations"
},
{
"question": "How is this different from Flask or Django?",
"answer": "FastAPI provides automatic OpenAPI docs, native async support, and type validation without Flask's manual request parsing"
}
]
},
"file_structure": [
{
"name": "assets",
"type": "dir",
"path": "assets",
"children": [
{
"name": "fastapi-template.py",
"type": "file",
"path": "assets/fastapi-template.py",
"lines": 181
}
]
},
{
"name": "references",
"type": "dir",
"path": "references",
"children": [
{
"name": "background-tasks.md",
"type": "file",
"path": "references/background-tasks.md",
"lines": 325
},
{
"name": "dependency-injection.md",
"type": "file",
"path": "references/dependency-injection.md",
"lines": 302
},
{
"name": "middleware-patterns.md",
"type": "file",
"path": "references/middleware-patterns.md",
"lines": 322
},
{
"name": "validation-serialization.md",
"type": "file",
"path": "references/validation-serialization.md",
"lines": 321
}
]
},
{
"name": "scripts",
"type": "dir",
"path": "scripts",
"children": [
{
"name": "scaffold-api.sh",
"type": "file",
"path": "scripts/scaffold-api.sh",
"lines": 123
}
]
},
{
"name": "SKILL.md",
"type": "file",
"path": "SKILL.md",
"lines": 207
}
]
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |