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
- Keyword Arguments
model (Type) – Model class the field belongs to.
parent (FieldDescriptorT) – parent field if any.
-
field
= None¶ Name of attribute on Model.
-
output_name
= None¶ Name of field when serializing data (if differs from
field
). Defaults toinput_name
.
-
type
= None¶ Type of value (e.g.
int
, orOptional[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()
, andModel.to_representation()
).
-
clone
(**kwargs: Any) → faust.types.models.FieldDescriptorT[source]¶ - Return type
FieldDescriptorT
[~T]
-
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
]
-
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
-
class
faust.models.fields.
NumberField
(*, max_value: int = None, min_value: int = None, **kwargs: Any) → None[source]¶
-
class
faust.models.fields.
IntegerField
(*, max_value: int = None, min_value: int = None, **kwargs: Any) → None[source]¶
-
class
faust.models.fields.
FloatField
(*, max_value: int = None, min_value: int = None, **kwargs: Any) → None[source]¶
-
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¶
-
-
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]¶
-
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]¶
-
class
faust.models.fields.
BytesField
(*, encoding: str = None, errors: str = None, **kwargs: Any) → None[source]¶ -
encoding
= 'utf-8'¶
-
errors
= 'strict'¶
-
-
faust.models.fields.
field_for_type
(typ: Type) → Type[faust.types.models.FieldDescriptorT][source]¶ - Return type
Type
[FieldDescriptorT
[~T]]