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:
  • field (str) – Name of field.

  • type (Type) – Field value type.

  • required (bool) – Set to false if field is optional.

  • default (Any) – Default value when required=False.

Keyword Arguments:
  • model (Type) – Model class the field belongs to.

  • parent (FieldDescriptorT) – parent field if any.

field: str

Name of attribute on Model.

input_name: str

Name of field in serialized data (if differs from field). Defaults to field.

output_name: str

Name of field when serializing data (if differs from field). Defaults to input_name.

type: Type[T]

Type of value (e.g. int, or Optional[int])).

model: Type[ModelT]

The model class this field is associated with.

required: bool = True

Set if a value for this field is required (cannot be None).

default: Optional[T] = None

Default value for non-required field.

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(), and Model.to_representation()).

tag: Optional[Type[Tag]]

Field may be tagged with Secret/Sensitive/etc.

on_model_attached() None[source]
Return type:

None

clone(**kwargs: Any) FieldDescriptorT[source]
Return type:

FieldDescriptorT

as_dict() Mapping[str, Any][source]
Return type:

_GenericAlias[str, Any]

validate_all(value: Any) Iterable[ValidationError][source]
Return type:

_GenericAlias[ValidationError]

validate(value: T) Iterable[ValidationError][source]
Return type:

_GenericAlias[ValidationError]

to_python(value: Any) Optional[T][source]
Return type:

_UnionGenericAlias[~T, None]

prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[T][source]
Return type:

_UnionGenericAlias[~T, None]

should_coerce(value: Any, coerce: Optional[bool] = None) bool[source]
Return type:

bool

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:

ValidationError

property ident: str

Return the fields identifier. :rtype: str

related_models[source]
lazy_coercion[source]
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]

prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[bool][source]
Return type:

_UnionGenericAlias[bool, None]

class faust.models.fields.NumberField(*, max_value: Optional[int] = None, min_value: Optional[int] = None, **kwargs: Any)[source]
max_value: Optional[int]
min_value: Optional[int]
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]
prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[float][source]
Return type:

_UnionGenericAlias[float, None]

class faust.models.fields.IntegerField(*, max_value: Optional[int] = None, min_value: Optional[int] = None, **kwargs: Any)[source]
prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[int][source]
Return type:

_UnionGenericAlias[int, None]

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]
to_python(value: Any) Any[source]
Return type:

Any

prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[datetime][source]
Return type:

_UnionGenericAlias[datetime, None]

class faust.models.fields.DecimalField(*, max_digits: Optional[int] = None, max_decimal_places: Optional[int] = None, **kwargs: Any)[source]
max_digits: Optional[int] = None
max_decimal_places: Optional[int] = None
to_python(value: Any) Any[source]
Return type:

Any

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]
encoding: str = 'utf-8'
errors: str = 'strict'
prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[bytes][source]
Return type:

_UnionGenericAlias[bytes, None]

class faust.models.fields.StringField(*, max_length: Optional[int] = None, min_length: Optional[int] = None, trim_whitespace: bool = False, allow_blank: bool = False, **kwargs: Any)[source]
prepare_value(value: Any, *, coerce: Optional[bool] = None) Optional[str][source]
Return type:

_UnionGenericAlias[str, None]

faust.models.fields.field_for_type(typ: Type) Tuple[Type[FieldDescriptorT], Optional[Type[Tag]]][source]
Return type:

_GenericAlias[_GenericAlias[FieldDescriptorT], _UnionGenericAlias[_GenericAlias[Tag], None]]