Chapter 4 of 7
TypedDict, dataclass and BaseModel
Three ways to write a shape down, at three prices. A TypedDict describes a dictionary and costs nothing at runtime, a dataclass generates a real class with attributes and validates nothing, and a pydantic BaseModel checks and coerces every field on construction, turning a quoted 3 into the integer 3 under v2 lax defaults. This chapter matches each to the seam it belongs at, and settles when dict[str, Any] is still the right signature.
Python for AI work — read the current version at https://daviddominguez.dev/learn/en/python-for-ai-work/typeddict-dataclass-and-basemodel