Create production-ready FastAPI projects with async patterns
FastAPI Project Templates

Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects.
--- name: fastapi-templates description: Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects. --- # FastAPI Project Templates Production-ready FastAPI project structures with async patterns, dependency injection, middleware, and best practices for building high-performance APIs. ## When to Use This Skill - Starting new FastAPI projects from scratch - Implementing async REST APIs with Python - Building high-performance web services and microservices - Creating async applications with PostgreSQL, MongoDB - Setting up API projects with proper structure and testing ## Core Concepts
Overview
Production-ready FastAPI project structures with async patterns, dependency injection, middleware, and best practices for building high-performance APIs.
Manual install (npx, ZIP)
npx skills add wshobson/agents --skill fastapi-templates -g -a claude-codemkdir -p ~/.claude/skills && curl -sL https://codeload.github.com/wshobson/agents/tar.gz/4236bb91f839 \
| tar -xz -C ~/.claude/skills --strip-components=4 agents-4236bb91f839/plugins/api-scaffolding/skills/fastapi-templatesNew-Item -ItemType Directory -Force "$HOME\.claude\skills" | Out-Null; Invoke-WebRequest "https://m.agentalley.io/zip/88deb6991f3d4a0b920f/fastapi-templates.zip" -OutFile "$env:TEMP\fastapi-templates.zip"; Expand-Archive "$env:TEMP\fastapi-templates.zip" -DestinationPath "$HOME\.claude\skills" -ForceConnects with Agent Alley MCP · agentalley.io/mcp
Files included
SKILL.md3.7 KBreferences/1 file · 11.4 KB
Read the files here
Show the full text137 lines
FastAPI Project Templates
Production-ready FastAPI project structures with async patterns, dependency injection, middleware, and best practices for building high-performance APIs.
When to Use This Skill
- Starting new FastAPI projects from scratch
- Implementing async REST APIs with Python
- Building high-performance web services and microservices
- Creating async applications with PostgreSQL, MongoDB
- Setting up API projects with proper structure and testing
Core Concepts
1. Project Structure
Recommended Layout:
app/
├── api/ # API routes
│ ├── v1/
│ │ ├── endpoints/
│ │ │ ├── users.py
│ │ │ ├── auth.py
│ │ │ └── items.py
│ │ └── router.py
│ └── dependencies.py # Shared dependencies
├── core/ # Core configuration
│ ├── config.py
│ ├── security.py
│ └── database.py
├── models/ # Database models
│ ├── user.py
│ └── item.py
├── schemas/ # Pydantic schemas
│ ├── user.py
│ └── item.py
├── services/ # Business logic
│ ├── user_service.py
│ └── auth_service.py
├── repositories/ # Data access
│ ├── user_repository.py
│ └── item_repository.py
└── main.py # Application entry
2. Dependency Injection
FastAPI's built-in DI system using Depends:
- Database session management
- Authentication/authorization
- Shared business logic
- Configuration injection
3. Async Patterns
Proper async/await usage:
- Async route handlers
- Async database operations
- Async background tasks
- Async middleware
Detailed worked examples and patterns
Detailed sections (starting with ## Implementation Patterns) live in references/details.md. Read that file when the navigation summary above is insufficient.
Testing
# tests/conftest.py
import pytest
import asyncio
from httpx import AsyncClient
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from app.main import app
from app.core.database import get_db, Base
TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
@pytest.fixture(scope="session")
def event_loop():
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()
@pytest.fixture
async def db_session():
engine = create_async_engine(TEST_DATABASE_URL, echo=True)
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
AsyncSessionLocal = sessionmaker(
engine, class_=AsyncSession, expire_on_commit=False
)
async with AsyncSessionLocal() as session:
yield session
@pytest.fixture
async def client(db_session):
async def override_get_db():
yield db_session
app.dependency_overrides[get_db] = override_get_db
async with AsyncClient(app=app, base_url="http://test") as client:
yield client
# tests/test_users.py
import pytest
@pytest.mark.asyncio
async def test_create_user(client):
response = await client.post(
"/api/v1/users/",
json={
"email": "[email protected]",
"password": "testpass123",
"name": "Test User"
}
)
assert response.status_code == 201
data = response.json()
assert data["email"] == "[email protected]"
assert "id" in data
| 1 | |
| 2 | name fastapi-templates |
| 3 | description Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling. Use when building new FastAPI applications or setting up backend API projects. |
| 4 | |
| 5 | |
| 6 | # FastAPI Project Templates |
| 7 | |
| 8 | Production-ready FastAPI project structures with async patterns, dependency injection, middleware, and best practices for building high-performance APIs. |
| 9 | |
| 10 | ## When to Use This Skill |
| 11 | |
| 12 | Starting new FastAPI projects from scratch |
| 13 | Implementing async REST APIs with Python |
| 14 | Building high-performance web services and microservices |
| 15 | Creating async applications with PostgreSQL, MongoDB |
| 16 | Setting up API projects with proper structure and testing |
| 17 | |
| 18 | ## Core Concepts |
| 19 | |
| 20 | ### 1. Project Structure |
| 21 | |
| 22 | **Recommended Layout:** |
| 23 | |
| 24 | |
| 25 | app/ |
| 26 | ├── api/ # API routes |
| 27 | │ ├── v1/ |
| 28 | │ │ ├── endpoints/ |
| 29 | │ │ │ ├── users.py |
| 30 | │ │ │ ├── auth.py |
| 31 | │ │ │ └── items.py |
| 32 | │ │ └── router.py |
| 33 | │ └── dependencies.py # Shared dependencies |
| 34 | ├── core/ # Core configuration |
| 35 | │ ├── config.py |
| 36 | │ ├── security.py |
| 37 | │ └── database.py |
| 38 | ├── models/ # Database models |
| 39 | │ ├── user.py |
| 40 | │ └── item.py |
| 41 | ├── schemas/ # Pydantic schemas |
| 42 | │ ├── user.py |
| 43 | │ └── item.py |
| 44 | ├── services/ # Business logic |
| 45 | │ ├── user_service.py |
| 46 | │ └── auth_service.py |
| 47 | ├── repositories/ # Data access |
| 48 | │ ├── user_repository.py |
| 49 | │ └── item_repository.py |
| 50 | └── main.py # Application entry |
| 51 | |
| 52 | |
| 53 | ### 2. Dependency Injection |
| 54 | |
| 55 | FastAPI's built-in DI system using `Depends`: |
| 56 | |
| 57 | Database session management |
| 58 | Authentication/authorization |
| 59 | Shared business logic |
| 60 | Configuration injection |
| 61 | |
| 62 | ### 3. Async Patterns |
| 63 | |
| 64 | Proper async/await usage: |
| 65 | |
| 66 | Async route handlers |
| 67 | Async database operations |
| 68 | Async background tasks |
| 69 | Async middleware |
| 70 | |
| 71 | ## Detailed worked examples and patterns |
| 72 | |
| 73 | Detailed sections (starting with `## Implementation Patterns`) live in `references/details.md`. Read that file when the navigation summary above is insufficient. |
| 74 | |
| 75 | ## Testing |
| 76 | |
| 77 | |
| 78 | # tests/conftest.py |
| 79 | import pytest |
| 80 | import asyncio |
| 81 | from httpx import AsyncClient |
| 82 | from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession |
| 83 | from sqlalchemy.orm import sessionmaker |
| 84 | |
| 85 | from app.main import app |
| 86 | from app.core.database import get_db, Base |
| 87 | |
| 88 | TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:" |
| 89 | |
| 90 | @pytest.fixture(scope="session") |
| 91 | def event_loop(): |
| 92 | loop = asyncio.get_event_loop_policy().new_event_loop() |
| 93 | yield loop |
| 94 | loop.close() |
| 95 | |
| 96 | @pytest.fixture |
| 97 | async def db_session(): |
| 98 | engine = create_async_engine(TEST_DATABASE_URL, echo=True) |
| 99 | async with engine.begin() as conn: |
| 100 | await conn.run_sync(Base.metadata.create_all) |
| 101 | |
| 102 | AsyncSessionLocal = sessionmaker( |
| 103 | engine, class_=AsyncSession, expire_on_commit=False |
| 104 | ) |
| 105 | |
| 106 | async with AsyncSessionLocal() as session: |
| 107 | yield session |
| 108 | |
| 109 | @pytest.fixture |
| 110 | async def client(db_session): |
| 111 | async def override_get_db(): |
| 112 | yield db_session |
| 113 | |
| 114 | app.dependency_overrides[get_db] = override_get_db |
| 115 | |
| 116 | async with AsyncClient(app=app, base_url="http://test") as client: |
| 117 | yield client |
| 118 | |
| 119 | # tests/test_users.py |
| 120 | import pytest |
| 121 | |
| 122 | @pytest.mark.asyncio |
| 123 | async def test_create_user(client): |
| 124 | response = await client.post( |
| 125 | "/api/v1/users/", |
| 126 | json={ |
| 127 | "email": "[email protected]", |
| 128 | "password": "testpass123", |
| 129 | "name": "Test User" |
| 130 | } |
| 131 | ) |
| 132 | assert response.status_code == 201 |
| 133 | data = response.json() |
| 134 | assert data["email"] == "[email protected]" |
| 135 | assert "id" in data |
| 136 | |
| 137 |
Details
- Updated
- Sep 21, 2026
- License
- MIT
- Stars on the repo
- ★ 39,857
- Checked
- Source
- wshobson/agents ↗
- Creator
- wshobson · 179 listings
Similar skills
See all →
SkillGuides stable API and interface design
MCPPulls up-to-date, version-specific library docsContext7
SkillFetch up-to-date documentation and code examples for anyContext7 Documentation Lookup
SkillHow to use the Adaptyv Bio Foundry API and Python SDK
SkillMaster C/.NET backend development patterns for building
SkillGuides the usage of Gemini Interactions API on GeminiGemini Interactions API SkillMore from wshobson
SkillMaster C/.NET backend development patterns for building
SkillImplement WCAG 2.2 compliant interfaces with mobileAccessibility compliance
SkillMaster Material Design 3 and Jetpack Compose patternsAndroid Mobile Design
SkillMigrate from AngularJS to Angular using hybrid modeAngular migration
SkillUnderstand anti-reversing, obfuscationAnti reversing techniques
SkillBuild production Apache Airflow DAGs with best practicesApache Airflow DAG Patterns