casys.readers.schemas
Elements’ schemas.
Functions
|
Normalize provided source into correct reader's parameters. |
Register all Casys readers schema. |
Classes
|
Special type indicating an unconstrained type. |
|
OCTANT TableInSitu data reader. |
|
CLS InSituTable's reader marshmallow schema. |
|
OCTANT CLS TableMeasure data reader. |
|
CLS Table's reader marshmallow schema. |
|
Abstract class representing a casys data reader. |
|
CasysReader marshmallow schema. |
|
|
|
DataCleaner' marshmallow schema. |
|
xarray Dataset reader. |
|
Dataset's reader marshmallow schema. |
|
Marshmallow schema for the Field class. |
|
Marshmallow FreqType field. |
|
Reader allowing to read from a set of readers. |
|
Multi data reader marshmallow schema. |
|
Reader for a swot_calval Collection. |
|
Swot_calval IO Collection Dataset's reader schema. |
|
xarray Dataset reader. |
|
Diagnostic storage reader schema. |
|
Reader for a Zcollection Collection. |
|
ZCollection Dataset's reader schema. |
|
Reader for the zcollection.Dataset format. |
|
ZCollection Dataset's reader schema. |
|
xarray Dataset reader for the zarr format. |
|
Dataset's reader marshmallow schema. |
Exceptions
|
Exception raised when a problem related to data reading occurs. |
- class casys.readers.schemas.CLSTableInSituReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
CasysReaderBaseSchema
CLS InSituTable’s reader marshmallow schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
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, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.CLSTableReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
CasysReaderBaseSchema
CLS Table’s reader marshmallow schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
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, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.CasysReaderBaseSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
RegistryBaseSchema
CasysReader marshmallow schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
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, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.CasysReaderGenericSchema(**kwargs)
Bases:
RegistryGenericSchema
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
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, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.DatasetReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
CasysReaderBaseSchema
Dataset’s reader marshmallow schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dump_fields: dict[str, Field]
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.
- error_messages: dict[str, str] = {}
Overrides for default schema-level error messages
- exclude: set[typing.Any] | typing.MutableSet[typing.Any]
- fields: dict[str, Field]
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- load_fields: dict[str, Field]
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.MultiReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
CasysReaderBaseSchema
Multi data reader marshmallow schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dump_fields: dict[str, Field]
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.
- error_messages: dict[str, str] = {}
Overrides for default schema-level error messages
- exclude: set[typing.Any] | typing.MutableSet[typing.Any]
- fields: dict[str, Field]
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- load_fields: dict[str, Field]
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.ScCollectionReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
ZDatasetReaderSchema
Swot_calval IO Collection Dataset’s reader schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dump_fields: dict[str, Field]
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.
- error_messages: dict[str, str] = {}
Overrides for default schema-level error messages
- exclude: set[typing.Any] | typing.MutableSet[typing.Any]
- fields: dict[str, Field]
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- load_fields: dict[str, Field]
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.StoreReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
CasysReaderBaseSchema
Diagnostic storage reader schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dump_fields: dict[str, Field]
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.
- error_messages: dict[str, str] = {}
Overrides for default schema-level error messages
- exclude: set[typing.Any] | typing.MutableSet[typing.Any]
- fields: dict[str, Field]
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- load_fields: dict[str, Field]
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.ZCollectionReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
DatasetReaderSchema
ZCollection Dataset’s reader schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dump_fields: dict[str, Field]
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.
- error_messages: dict[str, str] = {}
Overrides for default schema-level error messages
- exclude: set[typing.Any] | typing.MutableSet[typing.Any]
- fields: dict[str, Field]
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- load_fields: dict[str, Field]
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.ZDatasetReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
CasysReaderBaseSchema
ZCollection Dataset’s reader schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dump_fields: dict[str, Field]
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.
- error_messages: dict[str, str] = {}
Overrides for default schema-level error messages
- exclude: set[typing.Any] | typing.MutableSet[typing.Any]
- fields: dict[str, Field]
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- load_fields: dict[str, Field]
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- class casys.readers.schemas.ZarrDatasetReaderSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
DatasetReaderSchema
Dataset’s reader marshmallow schema.
- Parameters:
- 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.
-
exclude:
ClassVar
[tuple
[str
,...
] |list
[str
]] Fields to exclude in the serialized result. Nested fields can be represented with dot delimiters.
-
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.
-
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.
-
additional:
- 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'>}
- classmethod clear_registry()
Clear everything from this schema’s registry.
- dump(obj, *, many=None)
Serialize an object to native Python data types according to this Schema’s fields.
- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.Changed in version 3.0.0rc9: Validation no longer occurs upon serialization.
- dump_fields: dict[str, Field]
- dumps(obj, *args, many=None, **kwargs)
Same as
dump()
, except return a JSON-encoded string.- Parameters:
- 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. AValidationError
is raised ifobj
is invalid.
- error_messages: dict[str, str] = {}
Overrides for default schema-level error messages
- exclude: set[typing.Any] | typing.MutableSet[typing.Any]
- fields: dict[str, Field]
Dictionary mapping field_names ->
Field
objects
- classmethod from_dict(fields, *, name='GeneratedSchema')
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:
- Return type:
type
[Schema
]
Added in version 3.0.0.
- get_attribute(obj, attr, default)
Defines how to pull values from an object to serialize.
Changed in version 3.0.0a1: Changed position of
obj
andattr
.
- classmethod get_class(name: str) type[RegistryBaseSchema]
Return the registered class associated with the provided name.
- Parameters:
name (str) – Identifier of the schema.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- classmethod get_model()
Return the model associated to this schema.
- classmethod get_model_schema(model: type) type[RegistryBaseSchema]
Return the registered class associated with the provided model.
- Parameters:
model (type) – Identifier of the model.
- Return type:
type[RegistryBaseSchema]
- Returns:
Corresponding schema class.
- handle_error(error, data, *, many, **kwargs)
Custom error handler function for the schema.
- Parameters:
Changed in version 3.0.0rc9: Receives many and partial (on deserialization) as keyword arguments.
- classmethod is_reader(stype, source)
Check whether the provided source is for this reader or not.
- load(data, *, many=None, partial=None, unknown=None)
Deserialize a data structure to an object defined by this Schema’s fields.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to deserialize.many (
bool
|None
) – Whether to deserialize data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- load_fields: dict[str, Field]
- loads(json_data, *, many=None, partial=None, unknown=None, **kwargs)
Same as
load()
, except it uses marshmallow.Schema.Meta.render_module to deserialize the passed string before passing data toload()
.- Parameters:
json_data (
str
|bytes
|bytearray
) – A string of the data to deserialize.many (
bool
|None
) – Whether to deserialize obj as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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 (
str
|None
) – 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. AValidationError
is raised if invalid data are passed.
- make_object(data, **_)
- on_bind_field(field_name, field_obj)
Hook to modify a field when it is bound to the Schema <marshmallow.Schema>.
No-op by default.
- opts: typing.Any = <marshmallow.schema.SchemaOpts object>
- post_dump(data, original_data, **_)
- pre_dump(data, **_)
- pre_load(data, **_)
- classmethod register()
Register the current class.
- classmethod register_schema(schema, exception)
Register the provided schema.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schema to register.exception (
type
[Exception
]) – Exception raised when an invalid operation is made.
- classmethod registry()
Returns a copy of the registry.
- Return type:
- set_class
alias of
OrderedSet
- classmethod update_registry(schema)
Update current registry with the provided one. An error is raised if the same name is used twice.
- Parameters:
schema (
type
[RegistryAbstractSchema
]) – Schemas to register.
- validate(data, *, many=None, partial=None)
Validate data against the schema, returning a dictionary of validation errors.
- Parameters:
data (
Union
[Mapping
[str
,Any
],Iterable
[Mapping
[str
,Any
]]]) – The data to validate.many (
bool
|None
) – Whether to validate data as a collection. If None, the value for self.many is used.partial (
Union
[bool
,Sequence
[str
],AbstractSet
[str
],None
]) – Whether to ignore missing fields and not require any fields declared. Propagates down toNested
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.
- Return type:
- Returns:
A dictionary of validation errors.
Added in version 1.1.0.
- casys.readers.schemas.normalize_source(source, stype=None)
Normalize provided source into correct reader’s parameters.
- casys.readers.schemas.register_all_readers()
Register all Casys readers schema.