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

Mar 9, 2022

Confidentiality
Public
Reactions
1
Share

StrRField

Resource field for storing string values.

StrRField stores string values with automatic validation and configurable storage. By default, strings are stored in the KV_STORE as they can be large and are not typically used for database queries.

This is useful for: - Text content and descriptions - Names, labels, and identifiers - File paths and URLs - Any textual metadata

Storage behavior: - Stored in KV_STORE by default (efficient for larger strings) - Included in dict views by default - Automatically validated as string on load/save - For very large strings, consider setting include_in_dict_view=False

Example: ```python class MyResource(Resource): # Simple string field description = StrRField()

    # With default value
    status = StrRField(default_value='pending')

    # Stored in DATABASE for searchability
    name = StrRField(storage=RFieldStorage.DATABASE)

    # Large content not in dict view
    content = StrRField(include_in_dict_view=False)
```
Attributes
include_in_dict_view: boolstorage: RFieldStoragevalidator: Validator
Functions
__init__

Initialize a StrRField for storing string values.

default_value : str | None
Default string value. Can be: - str: A specific string value - Type or Callable: Called to generate default (e.g., str for '') - None: Field has no default value Defaults to None
include_in_dict_view : bool - True
If True, included in dict/JSON representations. Set to False for very large strings. Defaults to True
storage : RFieldStorage - RFieldStorage.KV_STORE
Storage backend (DATABASE for searchable but limited size, KV_STORE for larger strings, NONE for transient). Defaults to KV_STORE for strings
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.