05 - Scheming Schemas

In this module we will go over what Schemas are and create our own for our two models

Marshmallow and Schemas

Marshmallow is a Python library which enables us to easily sanitize and validate content according to a schema. Schemas are useful when we want to sift through user provided data in a group rather than dealing with each item individually. Schemas define how we will dump data and which fields/attributes will get through.

To achieve this, we need two items from marshmallow, the Schema object and fields. Add the following import statement to both model files, and add the trailing schema classes to their respective model files

from marshmallow import Schema, fields

UserSchema definition for UserModel
BlogPostSchema definition

Building this schema will also fix an error from the previous module as at the time we never had the BlogPostSchema

Last updated

Was this helpful?