logoalt Hacker News

whalesaladtoday at 2:40 AM1 replyview on HN

A lot of people have this misconception that Pydantic models are only useful for returning API responses. This is proliferated by all-in-one frameworks like FastAPI.

They are useful in and of themselves as internal business/domain objects, though. For a lot of cases I prefer lighter weight dataclasses that have less ceremony and runtime slowdown with the validation layer, but we use Pydantic models all over the place to guarantee and establish contracts for objects flowing thru our system, irrespective of external facing API layer.


Replies

nine_ktoday at 4:18 AM

Pydantic models are validating. Hence their natural place is interfaces with external systems, outside the reach of your typechecker.