Non-required properties in Schema


Is it possible to set a property to required=False in a Schema?

class TestSchema(schema.Object):
    properties = {
        'test_length': schema.Number(required=False)


Use eg. ‘default=None’.
At the moment we’re rolling with “if it doesn’t have a default then it’s required” this is more constrained than REST framework but also more natural, and doesn’t give you various different ways of representing emptiness. (Not present va None vs empty string)


I can roll with default=None


I just ran through this example:

Shouldn’t the snippet be like this:

class Product(schema.Object):
    properties = {
        'name': schema.String(max_length=100),
        'rating': schema.Integer(minimum=1, maximum=5),
        'in_stock': schema.Boolean,
        'size': ProductSize


Sorry I’m not sure what you’re asking.

Either ‘Boolean’ or ‘Boolean(default=False)’ could be valid, depending on if you want it to be required for the client to provide a value or not.


Sorry, what i asked is whether or not the example was correct, as i was not able to successfully implement it without the properties dict.


Hey guys, I tried starting another thread close to this topic of Schema. I actually got started on this path because of the topic of Non required fields.

I built an APIStar application using Marshmallow because it was easy to use the meta schema features on SQLAlchemy models via that package. It looks like it got plenty of views from forum participants, but it has zero replies.

Could either of you help identify what benefits could I be losing in APIStar by using Marchmallow for schema definition vs the Typesystem provided by APIStar?