faust.models.fields
¶
- class faust.models.fields.FieldDescriptor(*, field: Optional[str] = None, input_name: Optional[str] = None, output_name: Optional[str] = None, type: Optional[Type[T]] = None, model: Optional[Type[ModelT]] = None, required: bool = True, default: Optional[T] = None, parent: Optional[FieldDescriptorT] = None, coerce: Optional[bool] = None, exclude: Optional[bool] = None, date_parser: Optional[Callable[[Any], datetime]] = None, tag: Optional[Type[Tag]] = None, **options: Any)[source]¶
Describes a field.
Used for every field in Record so that they can be used in join’s /group_by etc.
Examples
>>> class Withdrawal(Record): ... account_id: str ... amount: float = 0.0
>>> Withdrawal.account_id <FieldDescriptor: Withdrawal.account_id: str> >>> Withdrawal.amount <FieldDescriptor: Withdrawal.amount: float = 0.0>
- Parameters:
- Keyword Arguments:
model (Type) – Model class the field belongs to.
parent (FieldDescriptorT) – parent field if any.
- output_name: str¶
Name of field when serializing data (if differs from
field
). Defaults toinput_name
.
- coerce: bool = False¶
Coerce value to field descriptors type. This means assigning a value to this field, will first convert the value to the requested type. For example for a
FloatField
the input will be converted to float, and passing any value that cannot be converted to float will raise an error.If coerce is not enabled you can store any type of value.
Note:
None
is usually considered a valid value for any field but this depends on the descriptor type.
- exclude: bool = False¶
Exclude field from model representation. This means the field will not be part of the serialized structure. (
Model.dumps()
,Model.asdict()
, andModel.to_representation()
).
- clone(**kwargs: Any) FieldDescriptorT [source]¶
- Return type:
- validate_all(value: Any) Iterable[ValidationError] [source]¶
- Return type:
_GenericAlias
[ValidationError
]
- validate(value: T) Iterable[ValidationError] [source]¶
- Return type:
_GenericAlias
[ValidationError
]
- prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[T] [source]¶
- Return type:
_UnionGenericAlias
[~T,None
]
- getattr(obj: ModelT) T [source]¶
Get attribute from model recursively.
Supports recursive lookups e.g.
model.getattr('x.y.z')
.- Return type:
~T
- validation_error(reason: str) ValidationError [source]¶
- Return type:
- class faust.models.fields.BooleanField(*, field: Optional[str] = None, input_name: Optional[str] = None, output_name: Optional[str] = None, type: Optional[Type[T]] = None, model: Optional[Type[ModelT]] = None, required: bool = True, default: Optional[T] = None, parent: Optional[FieldDescriptorT] = None, coerce: Optional[bool] = None, exclude: Optional[bool] = None, date_parser: Optional[Callable[[Any], datetime]] = None, tag: Optional[Type[Tag]] = None, **options: Any)[source]¶
- validate(value: T) Iterable[ValidationError] [source]¶
- Return type:
_GenericAlias
[ValidationError
]
- class faust.models.fields.NumberField(*, max_value: Optional[int] = None, min_value: Optional[int] = None, **kwargs: Any)[source]¶
-
- validate(value: T) Iterable[ValidationError] [source]¶
- Return type:
_GenericAlias
[ValidationError
]
- class faust.models.fields.FloatField(*, max_value: Optional[int] = None, min_value: Optional[int] = None, **kwargs: Any)[source]¶
- class faust.models.fields.IntegerField(*, max_value: Optional[int] = None, min_value: Optional[int] = None, **kwargs: Any)[source]¶
- class faust.models.fields.DatetimeField(*, field: Optional[str] = None, input_name: Optional[str] = None, output_name: Optional[str] = None, type: Optional[Type[T]] = None, model: Optional[Type[ModelT]] = None, required: bool = True, default: Optional[T] = None, parent: Optional[FieldDescriptorT] = None, coerce: Optional[bool] = None, exclude: Optional[bool] = None, date_parser: Optional[Callable[[Any], datetime]] = None, tag: Optional[Type[Tag]] = None, **options: Any)[source]¶
- class faust.models.fields.DecimalField(*, max_digits: Optional[int] = None, max_decimal_places: Optional[int] = None, **kwargs: Any)[source]¶
-
- prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[Decimal] [source]¶
- Return type:
_UnionGenericAlias
[Decimal
,None
]
- validate(value: Decimal) Iterable[ValidationError] [source]¶
- Return type:
_GenericAlias
[ValidationError
]
- class faust.models.fields.BytesField(*, encoding: Optional[str] = None, errors: Optional[str] = None, **kwargs: Any)[source]¶