faust.models.fields

class faust.models.fields.FieldDescriptor(*, field: str = None, input_name: str = None, output_name: str = None, type: Type[T] = None, model: Type[faust.types.models.ModelT] = None, required: bool = True, default: T = None, parent: faust.types.models.FieldDescriptorT = None, coerce: bool = None, generic_type: Type = None, member_type: Type = None, exclude: bool = None, date_parser: Callable[Any, datetime.datetime] = None, **options: Any) → None[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 = None

Name of attribute on Model.

input_name = None

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

output_name = None

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

type = None

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

model = None

The model class this field is associated with.

required = True

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

default = None

Default value for non-required field.

generic_type = None

If this holds a generic type such as list/set/dict then this holds the type of collection.

coerce = 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 = 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()).

clone(**kwargs: Any) → faust.types.models.FieldDescriptorT[source]
Return type

FieldDescriptorT[~T]

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

Mapping[str, Any]

validate_all(value: Any) → Iterable[faust.exceptions.ValidationError][source]
Return type

Iterable[ValidationError]

validate(value: T) → Iterable[faust.exceptions.ValidationError][source]
Return type

Iterable[ValidationError]

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

Optional[~T]

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

bool

getattr(obj: faust.types.models.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) → faust.exceptions.ValidationError[source]
Return type

ValidationError

property ident

Return the fields identifier. :rtype: str

class faust.models.fields.NumberField(*, max_value: int = None, min_value: int = None, **kwargs: Any) → None[source]
validate(value: T) → Iterable[faust.exceptions.ValidationError][source]
Return type

Iterable[ValidationError]

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

Optional[int]

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

Optional[float]

class faust.models.fields.DecimalField(*, max_digits: int = None, max_decimal_places: int = None, **kwargs: Any) → None[source]
max_digits = None
max_decimal_places = None
prepare_value(value: Any, *, coerce: bool = None) → Optional[decimal.Decimal][source]
Return type

Optional[Decimal]

validate(value: decimal.Decimal) → Iterable[faust.exceptions.ValidationError][source]
Return type

Iterable[ValidationError]

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

Optional[str]

class faust.models.fields.DatetimeField(*, field: str = None, input_name: str = None, output_name: str = None, type: Type[T] = None, model: Type[faust.types.models.ModelT] = None, required: bool = True, default: T = None, parent: faust.types.models.FieldDescriptorT = None, coerce: bool = None, generic_type: Type = None, member_type: Type = None, exclude: bool = None, date_parser: Callable[Any, datetime.datetime] = None, **options: Any) → None[source]
prepare_value(value: Any, *, coerce: bool = None) → Optional[datetime.datetime][source]
Return type

Optional[datetime]

class faust.models.fields.BytesField(*, encoding: str = None, errors: str = None, **kwargs: Any) → None[source]
encoding = 'utf-8'
errors = 'strict'
prepare_value(value: Any, *, coerce: bool = None) → Optional[bytes][source]
Return type

Optional[bytes]

faust.models.fields.field_for_type(typ: Type) → Type[faust.types.models.FieldDescriptorT][source]
Return type

Type[FieldDescriptorT[~T]]