Contents
Exceptions¶
RegistryNotFound¶
-
exception
anyblok_marshmallow.exceptions.
RegistryNotFound
Bases:
Exception
Exception raised when no registry is found to build schema
-
with_traceback
() Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
Fields¶
Nested¶
-
class
anyblok_marshmallow.fields.
Nested
(nested, default=<marshmallow.missing>, exclude=(), only=None, **kwargs) Bases:
marshmallow.fields.Nested
Inherit marshmallow fields.Nested
-
context
The context dictionary for the parent
Schema
.
-
deserialize
(value, attr=None, data=None) Deserialize
value
.Raises: ValidationError – If an invalid value is passed or if a required value is missing.
-
fail
(key, **kwargs) A helper method that simply raises a ValidationError.
-
get_value
(attr, obj, accessor=None, default=<marshmallow.missing>) Return the value for a given key from an object.
-
root
Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
schema
Overload the super property to remove cache
it is the only way to propagate the context at each call
-
serialize
(attr, obj, accessor=None) Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
Parameters: Raises: ValidationError – In case of formatting problem
-
File¶
-
class
anyblok_marshmallow.fields.
File
(default=<marshmallow.missing>, attribute=None, load_from=None, dump_to=None, error=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, missing=<marshmallow.missing>, error_messages=None, **metadata) Bases:
marshmallow.fields.Field
-
context
The context dictionary for the parent
Schema
.
-
deserialize
(value, attr=None, data=None) Deserialize
value
.Raises: ValidationError – If an invalid value is passed or if a required value is missing.
-
fail
(key, **kwargs) A helper method that simply raises a ValidationError.
-
get_value
(attr, obj, accessor=None, default=<marshmallow.missing>) Return the value for a given key from an object.
-
root
Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize
(attr, obj, accessor=None) Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
Parameters: Raises: ValidationError – In case of formatting problem
-
Text¶
-
class
anyblok_marshmallow.fields.
Text
(default=<marshmallow.missing>, attribute=None, load_from=None, dump_to=None, error=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, missing=<marshmallow.missing>, error_messages=None, **metadata) Bases:
marshmallow.fields.String
Simple field use to distinct by the class String and Text
-
context
The context dictionary for the parent
Schema
.
-
deserialize
(value, attr=None, data=None) Deserialize
value
.Raises: ValidationError – If an invalid value is passed or if a required value is missing.
-
fail
(key, **kwargs) A helper method that simply raises a ValidationError.
-
get_value
(attr, obj, accessor=None, default=<marshmallow.missing>) Return the value for a given key from an object.
-
root
Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize
(attr, obj, accessor=None) Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
Parameters: Raises: ValidationError – In case of formatting problem
-
JsonCollection¶
-
class
anyblok_marshmallow.fields.
JsonCollection
(fieldname=None, keys=None, instance='default', cls_or_instance_type=<class 'marshmallow.fields.String'>, *args, **kwargs) Bases:
marshmallow.fields.Field
-
context
The context dictionary for the parent
Schema
.
-
deserialize
(value, attr=None, data=None) Deserialize
value
.Raises: ValidationError – If an invalid value is passed or if a required value is missing.
-
fail
(key, **kwargs) A helper method that simply raises a ValidationError.
-
get_value
(attr, obj, accessor=None, default=<marshmallow.missing>) Return the value for a given key from an object.
-
root
Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize
(attr, obj, accessor=None) Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
Parameters: Raises: ValidationError – In case of formatting problem
-
Country¶
-
class
anyblok_marshmallow.fields.
Country
(default=<marshmallow.missing>, attribute=None, load_from=None, dump_to=None, error=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, missing=<marshmallow.missing>, error_messages=None, **metadata) Bases:
marshmallow.fields.String
-
context
The context dictionary for the parent
Schema
.
-
deserialize
(value, attr=None, data=None) Deserialize
value
.Raises: ValidationError – If an invalid value is passed or if a required value is missing.
-
fail
(key, **kwargs) A helper method that simply raises a ValidationError.
-
get_value
(attr, obj, accessor=None, default=<marshmallow.missing>) Return the value for a given key from an object.
-
root
Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize
(attr, obj, accessor=None) Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
Parameters: Raises: ValidationError – In case of formatting problem
-
InstanceField¶
-
class
anyblok_marshmallow.fields.
Country
(default=<marshmallow.missing>, attribute=None, load_from=None, dump_to=None, error=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, missing=<marshmallow.missing>, error_messages=None, **metadata) Bases:
marshmallow.fields.String
-
context
The context dictionary for the parent
Schema
.
-
deserialize
(value, attr=None, data=None) Deserialize
value
.Raises: ValidationError – If an invalid value is passed or if a required value is missing.
-
fail
(key, **kwargs) A helper method that simply raises a ValidationError.
-
get_value
(attr, obj, accessor=None, default=<marshmallow.missing>) Return the value for a given key from an object.
-
root
Reference to the Schema that this field belongs to even if it is buried in a List. Return None for unbound fields.
-
serialize
(attr, obj, accessor=None) Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
Parameters: Raises: ValidationError – In case of formatting problem
-
Schema¶
update_from_kwargs¶
-
anyblok_marshmallow.schema.
update_from_kwargs
(*entries) decorator to get temporaly the value in kwargs and put it in schema
Params entries: array ok entry name to take from the kwargs
format_field¶
-
anyblok_marshmallow.schema.
format_fields
(x) remove the anyblok prefix form the field name
ModelConverter¶
-
class
anyblok_marshmallow.schema.
ModelConverter
(schema_cls=None) Bases:
marshmallow_sqlalchemy.convert.ModelConverter
Overwrite the ModelConverter class of marshmallow-sqlalchemy
The goal if to fix the fieldname, because they are prefixed.
-
fields_for_model
(Model, **kwargs) Overwrite the method and remove prefix of the field name
-
TemplateSchema¶
-
class
anyblok_marshmallow.schema.
TemplateSchema
Bases:
object
Base class of Schema generated by
SchemaWrapper
-
OPTIONS_CLASS
alias of
marshmallow_sqlalchemy.schema.ModelSchemaOpts
-
PostLoadSchema¶
-
class
anyblok_marshmallow.schema.
PostLoadSchema
Bases:
object
Return the AnyBlok instance from marshmallow deserialize
SchemaWrapper¶
-
class
anyblok_marshmallow.schema.
SchemaWrapper
(*args, **kwargs) Bases:
marshmallow.base.SchemaABC
Schema Wrapper to generate marshmallow schema
class MySchema(SchemaWrapper): model = 'Model.Name'
the wrapper implement the marshmallow.base.SchemaABC abstract class. And call the methods of the marshmallow schema with the same parameter
Some class attributes can be added to improve the schema:
- model: str, the registry name of the AnyBlok model
- required_fields: list of the field which become required In this case the anyblok columns are not required but schema force them to be required
- registry: the anyblok registry, only if you know it
- only_primary_key: boolean, if True the marshmallow parameter only will be filled with the name of the primary keys.
Note
The model and registry are required to generate the schema. they can be defined by class attribute, parameter in the methods (load, loads, validate, dump, dumps) or in the context attribute.
-
generate_marsmallow_instance
() Generate the real mashmallow-sqlalchemy schema
-
schema
property to get the real schema