faust.models.base

Model descriptions.

The model describes the components of a data structure, kind of like a struct in C, but there’s no limitation of what type of data structure the model is, or what it’s used for.

A record (faust.models.record) is a model type that serialize into dictionaries, so the model describe the fields, and their types:

>>> class Point(Record):
...    x: int
...    y: int

>>> p = Point(10, 3)
>>> assert p.x == 10
>>> assert p.y == 3
>>> p
<Point: x=10, y=3>
>>> payload = p.dumps(serializer='json')
'{"x": 10, "y": 3, "__faust": {"ns": "__main__.Point"}}'
>>> p2 = Record.loads(payload)
>>> p2
<Point: x=10, y=3>

Models are mainly used for describing the data in messages: both keys and values can be described as models.

faust.models.base.registry = {'@ClientAssignment': <class 'faust.assignor.client_assignment.ClientAssignment'>, '@ClientMetadata': <class 'faust.assignor.client_assignment.ClientMetadata'>, '@ClusterAssignment': <class 'faust.assignor.cluster_assignment.ClusterAssignment'>, '@ReqRepRequest': <class 'faust.agents.models.ReqRepRequest'>, '@ReqRepResponse': <class 'faust.agents.models.ReqRepResponse'>, '@SetManagerOperation': <class 'faust.tables.sets.SetManagerOperation'>, 'faust.agents.models.ModelReqRepRequest': <class 'faust.agents.models.ModelReqRepRequest'>, 'faust.agents.models.ModelReqRepResponse': <class 'faust.agents.models.ModelReqRepResponse'>, 'faust.livecheck.models.SignalEvent': <class 'faust.livecheck.models.SignalEvent'>, 'faust.livecheck.models.TestExecution': <class 'faust.livecheck.models.TestExecution'>, 'faust.livecheck.models.TestReport': <class 'faust.livecheck.models.TestReport'>}

Global map of namespace -> Model, used to find model classes by name. Every single model defined is added here automatically when a model class is defined.

faust.models.base.maybe_model(arg: Any) → Any[source]

Convert argument to model if possible.

Return type

Any

class faust.models.base.Model(*args: Any, **kwargs: Any) → None[source]

Meta description model for serialization.

classmethod loads(s: bytes, *, default_serializer: Union[faust.types.codecs.CodecT, str, None] = None, serializer: Union[faust.types.codecs.CodecT, str, None] = None) → faust.types.models.ModelT[source]

Deserialize model object from bytes.

Keyword Arguments

serializer (CodecArg) – Default serializer to use if no custom serializer was set for this model subclass.

Return type

ModelT

classmethod make_final() → None[source]
Return type

None

abstract to_representation() → Any[source]

Convert object to JSON serializable object.

Return type

Any

is_valid() → bool[source]
Return type

bool

validate() → List[faust.exceptions.ValidationError][source]
Return type

List[ValidationError]

validate_or_raise() → None[source]
Return type

None

property validation_errors
Return type

List[ValidationError]

derive(*objects: faust.types.models.ModelT, **fields: Any) → faust.types.models.ModelT[source]

Derive new model with certain fields changed.

Return type

ModelT

dumps(*, serializer: Union[faust.types.codecs.CodecT, str, None] = None) → bytes[source]

Serialize object to the target serialization format.

Return type

bytes