
Fastapi Templates
Bootstrap a production-style FastAPI service with async routes, dependency injection, layered folders, and test-friendly layout.
Overview
FastAPI Templates is an agent skill for the Build phase that scaffolds production-ready FastAPI projects with async patterns, dependency injection, and layered api/core/models/schemas/services/repositories structure.
Install
npx skills add https://github.com/wshobson/agents --skill fastapi-templatesWhat is this skill?
- Recommended app/ layout: api/v1/endpoints, core config/security/database, models, schemas, services, repositories
- Async-first REST patterns with shared dependencies module
- Separation of Pydantic schemas, persistence models, services, and repositories
- Geared to PostgreSQL and MongoDB async stacks mentioned in the skill
- Includes middleware and error-handling orientation for high-performance microservices
Adoption & trust: 18.5k installs on skills.sh; 36.5k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need a new FastAPI backend but agent output keeps collapsing into one file without tests, DI, or a clear place for business logic.
Who is it for?
Solo builders starting async Python APIs or microservices who want consistent project structure from day one.
Skip if: Tiny scripts, serverless one-offs, or teams already locked into Django-only conventions without wanting FastAPI.
When should I use this skill?
Create production-ready FastAPI projects with async patterns, dependency injection, and comprehensive error handling when building new FastAPI applications or setting up backend API projects.
What do I get? / Deliverables
You get a versioned, layered FastAPI skeleton your agent can populate with endpoints, schemas, and repositories aligned to async best practices.
- Layered FastAPI app/ directory tree with routers and endpoint stubs
- Core config, security, and database module placeholders
- Models, schemas, services, and repositories separation ready for implementation
Recommended Skills
Journey fit
New API foundations are a core Build activity once scope is validated and you are implementing the product backend. Backend subphase is the canonical home for REST/async service structure, not frontend or DevOps-only repos.
How it compares
Opinionated folder template for FastAPI—not a hosted BaaS or generic Python web scaffold for Flask.
Common Questions / FAQ
Who is fastapi-templates for?
Indie developers and agent users creating new FastAPI REST or async web services who want maintainable separation between routes, services, and data access.
When should I use fastapi-templates?
Use it when starting new FastAPI applications from scratch, implementing async APIs with PostgreSQL or MongoDB, or restructuring an early prototype into a testable backend during Build.
Is fastapi-templates safe to install?
See the Security Audits panel on this Prism page; review generated dependencies, secrets handling, and auth code before exposing any API to the internet.
SKILL.md
READMESKILL.md - Fastapi Templates
# 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 ## Implementation Patterns ### Pattern 1: Complete FastAPI Application ```python # main.py from fastapi import FastAPI, Depends from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan events.""" # Startup await database.connect() yield # Shutdown await database.disconnect() app = FastAPI( title="API Template", version="1.0.0", lifespan=lifespan ) # CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Include routers from app.api.v1.router import api_router app.include_router(api_router, prefix="/api/v1") # core/config.py from pydantic_settings import BaseSettings from functools import lru_cache class Settings(BaseSettings): """Application settings.""" DATABASE_URL: str SECRET_KEY: str ACCESS_TOKEN_EXPIRE_MINUTES: int = 30 API_V1_STR: str = "/api/v1" class Config: env_file = ".env" @lru_cache() def get_settings() -> Settings: return Settings() # core/database.py from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from app.core.config import get_settings settings = get_settings() engine = create_async_engine( settings.DATABASE_URL, echo=True, future=True ) AsyncSessionLocal = sessionmaker( engine, class_=AsyncSession, expire_on_commit=False ) Base = declarative_base() async def get_db() -> AsyncSession: """Dependency for database session.""" async with AsyncSessionLocal() as session: try: yield session await session.commit() except Exception: await session.rollback() raise finally: await session.close() ``` ### Pattern 2: CRUD Repository Pattern ```python # repositories/base_repository.py from typing import Generic, TypeVar, Type, Optional, List from sqlalchemy.ext.asyncio