fastapi-templates
π―SkillHelps you set up a new Python backend, the server part that apps talk to, using the FastAPI framework. It gives a tidy folder layout, database setup, login handling, error handling and ready-made tests.
Installation
npx skills add wshobson/agents --skill fastapi-templatesRun it in a terminal; it asks which AI coding tools to install it for (Claude Code, Codex, Cursor and more).
Uses skills.sh Β· Node.js 22.20+
After installing
Ask for related work and the agent uses it on its own, or call it yourself.
/fastapi-templatesInstall by hand
Copy the whole skill folder from GitHub to the place below. Copying only SKILL.md can leave out files the skill uses.
Open the skill folder β- This project
.claude/skills/fastapi-templates/ - All projects
~/.claude/skills/fastapi-templates/
These paths are for Claude Code. For other tools, the command above puts it in the right place.
What this skill does
Overview
FastAPI is a popular Python tool for building web APIs, the server addresses that apps send requests to. This skill gives a recommended project layout and coding patterns that are ready for real users. It also lists the needed packages and shows how to write tests.
Key Features
- Get a clear folder layout that separates routes, database models, business logic and data access.
- Share common setup, like database connections and login checks, through FastAPI's
Dependsfeature. - Use async code, which lets the server handle many requests without waiting on each one.
- Connect your app to PostgreSQL or MongoDB databases.
- Run tests against a temporary SQLite database that lives only in memory.
Who is this for?
It is for Python developers starting a new backend or microservice, which is a small service that does one job. It helps if you want a solid structure from day one instead of reorganizing later.
Summarized by AI from this skill's SKILL.md. Suggest a better one
SKILL.md
View on GitHub β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
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
4. Dependencies
The packages the examples import:
# requirements.txt
fastapi
uvicorn[standard]
pydantic-settings
sqlalchemy[asyncio]>=2.0 # DeclarativeBase; [asyncio] installs greenlet for the async engine
asyncpg # PostgreSQL driver: postgresql+asyncpg://...
PyJWT
pwdlib[argon2]
python-multipart # only for a login route that uses OAuth2PasswordRequestForm
# requirements-dev.txt
pytest
pytest-asyncio
httpx
aiosqlite # test database: sqlite+aiosqlite:///:memory:
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_asyncio
from httpx import ASGITransport, 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:"
# Async fixtures need pytest_asyncio.fixture in pytest-asyncio's default strict mode
@pytest_asyncio.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
await engine.dispose()
@pytest_asyncio.fixture
async def client(db_session):
async def override_get_db():
yield db_session
app.dependency_overrides[get_db] = override_get_db
# httpx 0.28 removed AsyncClient(app=...); use an ASGI transport
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
yield client
app.dependency_overrides.clear()
# tests/test_users.py
import pytest
@pytest.mark.asyncio
async def test_create_user(client):
response = await client.post(
"/api/v1/users/",
json={
"email": "test@example.com",
"password": "testpass123",
"name": "Test User"
}
)
assert response.status_code == 201
data = response.json()
assert data["email"] == "test@example.com"
assert "id" in data
More from this repository10
Helps you build a consistent look for your app with Tailwind CSS v4. It sets up shared colors, sizes, dark mode and reusable components so every screen matches.
A guide to TypeScript's advanced type features, which describe the shape of your data so mistakes are caught before the code runs. It covers reusable types, types that change based on rules, and built-in helper types, with short examples.
Guidance for building reliable server-side apps with Node.js, using Express or Fastify. It covers login, error handling, databases, API design and a list of proven best practices.
Intelligent automation and multi-agent orchestration for Claude Code
Claude Code plugin for AI-powered framework migration workflows, coordinating specialized agents to plan and execute transitions between technology stacks as part of the wshobson/agents marketplace.
A Claude Code plugin for payment system integration covering Stripe, PayPal, and billing platforms with checkout flows, subscription management, and webhook handling in the wshobson/agents ecosystem.
A Claude Code plugin bundling core development tools and agents for everyday tasks like debugging and code generation, part of the wshobson/agents marketplace with 73 focused plugins.
Claude Code plugin for observability and monitoring including logging, metrics, distributed tracing, and alerting, part of the wshobson/agents marketplace with 73 focused plugins.
A Claude Code plugin providing specialized AI agents for deployment strategy planning and execution, covering blue-green deployments, canary releases, rolling updates, and zero-downtime patterns.
Claude Code plugin for JVM language development including Java, Kotlin, and Scala with specialized agents for idiomatic patterns, build tools, and runtime optimization in the wshobson/agents marketplace.