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.
- class faust.models.base.Model(*args: Any, **kwargs: Any)[source]¶
Meta description model for serialization.
- classmethod loads(s: bytes, *, default_serializer: Optional[Union[CodecT, str]] = None, serializer: Optional[Union[CodecT, str]] = None) 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:
- validate() List[ValidationError] [source]¶
- Return type:
_GenericAlias
[ValidationError
]
- property validation_errors: List[ValidationError]¶
- Return type:
_GenericAlias
[ValidationError
]
- faust.models.base.maybe_model(arg: Any) Any [source]¶
Convert argument to model if possible.
- Return type:
- faust.models.base.registry: MutableMapping[str, Type[ModelT]] = {'@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.