minos.networks.brokers.messages.models.v1

Classes

BrokerMessageV1

Broker Message V1 class.

BrokerMessageV1Payload

Broker Message Payload class.

BrokerMessageV1Status

Broker Message Status v1 class.

BrokerMessageV1Strategy

Broker Message Strategy class

class BrokerMessageV1[source]

Bases: BrokerMessage, DeclarativeModel

Broker Message V1 class.

strategy: BrokerMessageV1Strategy
payload: BrokerMessageV1Payload
__init__(topic, payload, *, identifier=None, strategy=None, **kwargs)[source]

Class constructor.

Parameters
class property version: int

Get the version of the message.

Returns

A strictly positive int value.

property topic: str

Get the topic of the message.

Returns

A str value.

property identifier: uuid.UUID

Get the identifier of the message.

Returns

An UUID instance.

property reply_topic: Optional[str]

Get the reply topic of the message if there is someone.

Returns

A str value or None.

set_reply_topic(value)[source]

Set the message’s reply topic.

Parameters

value (Optional[str]) – A str value or None.

Returns

This method does not return anything.

Return type

None

property content: Any

Get the content of the message.

Returns

Any value.

property ok: bool

Check if the message is okay or not.

Returns

True if the message is okay or False otherwise.

property status: int

Get the payload status.

Returns

A BrokerMessageV1Status instance.

property headers: dict[str, str]

Get the payload headers.

Returns

A dict with str keys and str values.

property data: Any

Get the payload content.

Returns

Any value.

property avro_bytes: bytes

Generate bytes representation of the current instance.

Returns

A bytes object.

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.

classname = 'minos.networks.brokers.messages.models.v1.BrokerMessageV1'
classmethod decode_data(decoder, target, type_, **kwargs)

Decode data with the given decoder.

Parameters
  • decoder (DataDecoder) – The decoder instance.

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

  • type – The data type.

  • type_ (ModelType) –

Returns

A decoded instance.

Return type

BrokerMessage

static decode_schema(decoder, target, **kwargs)

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

classmethod encode_data(encoder, target, **kwargs)

Encode data with the given encoder.

Parameters
  • encoder (DataEncoder) – The encoder instance.

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

Returns

The encoded data of the instance.

Return type

Any

classmethod encode_schema(encoder, target, **kwargs)

Encode schema with the given encoder.

Parameters
Returns

The encoded schema of the instance.

Return type

Any

property fields: dict[str, minos.common.model.fields.Field]

Fields getter

classmethod from_avro(schema, data)

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 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.

  • kwargs – Additional named arguments.

Returns

A single instance or a sequence of instances.

Return type

Union[T, list[~T]]

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.

Returns

A single instance or a sequence of instances.

Return type

Union[T, list[~T]]

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

Build a DeclarativeModel from a ModelType.

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

Returns

A new DeclarativeModel instance.

Return type

T

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

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

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
property should_reply: bool
Returns

classmethod to_avro_bytes(models)

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

classmethod to_avro_str(models)

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

type_hints_parameters = ()
values() an object providing a view on D's values
class BrokerMessageV1Payload[source]

Bases: DeclarativeModel

Broker Message Payload class.

content: Any
status: BrokerMessageV1Status
headers: dict[str, str]
__init__(content=None, headers=None, status=None, **kwargs)[source]

Class constructor.

Parameters
property ok: bool

Check if the message is okay or not.

Returns

True if the message is okay or False otherwise.

property data: Any

Get the content.

Returns

Any value.

property avro_bytes: bytes

Generate bytes representation of the current instance.

Returns

A bytes object.

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.

classname = 'minos.networks.brokers.messages.models.v1.BrokerMessageV1Payload'
static decode_data(decoder, target, type_, **kwargs)

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

static decode_schema(decoder, target, **kwargs)

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)

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 encode_schema(encoder, target, **kwargs)

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

property fields: dict[str, minos.common.model.fields.Field]

Fields getter

classmethod from_avro(schema, data)

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 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.

  • kwargs – Additional named arguments.

Returns

A single instance or a sequence of instances.

Return type

Union[T, list[~T]]

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.

Returns

A single instance or a sequence of instances.

Return type

Union[T, list[~T]]

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

Build a DeclarativeModel from a ModelType.

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

Returns

A new DeclarativeModel instance.

Return type

T

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

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

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.

Returns

A bytes object.

Return type

bytes

classmethod to_avro_str(models)

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

type_hints_parameters = ()
values() an object providing a view on D's values
class BrokerMessageV1Status[source]

Bases: int, Enum

Broker Message Status v1 class.

SUCCESS = 200
ERROR = 400
SYSTEM_ERROR = 500
UNKNOWN = 600
class BrokerMessageV1Strategy[source]

Bases: str, Enum

Broker Message Strategy class

UNICAST = 'unicast'
MULTICAST = 'multicast'