FastAPI Project Templates
Unverified●30/40Claude Code◐PartialHas SKILL.md but declares no allowed-tools — Claude Code will ask for permission each time
Cursor◐PartialPlain prose you can paste in — but no Cursor rules file
Codex◐PartialPlain prose you can paste in — but no AGENTS.md
Gemini CLI◐PartialPlain prose you can paste in
Copilot◐PartialPlain prose you can paste in — but no Copilot instructions file
npx agentalley add fastapi-templatesWho 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
Frontmatter — 2 properties
| 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. |
| 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 | ---A5 — No allowed-tools declared — no way to tell what this skill may touch |
| 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 | ```python |
| 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 |
Reviews
Installed this one?Write the first review and take the Trailblazer badge.
Alternatives
Subagent Driven DevelopmentUse when executing implementation plans with independent tasks in the current session◐◐◐◐◐●36/40Python Code Style & DocumentationPython code style, linting, formatting, naming conventions, and documentation standards. Use when writing new code, reviewing style, configuring linters, writing docstrings, or establishing project standards.◐····●35/40Competitor Price Analysis 💲Competitor pricing strategy analysis and market positioning. Price mapping, pricing gaps identification, elasticity signals evaluation, and strategic pricing optimization. Use when the user asks about competitor pricing, price analysis, pricing strategy, or co◐····●34/40Competitor Price Tracker 📊Set up competitor price tracking and monitoring workflows. Track price changes, detect promotions, analyze pricing patterns, and get alerts for competitive price movements.◐····●34/40