minos.common.model.abc

Classes

Model

Base class for minos model entities.

class Model[source]

Bases: Mapping

Base class for minos model entities.

__init__(fields=None, **kwargs)[source]

Class constructor.

Parameters

fields (Optional[Union[Iterable[Field], dict[str, minos.common.model.fields.Field]]]) – Dictionary that contains the Field instances of the model indexed by name.

classmethod from_typed_dict(typed_dict, *args, **kwargs)[source]

Build a Model from a TypeDict and data.

Parameters
  • typed_dict (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.

Returns

A new DataTransferObject instance.

Return type

T

abstract classmethod from_model_type(model_type, *args, **kwargs)[source]

Build a Model from a ModelType.

Parameters
  • model_type (ModelType) – ModelType 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.

Returns

A new DeclarativeModel instance.

Return type

T

classmethod from_avro_str(raw, **kwargs)[source]

Build a single instance or a sequence of instances from bytes

Parameters

raw (str) – A str representation of the model.

Returns

A single instance or a sequence of instances.

Return type

Union[T, list[~T]]

classmethod from_avro_bytes(raw, batch_mode=False, **kwargs)[source]

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.

  • kwargs – Additional named arguments.

Returns

A single instance or a sequence of instances.

Return type

Union[T, list[~T]]

classmethod from_avro(schema, data)[source]

Build a new instance from the avro schema and data.

Parameters
  • schema (Any) – The avro schema of the model.

  • data (Any) – The avro data of the model.

Returns

A new DynamicModel instance.

Return type

T

classmethod to_avro_str(models)[source]

Build the avro string representation of the given object instances.

Parameters

models (list[~T]) – A sequence of minos models.

Returns

A bytes object.

Return type

str

classmethod to_avro_bytes(models)[source]

Create a bytes representation of the given object instances.

Parameters

models (list[~T]) – A sequence of minos models.

Returns

A bytes object.

Return type

bytes

model_type

alias of Model

classname = 'minos.common.model.abc.Model'
type_hints = {}
type_hints_parameters = ()
property fields: dict[str, minos.common.model.fields.Field]

Fields getter

avro_schema = [{'name': 'Model', 'namespace': 'minos.common.model.abc.63a2ea0e-effa-46a2-a759-3b4e73f7c2fd', 'type': 'record', 'fields': []}]
property avro_data: dict[str, Any]

Compute the avro data of the model.

Returns

A dictionary object.

property avro_str: str

Generate bytes representation of the current instance.

Returns

A bytes object.

property avro_bytes: bytes

Generate bytes representation of the current instance.

Returns

A bytes object.

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

Encode schema with the given encoder.

Parameters
  • encoder (SchemaEncoder) – The encoder instance.

  • target (Any) – An optional pre-encoded schema.

  • kwargs – Additional named arguments.

Returns

The encoded schema of the instance.

Return type

Any

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

Decode schema with the given encoder.

Parameters
  • decoder (SchemaDecoder) – The decoder instance.

  • target (Any) – The schema to be decoded.

  • kwargs – Additional named arguments.

Returns

The decoded schema as a type.

Return type

Any

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

Encode data with the given encoder.

Parameters
  • encoder (DataEncoder) – The encoder instance.

  • target (Any) – An optional pre-encoded data.

  • kwargs – Additional named arguments.

Returns

The encoded data of the instance.

Return type

Any

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

Decode data with the given decoder.

Parameters
  • decoder (DataDecoder) – The decoder instance.

  • target (Any) – The data to be decoded.

  • type – The data type.

  • kwargs – Additional named arguments.

  • type_ (ModelType) –

Returns

A decoded instance.

Return type

Any

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
values() an object providing a view on D's values