python-fastapi

Scaffolds FastAPI projects with Pydantic V2 schemas, hexagonal architecture, and strict type hints.

6|Updated May 18, 2026
One-click install
npx skills add https://github.com/mokhtarabadi/cognitive-lead-hq --skill python-fastapi-mokhtarabadi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-fastapi
Source: https://github.com/mokhtarabadi/cognitive-lead-hq/tree/main/skill-templates/python-fastapi
Command: npx skills add https://github.com/mokhtarabadi/cognitive-lead-hq --skill python-fastapi-mokhtarabadi

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? AI-generated Python backends often suffer from hallucinated types, naive datetimes, and tangled framework coupling. This Skill enforces a strict FastAPI architecture so generated code stays typed, testable, and framework-decoupled. ## Core Features & Use Cases - Strict Type Safety: Mandates type hints on every function and Pydantic V2 schemas for all request/response DTOs, keeping ORM models out of API responses. - Hexagonal Architecture: Separates a zero-framework core (entities, ports as typing.Protocol, use cases) from FastAPI/SQLAlchemy adapters wired through a composition root. - Datetime Governance: Enforces timezone-aware datetimes, AwareDatetime schema fields, and an injectable ClockProvider instead of direct datetime.now() calls. - Use Case: Ask the AI to scaffold a new FastAPI microservice with user management; it produces modular routers, async SQLAlchemy 2.0 models, Pydantic V2 schemas, and pytest unit tests with faked protocol implementations. ## Quick Start Use the python-fastapi skill to scaffold a new FastAPI service with async endpoints, Pydantic V2 schemas, and a hexagonal core for a user management API.

Frequently Asked Questions about python-fastapi

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

FAQPage Schema
How do I structure a FastAPI project for production?▼

Organize code into app/api for routers, app/core for configuration, app/models for SQLAlchemy 2.0 models, app/schemas for Pydantic DTOs, and app/services for business logic. Use snake_case files, PascalCase classes, and keep dependency injection localized with Depends().

How to implement hexagonal architecture in FastAPI?▼

Keep a zero-framework core with plain dataclass entities and typing.Protocol ports, then place FastAPI routers and Postgres adapters in an adapters layer. Wire everything through a container.py composition root so routers depend only on inbound port protocols.

Should FastAPI endpoints return SQLAlchemy models directly?▼

No, endpoints should always return Pydantic V2 schemas instead of ORM models. This ensures response validation, hides sensitive fields, and decouples the API contract from the database schema.

Why is datetime.utcnow() deprecated in FastAPI apps?▼

datetime.utcnow() produces naive datetimes that cause timezone bugs. Use datetime.now(timezone.utc), Pydantic's AwareDatetime for schema fields, and an injectable ClockProvider so business logic stays testable.

How do I test FastAPI services and routes with pytest?▼

Write unit tests for services using faked protocol implementations, and integration tests for routes using pytest with httpx AsyncClient. For adapter tests against real Postgres, use testcontainers.