fastapi-templates

Automates scaffolding of FastAPI projects with async REST APIs, DI, middleware, and error handling.

1|Updated Aug 31, 2024
One-click install
npx skills add https://github.com/aRustyDev/dotfiles --skill fastapi-templates-arustydev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi-templates
Source: https://github.com/aRustyDev/dotfiles/tree/main/.ai/plugins/api-scaffolding/skills/fastapi-templates
Command: npx skills add https://github.com/aRustyDev/dotfiles --skill fastapi-templates-arustydev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires fastapi, uvicorn, sqlalchemy, asyncpg, pydantic, pydantic-settings, passlib, python-jose, httpx, pytest, pytest-asyncio, aiosqlite, and includes references (resource) and assets (resource) components.

What problem does it solve?

This Skill provides production-ready FastAPI project templates, enabling you to quickly scaffold high-performance async APIs with best practices like dependency injection, robust error handling, and a clear project structure.

Core Features & Use Cases

  • Structured Project Layout: Organizes code into API routes, core config, models, schemas, services, and repositories for maintainability.
  • Async Patterns & DI: Leverages FastAPI's async capabilities and dependency injection for efficient, testable code.
  • CRUD & Auth Implementation: Provides patterns for common CRUD operations, user authentication, and authorization.
  • Use Case: Rapidly start a new backend API for a web application, complete with user management, authentication, and database integration, following a scalable and maintainable architecture.

Quick Start

Generate the basic main.py file for a FastAPI application, including CORS middleware and a lifespan event for database connection.

Frequently Asked Questions about fastapi-templates

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I scaffold a production-ready FastAPI project quickly?

Scaffolding a FastAPI project creates a complete project structure with organized directories for routes, models, schemas, services, and repositories. This template automates setup of async REST APIs, dependency injection, middleware, error handling, and database integration—eliminating manual boilerplate so you start coding business logic immediately.

What's the best way to structure a FastAPI REST API with async route handlers?

Structure FastAPI REST APIs using layered architecture: routes handle HTTP requests, services contain business logic, repositories manage data access, and dependency injection connects components. This pattern leverages FastAPI's async capabilities and Pydantic for validation, making code testable, maintainable, and performant.

Can I use FastAPI with PostgreSQL and async database queries?

FastAPI integrates with PostgreSQL through asyncpg and SQLAlchemy, enabling non-blocking async database queries. The template provides configured patterns for async CRUD operations, connection pooling via lifespan events, and repository methods that work seamlessly with FastAPI's dependency injection system.

How do I implement user authentication and authorization in a FastAPI API?

Authentication and authorization in FastAPI use dependency injection with security schemes. The template includes patterns for JWT tokens via python-jose, password hashing with passlib, and protected route handlers that verify user credentials before allowing access to endpoints.

Does FastAPI handle middleware and error handling automatically?

FastAPI supports custom middleware and structured error handling through lifespan events and exception handlers. The template pre-configures CORS middleware, database connection lifecycle management, and centralized error responses—reducing setup time while ensuring consistency across your API.

What Python dependencies do I need for a production FastAPI application?

Production FastAPI applications require fastapi for the framework, uvicorn as the ASGI server, SQLAlchemy and asyncpg for async database access, Pydantic for data validation, passlib and python-jose for authentication, and pytest with pytest-asyncio for testing. The template pre-configures all these dependencies.