faust.models.record
¶
Record - Dictionary Model.
- class faust.models.record.Record[source]¶
Describes a model type that is a record (Mapping).
Examples
>>> class LogEvent(Record, serializer='json'): ... severity: str ... message: str ... timestamp: float ... optional_field: str = 'default value'
>>> event = LogEvent( ... severity='error', ... message='Broken pact', ... timestamp=666.0, ... )
>>> event.severity 'error'
>>> serialized = event.dumps() '{"severity": "error", "message": "Broken pact", "timestamp": 666.0}'
>>> restored = LogEvent.loads(serialized) <LogEvent: severity='error', message='Broken pact', timestamp=666.0>
>>> # You can also subclass a Record to create a new record >>> # with additional fields >>> class RemoteLogEvent(LogEvent): ... url: str
>>> # You can also refer to record fields and pass them around: >>> LogEvent.severity >>> <FieldDescriptor: LogEvent.severity (str)>
- classmethod from_data(data: Mapping, *, preferred_type: Optional[Type[ModelT]] = None) Record [source]¶
Create model object from Python dictionary.
- Return type: