Menu
Introduction
Getting Started
Developer guide
Release
Architecture
CLI
Technical documentations
Version
Publication date

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

PrimitiveRField

Base class for Resource fields storing primitive Python types.

PrimitiveRField provides validation and storage for primitive values (int, float, str, bool). This class should not be used directly - use the specific subclasses (IntRField, FloatRField, StrRField, BoolRField) instead.

The field automatically: - Validates values using type-specific validators - Handles serialization/deserialization - Supports configurable storage backends (DATABASE, KV_STORE, NONE) - Includes values in dict views by default (configurable)

Each primitive type has its own validator that ensures type safety during both serialization and deserialization operations.

Attributes: validator: Type-specific validator for ensuring data integrity

Note: Use the specific subclasses (IntRField, FloatRField, etc.) rather than instantiating this class directly.

Attributes
include_in_dict_view: boolstorage: RFieldStoragevalidator: Validator
Functions
__init__

Initialize a PrimitiveRField with validation and storage configuration.

validator : Validator
Validator used to verify the field value type during serialization and deserialization. Also validates the default value.
default_value : Any
Default value for the field. Can be: - Primitive value (int, float, str, bool): Used directly - Type or Callable: Called without parameters to generate default - None: Field has no default value Defaults to None
include_in_dict_view : bool - True
If True, this field is included in dict/JSON representations. Primitive fields are included by default. Defaults to True
storage : RFieldStorage - RFieldStorage.KV_STORE
Storage backend for this field (DATABASE, KV_STORE, or NONE). Defaults to KV_STORE
deserialize

Deserialize and validate a value from storage.

Validates the stored value using the field's validator before returning it.

r_field_value : Any
The raw value from storage
Return type : Any
get_default_value

Get the default value for this field.

If the default value is a Type or Callable, it will be called to generate a new default value. Otherwise, the default value is returned directly.

This ensures that mutable defaults (like lists or dicts) are not shared between Resource instances.

Return type : Any
serialize

Serialize and validate a value for storage.

Validates the value using the field's validator before storing it.

r_field_value : Any
The runtime value to serialize
Return type : Any
Shine Logo
Technical bricks to reuse or customize

Have you developed a brick?

Share it to accelerate projects for the entire community.