{"id":"2ad8cd16-a826-4b14-a9b3-9504e3734baa","shortId":"Rtg35y","kind":"skill","title":"python-fastapi","tagline":"Building REST APIs with FastAPI, Pydantic validation, and OpenAPI. Use when creating routes, handling requests, designing endpoints, implementing validation, error responses, pagination, or generating API documentation.","description":"# FastAPI - Modern Python Web APIs\n\nFastAPI is a modern, fast web framework for building APIs with Python, using standard Python type hints. FastAPI automatically validates requests, generates OpenAPI documentation, and provides excellent developer experience.\n\n## Quick Start\n\n### Basic Application\n\n```python\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\n\napp = FastAPI(\n    title=\"My API\",\n    description=\"API for my application\",\n    version=\"1.0.0\",\n)\n\nclass Item(BaseModel):\n    name: str\n    price: float\n\n@app.get(\"/\")\ndef read_root():\n    return {\"message\": \"Hello World\"}\n\n@app.post(\"/items\", response_model=Item)\ndef create_item(item: Item):\n    return item\n```\n\n**Run with:**\n```bash\nuvicorn main:app --reload\n```\n\n## Core Concepts\n\n### Request & Response Models\n\nUse Pydantic models for automatic validation and serialization:\n\n```python\nfrom pydantic import BaseModel, EmailStr, Field\n\nclass CreateUserRequest(BaseModel):\n    email: EmailStr\n    name: str = Field(min_length=1, max_length=100)\n    age: int = Field(ge=18, le=120)\n\nclass UserResponse(BaseModel):\n    id: int\n    email: str\n    name: str\n    model_config = {\"from_attributes\": True}  # Enable ORM mode\n\n@app.post(\"/users\", response_model=UserResponse)\ndef create_user(user: CreateUserRequest):\n    \"\"\"Request validated, response serialized automatically\"\"\"\n    return user\n```\n\nSee `references/validation.md` for detailed validation patterns including custom validators and field constraints.\n\n### Routers for Organization\n\nSplit routes across routers for clean organization:\n\n```python\n# routers/users.py\nfrom fastapi import APIRouter\n\nrouter = APIRouter(prefix=\"/users\", tags=[\"users\"])\n\n@router.get(\"/\")\ndef list_users():\n    ...\n\n@router.post(\"/\")\ndef create_user(user: CreateUserRequest):\n    ...\n\n# main.py\napp.include_router(users.router)\n```\n\n### Dependency Injection\n\nFastAPI's core feature for managing dependencies like database sessions and authentication:\n\n```python\nfrom fastapi import Depends\nfrom sqlalchemy.orm import Session\n\ndef get_db() -> Session:\n    \"\"\"Database session dependency\"\"\"\n    db = SessionLocal()\n    try:\n        yield db\n    finally:\n        db.close()\n\n@app.get(\"/users\")\ndef list_users(db: Session = Depends(get_db)):\n    \"\"\"db automatically injected\"\"\"\n    return db.query(User).all()\n```\n\nSee `references/dependencies.md` for advanced patterns including auth services, scoped dependencies, and dependency classes.\n\n## Error Handling\n\n### HTTP Exceptions\n\n```python\nfrom fastapi import HTTPException\n\n@app.get(\"/users/{user_id}\")\ndef get_user(user_id: int):\n    user = db.get(user_id)\n    if not user:\n        raise HTTPException(status_code=404, detail=\"User not found\")\n    return user\n```\n\n### Custom Exception Handlers\n\n```python\nfrom fastapi import Request\nfrom fastapi.responses import JSONResponse\n\nclass BusinessError(Exception):\n    def __init__(self, message: str):\n        self.message = message\n\n@app.exception_handler(BusinessError)\nasync def business_error_handler(request: Request, exc: BusinessError):\n    return JSONResponse(\n        status_code=400,\n        content={\"error\": exc.message},\n    )\n```\n\n## Project Structure\n\n```\nmy-api/\n├── main.py                   # FastAPI app\n├── routers/                  # Route handlers\n│   ├── users.py\n│   └── products.py\n├── schemas/                  # Pydantic models\n│   ├── users.py\n│   └── products.py\n├── services/                 # Business logic\n│   └── users.py\n├── repositories/             # Data access\n│   └── users.py\n└── dependencies.py           # Dependency injection\n```\n\n## Reference Materials\n\nDetailed patterns for common scenarios:\n\n- **Validation**: `references/validation.md` - Field constraints, custom validators, model validation\n- **Dependencies**: `references/dependencies.md` - Auth services, scoped dependencies, advanced injection patterns\n- **Middleware**: `references/middleware.md` - CORS, custom middleware, request/response processing\n- **API Design**: `references/api-design.md` - REST naming, pagination, OpenAPI customization, status codes\n\n## Best Practices\n\n1. **Use response_model** - Always define explicit response schemas\n2. **Validate inputs** - Use Pydantic models with constraints\n3. **Dependency injection** - Manage sessions, auth, and cross-cutting concerns\n4. **Router organization** - Split routes by resource/domain\n5. **Error handling** - Use HTTP exceptions and custom handlers appropriately\n6. **Type hints** - FastAPI uses them for both validation and documentation","tags":["python","fastapi","atelier","martinffx","agent-skills","agentic-coding","anthropic","claude-code","claude-skills","code-review","codex","codex-skill"],"capabilities":["skill","source-martinffx","skill-python-fastapi","topic-agent-skills","topic-agentic-coding","topic-anthropic","topic-claude-code","topic-claude-skills","topic-code-review","topic-codex","topic-codex-skill","topic-opencode","topic-prompt-engineering","topic-sdd","topic-spec-driven-development"],"categories":["atelier"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/martinffx/atelier/python-fastapi","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add martinffx/atelier","source_repo":"https://github.com/martinffx/atelier","install_from":"skills.sh"}},"qualityScore":"0.461","qualityRationale":"deterministic score 0.46 from registry signals: · indexed on github topic:agent-skills · 23 github stars · SKILL.md body (4,515 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T19:05:23.329Z","embedding":null,"createdAt":"2026-05-10T07:03:12.144Z","updatedAt":"2026-05-18T19:05:23.329Z","lastSeenAt":"2026-05-18T19:05:23.329Z","tsv":"'/items':105 '/users':182,229,284,323 '1':153,464 '1.0.0':88 '100':156 '120':163 '18':161 '2':473 '3':481 '4':492 '400':388 '404':343 '5':499 '6':509 'access':416 'across':215 'advanc':303,442 'age':157 'alway':468 'api':6,28,34,44,81,83,396,452 'apirout':225,227 'app':77,121,399 'app.exception':372 'app.get':96,283,322 'app.include':243 'app.post':104,181 'applic':67,86 'appropri':508 'async':375 'attribut':176 'auth':306,438,486 'authent':259 'automat':53,132,195,294 'basemodel':76,91,140,145,166 'bash':118 'basic':66 'best':462 'build':4,43 'busi':377,411 'businesserror':363,374,383 'class':89,143,164,312,362 'clean':218 'code':342,387,461 'common':426 'concept':124 'concern':491 'config':174 'constraint':209,431,480 'content':389 'cor':447 'core':123,250 'creat':15,110,187,238 'createuserrequest':144,190,241 'cross':489 'cross-cut':488 'custom':205,350,432,448,459,506 'cut':490 'data':415 'databas':256,273 'db':271,276,280,288,292,293 'db.close':282 'db.get':333 'db.query':297 'def':97,109,186,233,237,269,285,326,365,376 'defin':469 'depend':246,254,264,275,290,309,311,419,436,441,482 'dependencies.py':418 'descript':82 'design':19,453 'detail':201,344,423 'develop':62 'document':29,58,519 'email':146,169 'emailstr':141,147 'enabl':178 'endpoint':20 'error':23,313,378,390,500 'exc':382 'exc.message':391 'excel':61 'except':316,351,364,504 'experi':63 'explicit':470 'fast':39 'fastapi':3,8,30,35,52,70,72,78,223,248,262,319,355,398,512 'fastapi.responses':359 'featur':251 'field':142,150,159,208,430 'final':281 'float':95 'found':347 'framework':41 'ge':160 'generat':27,56 'get':270,291,327 'handl':17,314,501 'handler':352,373,379,402,507 'hello':102 'hint':51,511 'http':315,503 'httpexcept':321,340 'id':167,325,330,335 'implement':21 'import':71,75,139,224,263,267,320,356,360 'includ':204,305 'init':366 'inject':247,295,420,443,483 'input':475 'int':158,168,331 'item':90,108,111,112,113,115 'jsonrespons':361,385 'le':162 'length':152,155 'like':255 'list':234,286 'logic':412 'main':120 'main.py':242,397 'manag':253,484 'materi':422 'max':154 'messag':101,368,371 'middlewar':445,449 'min':151 'mode':180 'model':107,127,130,173,184,407,434,467,478 'modern':31,38 'my-api':394 'name':92,148,171,456 'openapi':12,57,458 'organ':212,219,494 'orm':179 'pagin':25,457 'pattern':203,304,424,444 'practic':463 'prefix':228 'price':94 'process':451 'products.py':404,409 'project':392 'provid':60 'pydant':9,74,129,138,406,477 'python':2,32,46,49,68,136,220,260,317,353 'python-fastapi':1 'quick':64 'rais':339 'read':98 'refer':421 'references/api-design.md':454 'references/dependencies.md':301,437 'references/middleware.md':446 'references/validation.md':199,429 'reload':122 'repositori':414 'request':18,55,125,191,357,380,381 'request/response':450 'resource/domain':498 'respons':24,106,126,183,193,466,471 'rest':5,455 'return':100,114,196,296,348,384 'root':99 'rout':16,214,401,496 'router':210,216,226,244,400,493 'router.get':232 'router.post':236 'routers/users.py':221 'run':116 'scenario':427 'schema':405,472 'scope':308,440 'see':198,300 'self':367 'self.message':370 'serial':135,194 'servic':307,410,439 'session':257,268,272,274,289,485 'sessionloc':277 'skill' 'skill-python-fastapi' 'source-martinffx' 'split':213,495 'sqlalchemy.orm':266 'standard':48 'start':65 'status':341,386,460 'str':93,149,170,172,369 'structur':393 'tag':230 'titl':79 'topic-agent-skills' 'topic-agentic-coding' 'topic-anthropic' 'topic-claude-code' 'topic-claude-skills' 'topic-code-review' 'topic-codex' 'topic-codex-skill' 'topic-opencode' 'topic-prompt-engineering' 'topic-sdd' 'topic-spec-driven-development' 'tri':278 'true':177 'type':50,510 'use':13,47,128,465,476,502,513 'user':188,189,197,231,235,239,240,287,298,324,328,329,332,334,338,345,349 'userrespons':165,185 'users.py':403,408,413,417 'users.router':245 'uvicorn':119 'valid':10,22,54,133,192,202,206,428,433,435,474,517 'version':87 'web':33,40 'world':103 'yield':279","prices":[{"id":"53c150ec-edca-44cc-a0c6-0116d080169b","listingId":"2ad8cd16-a826-4b14-a9b3-9504e3734baa","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"martinffx","category":"atelier","install_from":"skills.sh"},"createdAt":"2026-05-10T07:03:12.144Z"}],"sources":[{"listingId":"2ad8cd16-a826-4b14-a9b3-9504e3734baa","source":"github","sourceId":"martinffx/atelier/python-fastapi","sourceUrl":"https://github.com/martinffx/atelier/tree/main/skills/python-fastapi","isPrimary":false,"firstSeenAt":"2026-05-10T07:03:12.144Z","lastSeenAt":"2026-05-18T19:05:23.329Z"}],"details":{"listingId":"2ad8cd16-a826-4b14-a9b3-9504e3734baa","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"martinffx","slug":"python-fastapi","github":{"repo":"martinffx/atelier","stars":23,"topics":["agent-skills","agentic-coding","anthropic","claude-code","claude-skills","code-review","codex","codex-skill","opencode","prompt-engineering","sdd","spec-driven-development"],"license":"mit","html_url":"https://github.com/martinffx/atelier","pushed_at":"2026-05-18T06:56:45Z","description":"An atelier for Opencode, Claude Code, and other coding agents: spec-driven workflows, deep thinking, and code quality.","skill_md_sha":"63fb5ca27c00d1483ce45cacbf1a8f506b0d225c","skill_md_path":"skills/python-fastapi/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/martinffx/atelier/tree/main/skills/python-fastapi"},"layout":"multi","source":"github","category":"atelier","frontmatter":{"name":"python-fastapi","description":"Building REST APIs with FastAPI, Pydantic validation, and OpenAPI. Use when creating routes, handling requests, designing endpoints, implementing validation, error responses, pagination, or generating API documentation."},"skills_sh_url":"https://skills.sh/martinffx/atelier/python-fastapi"},"updatedAt":"2026-05-18T19:05:23.329Z"}}