Say I have a Schema like this:
class MySchema(Schema):
field_1 = Float()
field_2 = Float()
...
field_42 = Float()
Is there a w
All you need to do is to use type() function to build your class with any attributes you want:
MySchema = type('MySchema', (marshmallow.Schema,), {
attr: marshmallow.fields.Float()
for attr in FIELDS
})
You can even have different types of fields there:
fields = {}
fields['foo'] = marshmallow.fields.Float()
fields['bar'] = marshmallow.fields.String()
MySchema = type('MySchema', (marshmallow.Schema,), fields)
or as a base for your customizations:
class MySchema(type('_MySchema', (marshmallow.Schema,), fields)):
@marshmallow.post_dump
def update_something(self, data):
pass