Design Value Objects with Python Dataclasses
Python dictionaries are convenient for passing a few values around, but they become fragile when a value has invariants or behavior that deserves a name. dataclasses can express small domain value objects without repetitive constructors and representation methods.
Start with domain meaning A price represented as a dictionary is easy to misuse:
Copy price = {"amount": 1299, "currency": "USD"} Any caller can omit a key or accidentally mix cents and dollars. A value object makes the contract explicit: