testplan.testing.multitest.entries.schemas package

Submodules

testplan.testing.multitest.entries.schemas.assertions module

Schema definitions for serializing Assertion objects. This will be a one-way conversion, meaning that the reports and exports will be using the serialized data directly.

The reason being some assertion classes may have attributes that cannot be deserialized (processes, exception objects etc).

class testplan.testing.multitest.entries.schemas.assertions.ApproximateEqualitySchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.AssertionSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.AtMostOneList(cls_or_instance: Field | type[Field], **kwargs)[source]

Bases: List

property context: dict | None

The context dictionary for the parent Schema <marshmallow.Schema>.

property default
default_error_messages: dict[str, str] = {'invalid': 'Not a valid list.'}

Default error messages.

deserialize(value: Any, attr: str | None = None, data: Mapping[str, Any] | None = None, **kwargs)

Deserialize value.

Parameters:
  • value – The value to deserialize.

  • attr – The attribute/key in data to deserialize.

  • data – The raw input data passed to Schema.load <marshmallow.Schema.load>.

  • kwargs – Field-specific keyword arguments.

Raises:

ValidationError – If an invalid value is passed or if a required value is missing.

fail(key: str, **kwargs)

Helper method that raises a ValidationError with an error message from self.error_messages.

Deprecated since version 3.0.0: Use make_error <marshmallow.fields.Field.make_error> instead.

get_value(obj: ~typing.Any, attr: str, accessor: ~typing.Callable[[~typing.Any, str, ~typing.Any], ~typing.Any] | None = None, default: ~typing.Any = <marshmallow.missing>)

Return the value for a given key from an object.

Parameters:
  • obj – The object to get the value from.

  • attr – The attribute/key in obj to get the value from.

  • accessor – A callable used to retrieve the value of attr from the object obj. Defaults to marshmallow.utils.get_value.

make_error(key: str, **kwargs) ValidationError

Helper method to make a ValidationError with an error message from self.error_messages.

property missing
serialize(attr: str, obj: Any, accessor: Callable[[Any, str, Any], Any] | None = None, **kwargs)

Pulls the value for the given key from the object, applies the field’s formatting and returns the result.

Parameters:
  • attr – The attribute/key to get from the object.

  • obj – The object to access the attribute/key from.

  • accessor – Function used to access values from obj.

  • kwargs – Field-specific keyword arguments.

class testplan.testing.multitest.entries.schemas.assertions.BooleanSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.ColumnContainSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.DictCheckSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.DictMatchAllSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
compress_level(data, many, **kw)[source]
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.DictMatchSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
compress_level(data, many, **kw)[source]
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.EqualSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: FuncAssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.EqualSlicesSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.ExceptionRaisedSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.FailSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.FuncAssertionSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.LineDiffSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.LogfileMatchResultSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.LogfileMatchSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.MembershipSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.RawAssertionSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.RegexFindIterSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: RegexSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.RegexSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.TableMatchSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.assertions.XMLCheckSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AssertionSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

testplan.testing.multitest.entries.schemas.base module

Base classes / logic for marshalling go here.

class testplan.testing.multitest.entries.schemas.base.AssertionSchemaRegistry[source]

Bases: SchemaRegistry

bind(*classes)

Decorator for binding one or more classes to another.

Parameters:

classes – One or more classes that will be bound to the decorated class.

bind_default(category=None)

Decorator for binding a class as category based or absolute default.

Parameters:

category – (optional) If provided, the decorated class will be the default for the given category, otherwise it will be the absolute default.

property default
get_category(obj)[source]

Override this to define logic for generating the category key from the object instance.

get_lookup_key(obj)

This method is used for generating the key when do a lookup from the registry. Object class is used by default.

get_record_key(obj)

This method is used for generating the key when we bind an object (possibly a class) via the registry.

property logger: TestplanLogger

logger object

serialize(obj)
class testplan.testing.multitest.entries.schemas.base.AttachmentSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.BaseSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)[source]

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)[source]
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.CodeLogSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.DictLogSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
compress_level(data, many, **kw)[source]
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.DirectorySchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.EdgeSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.FlowChartSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.GenericEntryList(*, load_default: ~typing.Any = <marshmallow.missing>, missing: ~typing.Any = <marshmallow.missing>, dump_default: ~typing.Any = <marshmallow.missing>, default: ~typing.Any = <marshmallow.missing>, data_key: str | None = None, attribute: str | None = None, validate: ~typing.Callable[[~typing.Any], ~typing.Any] | ~typing.Iterable[~typing.Callable[[~typing.Any], ~typing.Any]] | None = None, required: bool = False, allow_none: bool | None = None, load_only: bool = False, dump_only: bool = False, error_messages: dict[str, str] | None = None, metadata: ~typing.Mapping[str, ~typing.Any] | None = None, **additional_metadata)[source]

Bases: Field

property context: dict | None

The context dictionary for the parent Schema <marshmallow.Schema>.

property default
default_error_messages: dict[str, str] = {'null': 'Field may not be null.', 'required': 'Missing data for required field.', 'validator_failed': 'Invalid value.'}

Default error messages for various kinds of errors. The keys in this dictionary are passed to Field.make_error. The values are error messages passed to marshmallow.exceptions.ValidationError.

deserialize(value: Any, attr: str | None = None, data: Mapping[str, Any] | None = None, **kwargs)

Deserialize value.

Parameters:
  • value – The value to deserialize.

  • attr – The attribute/key in data to deserialize.

  • data – The raw input data passed to Schema.load <marshmallow.Schema.load>.

  • kwargs – Field-specific keyword arguments.

Raises:

ValidationError – If an invalid value is passed or if a required value is missing.

fail(key: str, **kwargs)

Helper method that raises a ValidationError with an error message from self.error_messages.

Deprecated since version 3.0.0: Use make_error <marshmallow.fields.Field.make_error> instead.

get_value(obj: ~typing.Any, attr: str, accessor: ~typing.Callable[[~typing.Any, str, ~typing.Any], ~typing.Any] | None = None, default: ~typing.Any = <marshmallow.missing>)

Return the value for a given key from an object.

Parameters:
  • obj – The object to get the value from.

  • attr – The attribute/key in obj to get the value from.

  • accessor – A callable used to retrieve the value of attr from the object obj. Defaults to marshmallow.utils.get_value.

make_error(key: str, **kwargs) ValidationError

Helper method to make a ValidationError with an error message from self.error_messages.

property missing
serialize(attr: str, obj: Any, accessor: Callable[[Any, str, Any], Any] | None = None, **kwargs)

Pulls the value for the given key from the object, applies the field’s formatting and returns the result.

Parameters:
  • attr – The attribute/key to get from the object.

  • obj – The object to access the attribute/key from.

  • accessor – Function used to access values from obj.

  • kwargs – Field-specific keyword arguments.

class testplan.testing.multitest.entries.schemas.base.GraphSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.GroupSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)[source]

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.LogSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.MarkdownSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.NodeSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: Schema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.PlotlySchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: AttachmentSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

class testplan.testing.multitest.entries.schemas.base.TableLogSchema(*, only: Sequence[str] | AbstractSet[str] | None = None, exclude: Sequence[str] | AbstractSet[str] = (), many: bool | None = None, context: dict | None = None, load_only: Sequence[str] | AbstractSet[str] = (), dump_only: Sequence[str] | AbstractSet[str] = (), partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None)[source]

Bases: BaseSchema

class Meta

Bases: object

Options object for a Schema.

Example usage:

from marshmallow import Schema


class MySchema(Schema):
    class Meta:
        fields = ("id", "email", "date_created")
        exclude = ("password", "secret_attribute")

A note on type checking

Type checkers will only check the attributes of the Meta <marshmallow.Schema.Meta> class if you explicitly subclass marshmallow.Schema.Meta.

from marshmallow import Schema


class MySchema(Schema):
    # Not checked by type checkers
    class Meta:
        additional = True


class MySchema2(Schema):
    # Type checkers will check attributes
    class Meta(Schema.Opts):
        additional = True  # Incompatible types in assignment

Removed in version 3.0.0b7: Remove strict.

Added in version 3.0.0b12: Add unknown.

Changed in version 3.0.0b17: Rename dateformat to datetimeformat.

Added in version 3.9.0: Add timeformat.

Changed in version 3.26.0: Deprecate ordered. Field order is preserved by default.

additional: ClassVar[tuple[str, ...] | list[str]]

Fields to include in addition to the explicitly declared fields. additional <marshmallow.Schema.Meta.additional> and fields <marshmallow.Schema.Meta.fields> are mutually-exclusive options.

dateformat: ClassVar[str]

Default format for Date <marshmallow.fields.Date> fields.

datetimeformat: ClassVar[str]

Default format for DateTime <marshmallow.fields.DateTime> fields.

dump_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

exclude: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.

fields: ClassVar[tuple[str, ...] | list[str]]

Fields to include in the (de)serialized result

include: ClassVar[dict[str, Field]]

Dictionary of additional fields to include in the schema. It is usually better to define fields as class variables, but you may need to use this option, e.g., if your fields are Python keywords.

index_errors: ClassVar[bool]

If True, errors dictionaries will include the index of invalid items in a collection.

load_only: ClassVar[tuple[str, ...] | list[str]]

Fields to exclude from serialized results

many: ClassVar[bool]

Whether data should be (de)serialized as a collection by default.

ordered: ClassVar[bool]

If True, Schema.dump <marshmallow.Schema.dump> is a collections.OrderedDict.

register: ClassVar[bool]

Whether to register the Schema <marshmallow.Schema> with marshmallow’s internal class registry. Must be True if you intend to refer to this Schema <marshmallow.Schema> by class name in Nested fields. Only set this to False when memory usage is critical. Defaults to True.

render_module: Any

Module to use for loads <marshmallow.Schema.loads> and dumps <marshmallow.Schema.dumps>. Defaults to json from the standard library.

timeformat: ClassVar[str]

Default format for Time <marshmallow.fields.Time> fields.

unknown: ClassVar[str]

Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

OPTIONS_CLASS

alias of SchemaOpts

TYPE_MAPPING: dict[type, type[Field]] = {<class 'bool'>: <class 'marshmallow.fields.Boolean'>, <class 'bytes'>: <class 'marshmallow.fields.String'>, <class 'datetime.date'>: <class 'marshmallow.fields.Date'>, <class 'datetime.datetime'>: <class 'marshmallow.fields.DateTime'>, <class 'datetime.time'>: <class 'marshmallow.fields.Time'>, <class 'datetime.timedelta'>: <class 'marshmallow.fields.TimeDelta'>, <class 'decimal.Decimal'>: <class 'marshmallow.fields.Decimal'>, <class 'float'>: <class 'marshmallow.fields.Float'>, <class 'int'>: <class 'marshmallow.fields.Integer'>, <class 'list'>: <class 'marshmallow.fields.Raw'>, <class 'set'>: <class 'marshmallow.fields.Raw'>, <class 'str'>: <class 'marshmallow.fields.String'>, <class 'tuple'>: <class 'marshmallow.fields.Raw'>, <class 'uuid.UUID'>: <class 'marshmallow.fields.UUID'>}
property dict_class: type[dict]

dict type to return when serializing.

dump(obj: Any, *, many: bool | None = None)

Serialize an object to native Python data types according to this Schema’s fields.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

Serialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.

dump_fields: dict[str, Field]
dumps(obj: Any, *args, many: bool | None = None, **kwargs)

Same as dump(), except return a JSON-encoded string.

Parameters:
  • obj – The object to serialize.

  • many – Whether to serialize obj as a collection. If None, the value for self.many is used.

Returns:

A json string

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the serialized data rather than a (data, errors) duple. A ValidationError is raised if obj is invalid.

error_messages: dict[str, str] = {}

Overrides for default schema-level error messages

exclude: set[Any] | MutableSet[Any]
fields: dict[str, Field]

Dictionary mapping field_names -> Field objects

classmethod from_dict(fields: dict[str, Field], *, name: str = 'GeneratedSchema') type[Schema]

Generate a Schema <marshmallow.Schema> class given a dictionary of fields.

from marshmallow import Schema, fields

PersonSchema = Schema.from_dict({"name": fields.Str()})
print(PersonSchema().load({"name": "David"}))  # => {'name': 'David'}

Generated schemas are not added to the class registry and therefore cannot be referred to by name in Nested fields.

Parameters:
  • fields – Dictionary mapping field names to field instances.

  • name – Optional name for the class, which will appear in the repr for the class.

Added in version 3.0.0.

get_attribute(obj: Any, attr: str, default: Any)

Defines how to pull values from an object to serialize.

Changed in version 3.0.0a1: Changed position of obj and attr.

handle_error(error: ValidationError, data: Any, *, many: bool, **kwargs)

Custom error handler function for the schema.

Parameters:
  • error – The ValidationError raised during (de)serialization.

  • data – The original input data.

  • many – Value of many on dump or load.

  • partial – Value of partial on load.

Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.

load(*args, **kwargs)

Deserialize a data structure to an object defined by this Schema’s fields.

Parameters:
  • data – The data to deserialize.

  • many – Whether to deserialize data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

load_fields: dict[str, Field]
loads(json_data: str | bytes | bytearray, *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None, unknown: str | None = None, **kwargs)

Same as load(), except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data to load().

Parameters:
  • json_data – A string of the data to deserialize.

  • many – Whether to deserialize obj as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE. If None, the value for self.unknown is used.

Returns:

Deserialized data

Added in version 1.0.0.

Changed in version 3.0.0b7: This method returns the deserialized data rather than a (data, errors) duple. A ValidationError is raised if invalid data are passed.

on_bind_field(field_name: str, field_obj: Field) None

Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.

No-op by default.

opts: Any = <marshmallow.schema.SchemaOpts object>
set_class

alias of OrderedSet

streamline(data, **kwargs)
validate(data: Mapping[str, Any] | Iterable[Mapping[str, Any]], *, many: bool | None = None, partial: bool | Sequence[str] | AbstractSet[str] | None = None) dict[str, list[str]]

Validate data against the schema, returning a dictionary of validation errors.

Parameters:
  • data – The data to validate.

  • many – Whether to validate data as a collection. If None, the value for self.many is used.

  • partial – Whether to ignore missing fields and not require any fields declared. Propagates down to Nested fields as well. If its value is an iterable, only missing fields listed in that iterable will be ignored. Use dot delimiters to specify nested fields.

Returns:

A dictionary of validation errors.

Added in version 1.1.0.

Module contents

Entry point for schema serialization bindings.