Define a Schema for a Model
Declare fields that map to your model.
What a Schema Is
A Schema is a Python class that lists the fields your data should have. It mirrors a model but lives separately, just for input and output.
Subclass Schema
Every schema inherits from Marshmallow's base Schema class. Naming it after your model, like UserSchema, keeps the intent obvious at a glance.
class UserSchema(Schema):
passAll lessons in this course
- Why Hand-Built JSON Falls Apart
- Define a Schema for a Model
- Dump Objects to JSON
- Load and Validate Input Payloads