minos.aggregate.models.collections module

class minos.aggregate.models.collections.IncrementalSet(data=None, *args, **kwargs)[source]

Bases: minos.common.model.declarative.DeclarativeModel, collections.abc.MutableSet, Generic[minos.aggregate.models.collections.T]

Incremental Set class.

__init__(data=None, *args, **kwargs)[source]

Class constructor.

Parameters

kwargs – Named arguments to be set as model attributes.

add(value_object)[source]

Add a value object. :type value_object: ~T :param value_object: The value object to be added. :rtype: None :return: This method does not return anything.

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 = [{'type': 'array', 'items': 'null', 'logicalType': 'minos.aggregate.models.collections.IncrementalSet'}]
property avro_str: str

Generate bytes representation of the current instance.

Return type

str

Returns

A bytes object.

classname = 'minos.aggregate.models.collections.IncrementalSet'
clear()

This is slow (creates N new iterators!) but effective.

data: set[T]
property data_cls: Optional[type]

Get data class if available.

Return type

typing.Optional[type]

Returns

A model type.

classmethod decode_data(decoder, target, type_, **kwargs)[source]

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.

Return type

minos.aggregate.models.collections.IncrementalSet

Returns

A decoded instance.

classmethod decode_schema(decoder, target, **kwargs)[source]

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.

Return type

minos.common.model.types.model_types.ModelType

Returns

The decoded schema as a type.

diff(another)[source]

Compute the difference between self and another entity set. :type another: minos.aggregate.models.collections.IncrementalSet[~T] :param another: Another entity set instance. :rtype: minos.aggregate.models.collections.IncrementalSetDiff :return: The difference between both entity sets.

discard(value_object)[source]

Remove a value object. :type value_object: ~T :param value_object: The value object to be added. :rtype: None :return: This method does not return anything.

static encode_data(encoder, target, **kwargs)[source]

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.

Return type

typing.Any

Returns

The encoded data of the instance.

classmethod encode_schema(encoder, target, **kwargs)[source]

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.

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) – A bytes representation of the model.

  • batch_mode (bool) – If True 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) – A str 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 DeclarativeModel from a ModelType.

Parameters
  • model_type (minos.common.model.types.model_types.ModelType) – ModelType object containing the model structure.

  • args – 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 DeclarativeModel instance.

classmethod from_typed_dict(typed_dict, *args, **kwargs)

Build a Model from a TypeDict and data.

Parameters
  • typed_dict (typing.TypedDict) – TypeDict object containing the DTO’s structure

  • args – 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.
isdisjoint(other)

Return True if two sets have a null intersection.

items() a set-like object providing a view on D's items
keys() a set-like object providing a view on D's keys
pop()

Return the popped value. Raise KeyError if empty.

remove(value)

Remove an element. If not a member, raise a KeyError.

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,)
values() an object providing a view on D's values
class minos.aggregate.models.collections.IncrementalSetDiff(*args, **kwargs)[source]

Bases: minos.common.model.declarative.DeclarativeModel

Incremental Set Diff class.

__init__(*args, **kwargs)

Class constructor.

Parameters

kwargs – Named arguments to be set as model attributes.

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': 'IncrementalSetDiff', 'namespace': 'minos.aggregate.models.collections.6bf762e4-37ea-4eeb-a9e8-6f7450a71f79', 'type': 'record', 'fields': [{'name': 'diffs', 'type': {'type': 'array', 'items': {'name': 'SetDiffEntry', 'namespace': '', 'type': 'record', 'fields': [{'name': 'action', 'type': {'type': 'string', 'logicalType': 'minos.aggregate.models.actions.Action'}}, {'name': 'entity', 'type': 'null'}]}}}]}]
property avro_str: str

Generate bytes representation of the current instance.

Return type

str

Returns

A bytes object.

classname = 'minos.aggregate.models.collections.IncrementalSetDiff'
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.

diffs: list[IncrementalSetDiffEntry]
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) – A bytes representation of the model.

  • batch_mode (bool) – If True 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) – A str representation of the model.

Return type

typing.Union[~T, list[~T]]

Returns

A single instance or a sequence of instances.

classmethod from_difference(new, old, get_fn=None)[source]

Build a new instance from two entity sets. :type new: minos.aggregate.models.collections.IncrementalSet[~T] :param new: The new entity set. :type old: minos.aggregate.models.collections.IncrementalSet[~T] :param old: The old entity set. :type get_fn: typing.Optional[typing.Callable[[~T], typing.Any]] :param get_fn: Optional function to get entries from the set by identifier. :rtype: minos.aggregate.models.collections.IncrementalSetDiff :return: The difference between new and old.

classmethod from_model_type(model_type, *args, **kwargs)

Build a DeclarativeModel from a ModelType.

Parameters
  • model_type (minos.common.model.types.model_types.ModelType) – ModelType object containing the model structure.

  • args – 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 DeclarativeModel instance.

classmethod from_typed_dict(typed_dict, *args, **kwargs)

Build a Model from a TypeDict and data.

Parameters
  • typed_dict (typing.TypedDict) – TypeDict object containing the DTO’s structure

  • args – 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
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