# Fastapi

> FastAPI framework best practices including Pydantic schemas, dependency injection, and async patterns. Use when this capability is needed.

- Skill: `tomevault-io/fastapi-8` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/fastapi-8`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/fastapi-8/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/fastapi-8

---


# FastAPI Best Practices

## Project Structure
- app/main.py - Application entry
- app/routers/ - Route handlers
- app/models/ - SQLAlchemy models
- app/schemas/ - Pydantic schemas
- app/services/ - Business logic
- app/dependencies.py - Dependency injection

## Pydantic Schemas
- Use separate schemas for input/output
- Use Field() for validation
- Use model_validator for complex validation
- Use Config for schema settings

## Dependency Injection
- Use Depends() for dependencies
- Create reusable dependencies
- Use yield for cleanup logic
- Cache expensive dependencies

## Async
- Use async def for I/O operations
- Use httpx for async HTTP
- Use databases/SQLAlchemy async
- Avoid blocking in async context

## Performance
- Use response_model for serialization
- Enable response caching
- Use background tasks
- Stream large responses
- Use connection pooling

---
> Source: [kprsnt2/MyLocalCLI](https://github.com/kprsnt2/MyLocalCLI) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-16 -->

