Kemux stream Schema classes

Base class for Schema classes.

Schema dataclass

Schema base Class

Provides a common interface for Schema classes to validate data and create faust.Record classes.

Attributes:
  • logger (Logger) –

    The logger to use for logging messages.

  • decorated_fields (dict[str, type]) –

    The fields to validate, with the leading and trailing underscores.

  • fields (dict[str, type]) –

    The fields to validate, without the leading and trailing underscores.

  • record_class (Record) –

    The faust.Record class to use for automatic serialization and deserialization of records.

find_decorated_fields() classmethod

Find decorated fields and compose a faust.Record subclass.

Raises:
  • ValueError

    If no decorated fields are found.

StreamRecordT

Bases: Record

StreamRecordT Class

A type hint for custom faust.Record classes. These subclasses are created automatically by the input and output schema classes and are passed to faust.TopicT initializers as the value_type argument i.e. record models.

to_dict()

Convert the record to a dict.

Returns:
  • dict( dict ) –

    The record as a dict.

Input Schema

Input schema for Kemux.

This is the schema that is used to validate incoming messages.

InputSchema dataclass

Bases: Schema

InputSchema Class

The schema that is used to validate incoming messages.

asdict() classmethod

Convert the nested faust.Record subclass to a dict.

Returns:
  • dict( dict[str, type] ) –

    The nested faust.Record subclass as a dict.

construct_input_record_class() classmethod

Factory used to construct the faust.Record subclass that is used to accept and validate incoming messages.

Raises:
  • ValueError

    If a validator is not a valid callable.

Output Schema

Base class for output schema classes.

OutputSchema dataclass

Bases: Schema

OutputSchema Class

The schema that is used to construct and validate outgoing messages.

construct_output_record_class() classmethod

Factory used to construct the faust.Record subclass that is used to construct and validate outgoing messages.

transform(message) staticmethod

Transform the message into a format that can be consumed by the output schema.

Must be implemented by user when defining a stream output messages schema. This is done instead of enforcing implementation via abstract classes, due to the fact that this class is never instantiated directly, but rather used as an interface.

Parameters:
  • message (dict) –

    The message to be transformed.

Raises:
  • NotImplementedError

    If the method is not implemented by the user.

validate(message) classmethod

Validate the outgoing message using schema fields defined in the OutputSchema class.

Parameters:
  • message (dict) –

    The message to be validated.

Returns:
  • bool( bool ) –

    True if the message is valid, False otherwise.