casys.report.configurator
Submodule allowing to set and generate structured reports.
Functions
|
Create a diagnostic name if not included in provided parameters. |
Classes
|
Class representing a single diagnostic configuration. |
|
Class representing the configuration's information of a field. |
|
Class allowing to configure and generate reports. |
|
Marshmallow schema for ReportConfigurator. |
|
Different types of multi-mission display policies. |
|
Marshmallow MultiMissionPolicy field. |
|
Class containing text properties (title and text) for different elements. |
|
ReportProperties' marshmallow schema. |
|
Different types of section naming policies. |
|
Marshmallow SectionOrderType field. |
|
Data source specification. |
|
SourceConfiguration's marshmallow schema. |
|
Class representing the configuration of a report's section. |
|
Marshmallow schema for SectionConfiguration. |
|
Report's sources configuration. |
|
ReportSources' marshmallow schema. |
|
Diagnostic allowing to combine plots from different sources. |
|
Marshmallow schema for the PlotOperatorDiagnostic class. |
|
Base class to create custom diagnostics usable in a ReportGenerator. |
|
|
|
Exceptions
Exception raised when a problem related to report configuration occurs. |
- class casys.report.configurator.DiagnosticConfiguration(section=None, properties=<factory>, parameters=<factory>, report=<factory>)
Bases:
SectionBase
Class representing a single diagnostic configuration.
- Parameters:
parameters (dict[str, Any]) – AltiData’s diagnostic parameters.
section (str | None) – Section of the report in which this diagnostic will be used.
properties (SectionProperties) – Section properties
report (list[SectionConfiguration]) – List of report’s section configuration where this diagnostic is used.
- custom_conf(sources, nb, with_store=True)
Format provided diagnostic configuration as a custom diagnostic.
- data_conf(source)
Dump the diagnostic configuration.
- Parameters:
source (
SourceConfiguration
) – Source for which to generate the configuration.- Return type:
- Returns:
Diagnostic configuration as a dictionary.
- initialize(field, conf_report)
Initialize this diagnostic by sorting and expanding its sections.
Provided properties are propagated to expanded sections.
- Parameters:
field (
NamedSectionBase
) – Field’s section properties.conf_report (
ReportProperties
) – Report’s properties.
- parameters: dict[str, Any]
- property path: SectionPath
- properties: SectionProperties
- report: list[SectionConfiguration]
- report_chapters: dict[str, dict[str, SectionConfiguration]]
- report_names: list[str]
- report_properties: ReportProperties = None
- section: str | None = None
- validate_diagnostic_level()
Validate the properties defined at the diagnostic level.
- Raises:
ReportConfiguratorError – If split_per_diag properties are defined.
- class casys.report.configurator.FieldConfiguration(name=None, source=None, source_aux=None, subfields=None, unit=None, description='', interpolation=None, attributes=<factory>, section=None, properties=<factory>, diagnostics=<factory>)
Bases:
NamedSectionBase
,FieldBase
Class representing the configuration’s information of a field.
- Parameters:
name (str | None) – Name of the field.
source (str | None) –
Name of the field in the data source (can be a clip). WARNING: Clip’s operator syntax might change depending on the source’s type.
Dataset sources might require vector operator: :==, :!=, :<, :<=, :>, :>=
CLS Table sources require scalar operators: ==, !=, <, <=, >, >=
source_aux (str | None) – Alternative name of the field in the data source (can be a clip). This attribute might be used for multi-missions crossovers.
subfields (list[FieldBase] | None) – List of subfields used in the source of this field. This might be useful when creating fields as clip from a MultiReader. Each subfield have to belong to single reader and will be computed before any reader post-processing (such as interpolation).
unit (cfu_t.Unit | str | None) – Unit of the field.
description (str) – Description of the field.
interpolation (str | dict[str, Any] | InterpolationOptions | None) –
Interpolation options. Can be provided using an InterpolationOptions object or a dictionary containing ‘mode’ and ‘noise_level’ keys: {‘mode’: ‘smoothing_spline’, noise_level: 0.1} or a string containing only the ‘mode’.
- mode
Interpolation mode to use when interpolating along a reference track. Accepted values are linear, nearest or smoothing_spline.
- noise_level
Only required for the smoothing_spline mode. Estimated noise level in the signal. Oscillations lower that this value will be removed by the smoothing spline.
attributes (dict[str, Any]) – Additional information.
section (str | None) – Section of the report in which this diagnostic will be used.
properties (SectionProperties) – Section properties
diagnostics (list[DiagnosticConfiguration]) – List of field’s related diagnostics’ configuration.
- attributes: dict[str, Any]
- classmethod consolidate_sections(section)
Recursively set missing section configuration title when containing subsections.
- Parameters:
section (
SectionConfiguration
) – SectionConfiguration object.
- description: str = ''
- diagnostics: list[DiagnosticConfiguration]
- initialize(properties)
Initialize current field sections and properties.
- Parameters:
properties (
ReportProperties
) – Additional properties to take into account.
- interpolation: str | dict[str, Any] | InterpolationOptions | None = None
- is_similar(field)
Test whether both fields are equivalent or not.
Similar fields have identical properties with an exception
- name: str | None = None
- property path: SectionPath
- properties: SectionProperties
- report_names: list[str]
- reports: dict[str, ReportContent]
- section: str | None = None
- source: str | None = None
- source_aux: str | None = None
- storage_field()
Storage (DiagnosticField) representation of this field.
- Return type:
- subfields: list[FieldBase] | None = None
- unit: cfu_t.Unit | str | None = None
- class casys.report.configurator.MultiMissionPolicy(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
Different types of multi-mission display policies.
- GRID = 4
- NONE = 1
- SEQUENTIAL = 2
- STACK = 3
- class casys.report.configurator.MultiMissionPolicyField(*, load_default=<marshmallow.missing>, missing=<marshmallow.missing>, dump_default=<marshmallow.missing>, default=<marshmallow.missing>, data_key=None, attribute=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, error_messages=None, metadata=None, **additional_metadata)
Bases:
BaseEnumField
Marshmallow MultiMissionPolicy field.
- Parameters:
- property default
- default_error_messages: dict[str, str] = {'null': 'Field may not be null.', 'required': 'Missing data for required field.', 'validator_failed': 'Invalid value.'}
Default error messages for various kinds of errors. The keys in this dictionary are passed to Field.make_error. The values are error messages passed to
marshmallow.exceptions.ValidationError
.
- deserialize(value, attr=None, data=None, **kwargs)
Deserialize
value
.- Parameters:
- Raises:
ValidationError – If an invalid value is passed or if a required value is missing.
- fail(key, **kwargs)
Helper method that raises a ValidationError with an error message from
self.error_messages
.Deprecated since version 3.0.0: Use make_error <marshmallow.fields.Field.make_error> instead.
- Parameters:
key (
str
)
- get_value(obj, attr, accessor=None, default=<marshmallow.missing>)
Return the value for a given key from an object.
- make_error(key, **kwargs)
Helper method to make a ValidationError with an error message from
self.error_messages
.- Parameters:
key (
str
)- Return type:
ValidationError
- property missing
- serialize(attr, obj, accessor=None, **kwargs)
Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
- class casys.report.configurator.PlotOperatorDiagnostic(field, *, operator, data_name, stat)
Bases:
ReportDiagnostic
Diagnostic allowing to combine plots from different sources.
- Parameters:
field (Field)
operator (str)
data_name (str)
stat (str)
- REQUIRE_COMPUTE: ClassVar[bool] = False
- REQUIRE_REPORT_CONTENT: ClassVar[bool] = True
- compute(data)
Diagnostic computation.
Diagnostic results have to be stored into the class itself.
- Parameters:
data (
list
[CommonData
]) – Computed AltiData related to each source.
- data_name: str
- field: Field
- classmethod get(name)
- Parameters:
name (
str
)- Return type:
TypeVar
(ReportDiagnosticType
, bound=ReportDiagnostic
)
- classmethod load(name)
Load a previously stored diagnostic object.
- Parameters:
name (
str
|Path
) – Path and name of the stored diagnostic.- Return type:
TypeVar
(ReportDiagnosticType
, bound=ReportDiagnostic
)- Returns:
The loaded diagnostic.
- operator: str
- report_content(data, template=None, data_params=None, plot_params=None, text_params=None, **kwargs)
Diagnostic representation. This method will generate the content displayed into a report’s section.
- Parameters:
data (
list
[CommonData
]) – Computed CommonData related to each source.template (
PlotTemplate
) – Global plot’s template.data_params (
DataParams
) – Plot’s data parameters.plot_params (
PlotParams
) – Plot’s general parameters.text_params (
TextParams
) – Plot’s text parameters.kwargs – Additional parameters.
- stat: str
- class casys.report.configurator.PlotOperatorDiagnosticSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
ReportDiagnosticBaseSchema
Marshmallow schema for the PlotOperatorDiagnostic class.
- 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.
- 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()
In addition to registering the custom diagnostic, this function generates schemas allowing the diagnostic to be used in reports (and dumped as code).
- 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.report.configurator.ReportConfigurator(fields, data_type=DataContainerType.NADIR, properties=<factory>, imports=None)
Bases:
object
Class allowing to configure and generate reports.
- Parameters:
data_type (
DataContainerType
) – Type of data (nadir or swath).fields (
list
[FieldConfiguration
]) – List of fields’ configuration.properties (
ReportProperties
) – Report properties.imports (
dict
[str
,Any
] |None
) – Imported plugins specification.
- chapters_diagnostics(report=None, chapters=None)
Diagnostics for the provided report including requested chapters. Diagnostics are sorted per chapters.
- Parameters:
- Return type:
- Returns:
Dictionary of chapters with their diagnostics’ configuration.
- compute_data(sources, date_start=None, date_end=None, report=None, chapters=None, dask_params=None)
Compute and store data for the provided source.
- Parameters:
sources (
SourceConfiguration
|list
[SourceConfiguration
]) – Sources for which to do the computation.report (
str
|None
) – Report to compute. Default to a report containing everything.dask_params (
dict
[str
,Any
] |None
) –‘compute_dask’ method parameters including:
freq
jobs_number
dask_client
- Return type:
- Returns:
Dictionary of source’s name for which the computation was completed associated to their computed data.
-
data_type:
DataContainerType
= 1
-
fields:
list
[FieldConfiguration
]
- initialize(properties=None)
Sets fields, diagnostics and report’s section.
- Parameters:
properties (
ReportProperties
|None
) – Additional properties to take into account.
- classmethod load(conf, context=None, properties=None)
Generate a ReportConfigurator based on the provided configuration and properties.
- Parameters:
conf (
str
|dict
) – Configuration to load (as a dictionary or file name).context (
dict
|None
) – Jinja context used to read provided configuration file.properties (
ReportProperties
|None
) – Additional properties used by the ReportConfigurator. These properties have a lower priority than the ones included in the ‘conf’.
- Return type:
- Returns:
A new, initialized, ReportConfigurator.
-
properties:
ReportProperties
- report_chapters(report=None)
List existing chapters for the provided report.
- report_content(sources, report=None, chapters=None, date_start=None, date_end=None)
Generate a report limited to the content part.
- Parameters:
sources (
SourceConfiguration
|list
[SourceConfiguration
]) – Sources for which to generate the report.report (
str
|None
) – Name of the report. Default to a report containing everything.
- Return type:
- Returns:
Generated Casys’ report.
- report_content_conf(sources, report=None, ch_names=None)
Generate the report’s content.
- Parameters:
- Return type:
- Returns:
Dictionary representing the report’s content configuration.
- report_data(sources, date_start=None, date_end=None, report=None, chapters=None)
Generate a report limited to the data part.
- Parameters:
sources (
SourceConfiguration
|list
[SourceConfiguration
]) – Sources for which to generate the report.report (
str
|None
) – Name of the report. Default to a report containing everything.
- Return type:
- Returns:
Generated Casys’ report.
- report_data_conf(sources, date_start=None, date_end=None, report=None, ch_names=None, compute=True, store=True)
Generate the report’s data part.
- Parameters:
sources (
list
[SourceConfiguration
]) – Sources for which to generate data.report (
str
|None
) – Report’s name. Default to a report containing everything.ch_names (
str
|list
[str
] |None
) – Included chapters’ list (default to all chapters).compute (
bool
) – Whether to add computation operation to each source or not.store (
bool
) – Whether to add store operation to each data or not.
- Return type:
- Returns:
Dictionary representing the report’s data configuration.
- report_full(sources, date_start=None, date_end=None, report=None, chapters=None, store=False)
Generate a full report including the data and report’s content parts.
- Parameters:
sources (
SourceConfiguration
|list
[SourceConfiguration
]) – Sources for which to generate the report.report (
str
|None
) – Name of the report. Default to a report containing everything.store (
bool
) – Whether to store data or not.
- Return type:
- Returns:
Generated Casys’ report.
- exception casys.report.configurator.ReportConfiguratorError
Bases:
Exception
Exception raised when a problem related to report configuration occurs.
- add_note(object, /)
Exception.add_note(note) – add a note to the exception
- args
- with_traceback(object, /)
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class casys.report.configurator.ReportConfiguratorSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
BaseSchema
Marshmallow schema for ReportConfigurator.
- 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'>}
- 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_model()
Return the model associated to this schema.
- 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, **_)
- set_class
alias of
OrderedSet
- 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.report.configurator.ReportDiagnostic(field)
Bases:
ABC
Base class to create custom diagnostics usable in a ReportGenerator.
- Parameters:
field (
Field
) – Automatically generated field.
- compute(data)
Diagnostic computation.
Diagnostic results have to be stored into the class itself.
- Parameters:
data (
list
[CommonData
]) – Computed AltiData related to each source.
- classmethod get(name)
- Parameters:
name (
str
)- Return type:
TypeVar
(ReportDiagnosticType
, bound=ReportDiagnostic
)
- classmethod load(name)
Load a previously stored diagnostic object.
- Parameters:
name (
str
|Path
) – Path and name of the stored diagnostic.- Return type:
TypeVar
(ReportDiagnosticType
, bound=ReportDiagnostic
)- Returns:
The loaded diagnostic.
- report_content(data, template=None, data_params=None, plot_params=None, text_params=None, *args, **kwargs)
Diagnostic representation. This method will generate the content displayed into a report’s section.
- Parameters:
data (
list
[CommonData
]) – Computed CommonData related to each source.template (
PlotTemplate
) – Global plot’s template.data_params (
DataParams
) – Plot’s data parameters.plot_params (
PlotParams
) – Plot’s general parameters.text_params (
TextParams
) – Plot’s text parameters.kwargs – Additional parameters.
- class casys.report.configurator.ReportDiagnosticBaseSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
ReportDiagnosticSimpleBaseSchema
- 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.
- 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()
In addition to registering the custom diagnostic, this function generates schemas allowing the diagnostic to be used in reports (and dumped as code).
- 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.report.configurator.ReportDiagnosticGenericSchema(**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, **kwargs)
- 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.report.configurator.ReportProperties(common=<factory>, templates=<factory>, sections=<factory>, diagnostics=<factory>, frequencies=<factory>, statistics=<factory>)
Bases:
object
Class containing text properties (title and text) for different elements.
- Parameters:
common (
SectionProperties
) – Common report’s properties.templates (
dict
[str
,dict
]) – Set of templates that will be registered and available in the generated report.sections (
dict
[str
,SectionProperties
]) – Section’s properties. The order in which sections are defined is used to define the order of sections in reports.diagnostics (
dict
[str
,SectionProperties
]) – Diagnostics type properties. Diagnostics type are ‘raw’, ‘temporal’, ‘geobox’, …frequencies (
dict
[FreqType
,SectionProperties
]) – Frequencies properties. Frequencies are ‘cycle’, ‘pass’, ‘day’, …statistics (
dict
[StatType
,SectionProperties
]) – Statistics properties. Statistics are ‘count’, ‘mean’, ‘med’, …
-
common:
SectionProperties
- diagnostic(diag)
Properties for the requested diagnostic. Default properties using the diag name as title are returned if not included.
- Parameters:
diag (
str
) – Name of the diagnostic (raw, geobox, temporal, …)- Return type:
SectionProperties
- Returns:
Text and plot properties.
- frequency(freq)
Properties for the requested frequency. Default properties using the diag name as title are returned if not included.
- Parameters:
freq (
FrequencyHandler
) – Name of the frequency (cycle, pass, day, …)- Return type:
SectionProperties
- Returns:
Text and plot properties.
- section(path)
Properties for the requested section’s path. Default properties are returned if not included.
- Parameters:
path (
SectionPath
) – Path of the section.- Return type:
SectionProperties
- Returns:
Text and plot properties.
- statistic(stat)
Properties for the requested statistic. Default properties using the stat name as title are returned if not included.
- update(config)
Update report’s properties with the providing ones.
- Parameters:
config (
ReportProperties
|None
) – Properties from which to update.
- class casys.report.configurator.ReportPropertiesSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
BaseSchema
ReportProperties’ 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'>}
- 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_model()
Return the model associated to this schema.
- 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, **_)
- set_class
alias of
OrderedSet
- 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.report.configurator.ReportSources(database, ges_table_dir=None, time_extension=None)
Bases:
object
Report’s sources configuration.
- Parameters:
- db_source(mission, timeliness)
Return the requested data’s source.
- Parameters:
- Return type:
- Returns:
Corresponding data’s source.
- db_timeliness(mission)
Return available mission’s timeliness.
- classmethod load(conf, context=None)
Generate a ReportSources based on the provided configuration.
- Parameters:
- Return type:
- Returns:
A new, initialized, ReportConfigurator.
- class casys.report.configurator.ReportSourcesSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
BaseSchema
ReportSources’ 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'>}
- 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_model()
Return the model associated to this schema.
- 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, **_)
- set_class
alias of
OrderedSet
- 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.report.configurator.SectionConfiguration(section=None, properties=<factory>, *, reports=<factory>, data_name=None, diag_type=None, parameters=<factory>, place_holder=False, report_properties=<factory>, default_report=True)
Bases:
SectionBase
Class representing the configuration of a report’s section.
- Parameters:
reports (
list
[str
]) – List of reports’ name in which this section is included.section (
str
|None
) – Section of the report in which this diagnostic will be used.properties (
SectionProperties
) – Section propertiesplace_holder (
bool
) – Whether this configuration is automatically generated or define with user parameters.report_properties (
ReportProperties
)default_report (
InitVar
)
- add_section(section, level=0, allow_update=True)
Add provided section to this content.
- Parameters:
section (
SectionConfiguration
) – Section to add.level (
int
) – Current ReportSectionContent level.allow_update (
bool
) – Whether to allow this section properties update or not.
- full_report(ctype, sources, sorter=<function SectionConfiguration.<lambda>>)
Convert this sections with its subsections into their report representation.
- Parameters:
ctype (
DataContainerType
) – Data container type.sources (
list
[SourceConfiguration
]) – Sources for which to generate a report.sorter (
Callable
[[SectionConfiguration
],int
]) – Sorter defining sections’ ordering.
- Return type:
- Returns:
Report’s representation of this content.
- holder_section(level)
Generate a new placeholder’s section configuration for the requested level.
- Parameters:
level (
int
) – Level for which to create the configuration.- Return type:
- Returns:
Default SectionConfiguration for the requested level.
- initialize(name, dtype, section, report)
Fill missing information from provided properties.
- Parameters:
name (
str
) – Section’s data name.dtype (
str
) – Section’s data type.section (
SectionProperties
) – Section’s properties.report (
ReportProperties
) – Report’s properties.
- property is_visible: bool
A section is visible if any of its section is visible.
- Returns:
Section visibility.
- merge(s2)
Merge provided configuration into the current one.
- Parameters:
s2 (
SectionConfiguration
) – Second section to merge.- Returns:
New ReportChapterContent containing both contents.
- new_section(path, title, text)
Create a new section inhering current properties.
- Parameters:
- Return type:
- Returns:
New section.
- property path: SectionPath
- path_sections(conf_field, conf_diag, diag_type, freq)
Generate the list of section required to build the path of the current one.
- Parameters:
conf_field (
NamedSectionBase
) – Field’s configuration.conf_diag (
DiagnosticConfiguration
) – Diagnostic configuration.diag_type (
str
) – Type of diagnostic.freq (
FrequencyHandler
|None
) – Frequency of the diagnostic.
- Return type:
- Returns:
List of required section.
-
properties:
SectionProperties
-
report_properties:
ReportProperties
- single_stat_sections(stat)
Create new report’s sections configuration specific to the provided statistic.
- Parameters:
stat (
str
) – Statistic for which to set the configuration.- Return type:
- Returns:
Sections required to include the requested statistic.
- stats_sections(stats)
Create report’s sections configuration for the provided statistics.
-
sub_sections:
dict
[str
,SectionConfiguration
]
- update_light(section)
Light merging: union of reports.
- Parameters:
section (
SectionConfiguration
) – Section to merge.
- update_section(section)
Update current section parameters by the provided one.
- Parameters:
section (
SectionConfiguration
) – Section from which to get new parameters.
- validate_report_level()
Validate the properties defined at the report level.
- Raises:
ReportConfiguratorError – If text or split_per_diag properties are defined.
- class casys.report.configurator.SectionConfigurationSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
SectionBaseSchema
Marshmallow schema for SectionConfiguration.
- 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'>}
- 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_model()
Return the model associated to this schema.
- 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, **_)
- set_class
alias of
OrderedSet
- 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.report.configurator.SectionOrderType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
Different types of section naming policies.
- DIAG_FIRST = 3
- FIELD_FIRST = 2
- NONE = 1
- class casys.report.configurator.SectionOrderTypeField(*, load_default=<marshmallow.missing>, missing=<marshmallow.missing>, dump_default=<marshmallow.missing>, default=<marshmallow.missing>, data_key=None, attribute=None, validate=None, required=False, allow_none=None, load_only=False, dump_only=False, error_messages=None, metadata=None, **additional_metadata)
Bases:
BaseEnumField
Marshmallow SectionOrderType field.
- Parameters:
- property default
- default_error_messages: dict[str, str] = {'null': 'Field may not be null.', 'required': 'Missing data for required field.', 'validator_failed': 'Invalid value.'}
Default error messages for various kinds of errors. The keys in this dictionary are passed to Field.make_error. The values are error messages passed to
marshmallow.exceptions.ValidationError
.
- deserialize(value, attr=None, data=None, **kwargs)
Deserialize
value
.- Parameters:
- Raises:
ValidationError – If an invalid value is passed or if a required value is missing.
- fail(key, **kwargs)
Helper method that raises a ValidationError with an error message from
self.error_messages
.Deprecated since version 3.0.0: Use make_error <marshmallow.fields.Field.make_error> instead.
- Parameters:
key (
str
)
- get_value(obj, attr, accessor=None, default=<marshmallow.missing>)
Return the value for a given key from an object.
- make_error(key, **kwargs)
Helper method to make a ValidationError with an error message from
self.error_messages
.- Parameters:
key (
str
)- Return type:
ValidationError
- property missing
- serialize(attr, obj, accessor=None, **kwargs)
Pulls the value for the given key from the object, applies the field’s formatting and returns the result.
- class casys.report.configurator.SourceConfiguration(reference, source, data_dir=None, store=None, time_extension=None, fields=<factory>, theoretical_orf=None, reference_track=None, name=None, plot_params=None)
Bases:
object
Data source specification.
- Parameters:
reference (
str
) – Source’s reference name when used in AltiData.time_extension (
bool
|None
) – Whether to allow the extension of user defined time interval for specific diagnostic requirements or not.data_dir (
Path
|str
|None
) – Directory into which to store data.store (
dict
[str
,str
] |None
) –Storage specifications.
store: store path
analyse_type: type of analyse (cycle, pass or custom).
analyse_date: for custom types, date to tag this analyse with
groups: dictionary of diagnostic names and their specific store’s group name
fields (
dict
[str
,FieldBase
]) – Mission’s fields definition. These field’s parameters will overwrite the ones from the report configuration.theoretical_orf (
str
|None
) – Theoretical orf name or path.reference-track – Reference track name or path.
plot_params (
PlotParams
|None
) – Mission specific plot parameters.
- compute(data, diags)
Compute specified diagnostics with the provided AltiData.
- compute_custom_diag(data, section, diag_ref)
Compute provided custom diagnostic.
- Parameters:
data (
list
[CommonData
]) – List of computed AltiData available to the diagnostic.section (
ReportSection
) – Report’s section containing the custom diagnostic specifications.diag_ref (
str
) – Reference of the custom diagnostic.
- compute_dask(data, diags, parameters)
Compute specified diagnostics using dask with the provided AltiData.
- Parameters:
- data_path(name)
Generate the data path for the provided name.
-
plot_params:
PlotParams
|None
= None
- report_configuration()
Source representation in a report only configuration.
- set_environment()
Set source required environment variables.
- set_plot_params(data, mtype)
- Parameters:
mtype (
MultiMissionPolicy
)
- store_diagnostic_pickle(diag, diag_ref)
Store provided diagnostic as a pickle file. Nothing is done if this source’s
data_file
is not defined.- Parameters:
diag (
TypeVar
(ReportDiagnosticType
, bound=ReportDiagnostic
)) – Diagnostic to store.diag_ref (
str
) – Diagnostic reference.
- store_diagnostics(data)
Store provided data in a diagnostic store. Nothing is done if this source’s
store
is not defined.- Parameters:
data (
CommonData
) – Data to store.
- store_pickle(data)
Store provided data as a pickle file. Nothing is done if this source’s
data_file
is not defined.- Parameters:
data (
CommonData
) – Data to store.
- class casys.report.configurator.SourceConfigurationSchema(*, only=None, exclude=(), many=None, context=None, load_only=(), dump_only=(), partial=None, unknown=None)
Bases:
BaseSchema
SourceConfiguration’s 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'>}
- 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_model()
Return the model associated to this schema.
- 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, **_)
- set_class
alias of
OrderedSet
- 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.report.configurator.set_diag_name(param, diag_type, field_name)
Create a diagnostic name if not included in provided parameters.
‘param’ parameter might be modified.