Betwixt: a data transformation layer design spec
TLDR
Your DB type and your API type are not the same shape. Stop trying to squish them together with awkward hooks, aliases, and non-local mapping functions. Betwixt your models lives a new, delcarative mapping layer.
Pick any non-trivial Python backend. There is a database type (an
ORM row, a @dataclass, an attrs class) and there is an API type
(a Pydantic model, an msgspec struct, whatever the framework
demands). They are not the same shape. They cannot be the same
shape: one is constrained by the storage schema, the other by
the wire contract. Mapping between them is real work.



