minos.aggregate.models.diffs.fields module¶
- class minos.aggregate.models.diffs.fields.FieldDiff(name, type_, value, **kwargs)[source]¶
Bases:
minos.common.model.abc.Model
,Generic
[minos.aggregate.models.diffs.fields.T
]Field Diff class.
- __init__(name, type_, value, **kwargs)[source]¶
Class constructor.
- Parameters
fields – Dictionary that contains the
Field
instances of the model indexed by name.
- property avro_bytes: bytes¶
Generate bytes representation of the current instance.
- Return type
bytes
- Returns
A bytes object.
- property avro_data: dict[str, typing.Any]¶
Compute the avro data of the model.
- Return type
dict
[str
,typing.Any
]- Returns
A dictionary object.
- avro_schema = [{'name': 'FieldDiff', 'namespace': 'minos.aggregate.models.diffs.fields.d9f3e59b-79fe-45bf-ad24-50367754b9b7', 'type': 'record', 'fields': []}]¶
- property avro_str: str¶
Generate bytes representation of the current instance.
- Return type
str
- Returns
A bytes object.
- classname = 'minos.aggregate.models.diffs.fields.FieldDiff'¶
- classmethod decode_data(decoder, target, type_, **kwargs)¶
Decode data with the given decoder.
- Parameters
decoder (
minos.common.model.serializers.abc.DataDecoder
) – The decoder instance.target (
typing.Any
) – The data to be decoded.type – The data type.
kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
A decoded instance.
- classmethod decode_schema(decoder, target, **kwargs)¶
Decode schema with the given encoder.
- Parameters
decoder (
minos.common.model.serializers.abc.SchemaDecoder
) – The decoder instance.target (
typing.Any
) – The schema to be decoded.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The decoded schema as a type.
- encode_data(encoder, target, **kwargs)¶
Encode data with the given encoder.
- Parameters
encoder (
minos.common.model.serializers.abc.DataEncoder
) – The encoder instance.target (
typing.Any
) – An optional pre-encoded data.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The encoded data of the instance.
- classmethod encode_schema(encoder, target, **kwargs)¶
Encode schema with the given encoder.
- Parameters
encoder (
minos.common.model.serializers.abc.SchemaEncoder
) – The encoder instance.target (
typing.Any
) – An optional pre-encoded schema.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The encoded schema of the instance.
- property fields: dict[str, minos.common.model.fields.Field]¶
Fields getter
- Return type
dict
[str
,minos.common.model.fields.Field
]
- classmethod from_avro(schema, data)¶
Build a new instance from the
avro
schema and data.- Parameters
schema (
typing.Any
) – The avro schema of the model.data (
typing.Any
) – The avro data of the model.
- Return type
~T
- Returns
A new
DynamicModel
instance.
- classmethod from_avro_bytes(raw, batch_mode=False, **kwargs)¶
Build a single instance or a sequence of instances from bytes
- Parameters
raw (
bytes
) – Abytes
representation of the model.batch_mode (
bool
) – IfTrue
the data is processed as a list of models, otherwise the data is processed as a
single model. :param kwargs: Additional named arguments. :rtype:
typing.Union
[~T,list
[~T]] :return: A single instance or a sequence of instances.
- classmethod from_avro_str(raw, **kwargs)¶
Build a single instance or a sequence of instances from bytes
- Parameters
raw (
str
) – Astr
representation of the model.- Return type
typing.Union
[~T,list
[~T]]- Returns
A single instance or a sequence of instances.
- classmethod from_model_type(model_type, *args, **kwargs)[source]¶
Build a new instance from model type.
- Parameters
model_type (
minos.common.model.types.model_types.ModelType
) – The model type.args – Additional positional. arguments.
kwargs – Additional named arguments.
- Return type
- Returns
A new
FieldDiff
instance.
- classmethod from_typed_dict(typed_dict, *args, **kwargs)¶
Build a
Model
from aTypeDict
anddata
.- Parameters
typed_dict (
typing.TypedDict
) –TypeDict
object containing the DTO’s structureargs – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Return type
~T
- Returns
A new
DataTransferObject
instance.
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- model_type¶
alias of
minos.common.model.types.model_types.FieldDiff
- name: str¶
- classmethod to_avro_bytes(models)¶
Create a
bytes
representation of the given object instances.- Parameters
models (
list
[~T]) – A sequence of minos models.- Return type
bytes
- Returns
A bytes object.
- classmethod to_avro_str(models)¶
Build the avro string representation of the given object instances.
- Parameters
models (
list
[~T]) – A sequence of minos models.- Return type
str
- Returns
A bytes object.
- type_hints = {}¶
- type_hints_parameters = (~T,)¶
- value: minos.aggregate.models.diffs.fields.T¶
- values() an object providing a view on D's values ¶
- class minos.aggregate.models.diffs.fields.FieldDiffContainer(diffs=None, fields=None, **kwargs)[source]¶
Bases:
minos.common.model.dynamic.bucket.BucketModel
Field Diff Container class.
- __init__(diffs=None, fields=None, **kwargs)[source]¶
Class constructor.
- Parameters
fields (
typing.Union
[typing.Iterable
[minos.common.model.fields.Field
],dict
[str
,minos.common.model.fields.Field
],None
]) – Dictionary that contains theField
instances of the model indexed by name.
- property avro_bytes: bytes¶
Generate bytes representation of the current instance.
- Return type
bytes
- Returns
A bytes object.
- property avro_data: dict[str, typing.Any]¶
Compute the avro data of the model.
- Return type
dict
[str
,typing.Any
]- Returns
A dictionary object.
- avro_schema = [{'name': 'FieldDiffContainer', 'namespace': 'minos.aggregate.models.diffs.fields.8fa276d2-9be9-4a2a-aa35-0bf72b4d4690', 'type': 'record', 'fields': []}]¶
- property avro_str: str¶
Generate bytes representation of the current instance.
- Return type
str
- Returns
A bytes object.
- classname = 'minos.aggregate.models.diffs.fields.FieldDiffContainer'¶
- classmethod decode_data(decoder, target, type_, **kwargs)¶
Decode data with the given decoder.
- Parameters
decoder (
minos.common.model.serializers.abc.DataDecoder
) – The decoder instance.target (
typing.Any
) – The data to be decoded.type – The data type.
kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
A decoded instance.
- classmethod decode_schema(decoder, target, **kwargs)¶
Decode schema with the given encoder.
- Parameters
decoder (
minos.common.model.serializers.abc.SchemaDecoder
) – The decoder instance.target (
typing.Any
) – The schema to be decoded.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The decoded schema as a type.
- classmethod empty()¶
Build an empty
BucketModel
instance.- Return type
~T
- Returns
A
BucketModel
instance.
- encode_data(encoder, target, **kwargs)¶
Encode data with the given encoder.
- Parameters
encoder (
minos.common.model.serializers.abc.DataEncoder
) – The encoder instance.target (
typing.Any
) – An optional pre-encoded data.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The encoded data of the instance.
- classmethod encode_schema(encoder, target, **kwargs)¶
Encode schema with the given encoder.
- Parameters
encoder (
minos.common.model.serializers.abc.SchemaEncoder
) – The encoder instance.target (
typing.Any
) – An optional pre-encoded schema.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The encoded schema of the instance.
- property fields: dict[str, minos.common.model.fields.Field]¶
Fields getter
- Return type
dict
[str
,minos.common.model.fields.Field
]
- flatten_items()[source]¶
Get the field differences in a flatten way.
- Return type
typing.Iterator
[tuple
[str
,minos.aggregate.models.diffs.fields.FieldDiff
]]- Returns
An
Iterator
oftuple[str, FieldDiff]
instances.
- flatten_values()[source]¶
Get the field differences in a flatten way.
- Return type
typing.Iterator
[minos.aggregate.models.diffs.fields.FieldDiff
]- Returns
An
Iterator
ofFieldDiff
instances.
- classmethod from_avro(schema, data)¶
Build a new instance from the
avro
schema and data.- Parameters
schema (
typing.Any
) – The avro schema of the model.data (
typing.Any
) – The avro data of the model.
- Return type
~T
- Returns
A new
DynamicModel
instance.
- classmethod from_avro_bytes(raw, batch_mode=False, **kwargs)¶
Build a single instance or a sequence of instances from bytes
- Parameters
raw (
bytes
) – Abytes
representation of the model.batch_mode (
bool
) – IfTrue
the data is processed as a list of models, otherwise the data is processed as a
single model. :param kwargs: Additional named arguments. :rtype:
typing.Union
[~T,list
[~T]] :return: A single instance or a sequence of instances.
- classmethod from_avro_str(raw, **kwargs)¶
Build a single instance or a sequence of instances from bytes
- Parameters
raw (
str
) – Astr
representation of the model.- Return type
typing.Union
[~T,list
[~T]]- Returns
A single instance or a sequence of instances.
- classmethod from_difference(a, b, ignore=frozenset({}))[source]¶
Build a new instance from the difference between two models.
- Parameters
a (
minos.common.model.abc.Model
) – Latest model instance.b (
minos.common.model.abc.Model
) – Oldest model instance.ignore (
set
[str
]) – Set of fields to be ignored.
- Return type
- Returns
A new
FieldDiffContainer
instance.
- classmethod from_model(model, ignore=frozenset({}))[source]¶
Build a new difference from a single model.
- Parameters
model (
minos.common.model.abc.Model
) – The model instance.ignore (
set
[str
]) – Set of fields to be ignored.
- Return type
- Returns
A new
FieldDiffContainer
instance.
- classmethod from_model_type(model_type, *args, **kwargs)¶
Build a
DynamicModel
from aModelType
.- Parameters
model_type (
minos.common.model.types.model_types.ModelType
) –ModelType
object containing the model structureargs – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Return type
~T
- Returns
A new
DynamicModel
instance.
- classmethod from_typed_dict(typed_dict, *args, **kwargs)¶
Build a
Model
from aTypeDict
anddata
.- Parameters
typed_dict (
typing.TypedDict
) –TypeDict
object containing the DTO’s structureargs – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Return type
~T
- Returns
A new
DataTransferObject
instance.
- static generate_random_str()[source]¶
Generate a random string
- Return type
str
- Returns
A random string value.
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- get_all(return_diff=True)[source]¶
Get a dictionary containing all names as keys and all the values of each one as values.
- Parameters
return_diff (
bool
) – IfTrue
the result is returned as field diff instances, otherwise the result is returned as value instances.- Return type
dict
[str
,typing.Union
[minos.aggregate.models.diffs.fields.FieldDiff
,typing.Any
,list
[minos.aggregate.models.diffs.fields.FieldDiff
],list
[typing.Any
]]]- Returns
A
dict
withstr
keys andlist[Any]
values.
- get_one(name, return_diff=True)[source]¶
Get first field diff with given name.
- Parameters
name (
str
) – The name of the field diff.return_diff (
bool
) – IfTrue
the result is returned as field diff instances, otherwise the result is returned as value instances.
- Return type
typing.Union
[minos.aggregate.models.diffs.fields.FieldDiff
,typing.Any
,list
[minos.aggregate.models.diffs.fields.FieldDiff
],list
[typing.Any
]]- Returns
A
FieldDiff
instance.
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- model_type¶
alias of
minos.common.model.types.model_types.FieldDiffContainer
- classmethod to_avro_bytes(models)¶
Create a
bytes
representation of the given object instances.- Parameters
models (
list
[~T]) – A sequence of minos models.- Return type
bytes
- Returns
A bytes object.
- classmethod to_avro_str(models)¶
Build the avro string representation of the given object instances.
- Parameters
models (
list
[~T]) – A sequence of minos models.- Return type
str
- Returns
A bytes object.
- type_hints = {}¶
- type_hints_parameters = ()¶
- values() an object providing a view on D's values ¶
- class minos.aggregate.models.diffs.fields.IncrementalFieldDiff(name, type_, value, action, **kwargs)[source]¶
Bases:
minos.aggregate.models.diffs.fields.FieldDiff
,Generic
[minos.aggregate.models.diffs.fields.T
]Incremental Field Diff class.
- __init__(name, type_, value, action, **kwargs)[source]¶
Class constructor.
- Parameters
fields – Dictionary that contains the
Field
instances of the model indexed by name.
- property avro_bytes: bytes¶
Generate bytes representation of the current instance.
- Return type
bytes
- Returns
A bytes object.
- property avro_data: dict[str, typing.Any]¶
Compute the avro data of the model.
- Return type
dict
[str
,typing.Any
]- Returns
A dictionary object.
- avro_schema = [{'name': 'IncrementalFieldDiff', 'namespace': 'minos.aggregate.models.diffs.fields.febe3293-ba45-4858-8bb1-98ca0a792824', 'type': 'record', 'fields': []}]¶
- property avro_str: str¶
Generate bytes representation of the current instance.
- Return type
str
- Returns
A bytes object.
- classname = 'minos.aggregate.models.diffs.fields.IncrementalFieldDiff'¶
- classmethod decode_data(decoder, target, type_, **kwargs)¶
Decode data with the given decoder.
- Parameters
decoder (
minos.common.model.serializers.abc.DataDecoder
) – The decoder instance.target (
typing.Any
) – The data to be decoded.type – The data type.
kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
A decoded instance.
- classmethod decode_schema(decoder, target, **kwargs)¶
Decode schema with the given encoder.
- Parameters
decoder (
minos.common.model.serializers.abc.SchemaDecoder
) – The decoder instance.target (
typing.Any
) – The schema to be decoded.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The decoded schema as a type.
- encode_data(encoder, target, **kwargs)¶
Encode data with the given encoder.
- Parameters
encoder (
minos.common.model.serializers.abc.DataEncoder
) – The encoder instance.target (
typing.Any
) – An optional pre-encoded data.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The encoded data of the instance.
- classmethod encode_schema(encoder, target, **kwargs)¶
Encode schema with the given encoder.
- Parameters
encoder (
minos.common.model.serializers.abc.SchemaEncoder
) – The encoder instance.target (
typing.Any
) – An optional pre-encoded schema.kwargs – Additional named arguments.
- Return type
typing.Any
- Returns
The encoded schema of the instance.
- property fields: dict[str, minos.common.model.fields.Field]¶
Fields getter
- Return type
dict
[str
,minos.common.model.fields.Field
]
- classmethod from_avro(schema, data)¶
Build a new instance from the
avro
schema and data.- Parameters
schema (
typing.Any
) – The avro schema of the model.data (
typing.Any
) – The avro data of the model.
- Return type
~T
- Returns
A new
DynamicModel
instance.
- classmethod from_avro_bytes(raw, batch_mode=False, **kwargs)¶
Build a single instance or a sequence of instances from bytes
- Parameters
raw (
bytes
) – Abytes
representation of the model.batch_mode (
bool
) – IfTrue
the data is processed as a list of models, otherwise the data is processed as a
single model. :param kwargs: Additional named arguments. :rtype:
typing.Union
[~T,list
[~T]] :return: A single instance or a sequence of instances.
- classmethod from_avro_str(raw, **kwargs)¶
Build a single instance or a sequence of instances from bytes
- Parameters
raw (
str
) – Astr
representation of the model.- Return type
typing.Union
[~T,list
[~T]]- Returns
A single instance or a sequence of instances.
- classmethod from_model_type(model_type, *args, **kwargs)¶
Build a new instance from model type.
- Parameters
model_type (
minos.common.model.types.model_types.ModelType
) – The model type.args – Additional positional. arguments.
kwargs – Additional named arguments.
- Return type
- Returns
A new
FieldDiff
instance.
- classmethod from_typed_dict(typed_dict, *args, **kwargs)¶
Build a
Model
from aTypeDict
anddata
.- Parameters
typed_dict (
typing.TypedDict
) –TypeDict
object containing the DTO’s structureargs – Positional arguments to be passed to the model constructor.
kwargs – Named arguments to be passed to the model constructor.
- Return type
~T
- Returns
A new
DataTransferObject
instance.
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D's items ¶
- keys() a set-like object providing a view on D's keys ¶
- model_type¶
alias of
minos.common.model.types.model_types.IncrementalFieldDiff
- name: str¶
- classmethod to_avro_bytes(models)¶
Create a
bytes
representation of the given object instances.- Parameters
models (
list
[~T]) – A sequence of minos models.- Return type
bytes
- Returns
A bytes object.
- classmethod to_avro_str(models)¶
Build the avro string representation of the given object instances.
- Parameters
models (
list
[~T]) – A sequence of minos models.- Return type
str
- Returns
A bytes object.
- type_hints = {}¶
- type_hints_parameters = (~T,)¶
- value: minos.aggregate.models.diffs.fields.T¶
- values() an object providing a view on D's values ¶