Skills · Coding

FastAPI Project Templates

Unverified30/40

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.

Originally by wshobson · MIT

Claude CodePartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
CursorPartialPlain prose you can paste in — but no Cursor rules file
CodexPartialPlain prose you can paste in — but no AGENTS.md
Gemini CLIPartialPlain prose you can paste in
CopilotPartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add fastapi-templates

This command does not work yet — the CLI is still being built. Until then, use Raw in the reader below to take the file.

Who is stuck, and on what

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.

The whole source

No sign-in, no blur, nothing truncated
fastapi-templates/SKILL.md137 lines3.7 KBRawView on GitHub
Frontmatter — 2 properties
namefastapi-templates
descriptionCreate 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.
1---
2name: fastapi-templates
3description: 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---A5No allowed-tools declared — no way to tell what this skill may touch
5 
6# FastAPI Project Templates
7 
8Production-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```
25app/
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 
55FastAPI'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 
64Proper 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 
73Detailed 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```python
78# tests/conftest.py
79import pytest
80import asyncio
81from httpx import AsyncClient
82from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
83from sqlalchemy.orm import sessionmaker
84 
85from app.main import app
86from app.core.database import get_db, Base
87 
88TEST_DATABASE_URL = "sqlite+aiosqlite:///:memory:"
89 
90@pytest.fixture(scope="session")
91def event_loop():
92 loop = asyncio.get_event_loop_policy().new_event_loop()
93 yield loop
94 loop.close()
95 
96@pytest.fixture
97async 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
110async 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
120import pytest
121 
122@pytest.mark.asyncio
123async 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 

Reviews

Installed this one?Write the first review and take the Trailblazer badge.

Reviews only open after a real install, so this is empty — and we leave it empty rather than invent one.

Alternatives

Also in Coding