Scaffold FastAPI with async endpoints and auto-docs
✓Works with OpenClaudeYou are a Python backend developer. The user wants to scaffold a FastAPI application with async endpoints and auto-generated API documentation.
What to check first
- Run
python --versionto ensure Python 3.7+ is installed - Check if
pipis available withpip --version - Verify no existing FastAPI project in the current directory
Steps
- Create a new project directory and initialize a virtual environment with
python -m venv venv - Activate the virtual environment:
source venv/bin/activate(on Windows:venv\Scripts\activate) - Install FastAPI and Uvicorn with
pip install fastapi uvicorn[standard] - Create
main.pyand importFastAPIfrom the fastapi module - Instantiate a FastAPI app with
app = FastAPI(title="Your API", version="1.0.0") - Define async route handlers using
@app.get(),@app.post(), etc. decorators with async def functions - Add Pydantic BaseModel classes for request/response validation with type hints
- Run the development server with
uvicorn main:app --reloadto enable hot-reload and auto-docs at/docs
Code
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import Optional
import uvicorn
app = FastAPI(
title="FastAPI App",
description="A scalable async API with auto-generated documentation",
version="1.0.0"
)
class Item(BaseModel):
id: int
name: str
description: Optional[str] = None
price: float
class ItemUpdate(BaseModel):
name: Optional[str] = None
description: Optional[str] = None
price: Optional[float] = None
items_db = {}
@app.get("/", tags=["Root"])
async def read_root():
"""Root endpoint that returns a welcome message."""
return {"message": "Welcome to FastAPI"}
@app.get("/items/{item_id}", tags=["Items"])
async def get_item(item_id: int):
"""Fetch a single item by ID."""
if item_id not in items_db:
raise HTTPException(status_code=404, detail="Item not found")
return items_db[item_id]
@app.post("/items", tags=["Items"], response_model=Item)
async def create_item(item: Item):
"""Create a new item with validation."""
items_db[item.id] = item
return item
@app.put("/items/{item_id}", tags=["Items"])
async def update_item(item_id: int, item_update: ItemUpdate):
"""Update an existing item partially."""
if item_id not in items_db:
raise HTTPException(status_code=404, detail="Item not found")
existing =
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Python Skills
Other Claude Code skills in the same category — free to download.
Django Setup
Scaffold Django project with models, views, and URLs
Flask Setup
Scaffold Flask application with blueprints and extensions
Pytest Setup
Configure pytest with fixtures, plugins, and coverage
Python Venv
Set up Python virtual environments and dependency management
Poetry Setup
Set up Poetry for Python dependency and package management
Python Typing
Add comprehensive type hints and mypy configuration to Python code
Django REST Framework
Set up Django REST Framework with serializers and viewsets
Python Logging
Configure structured logging for Python applications
Want a Python skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.