Serialization¶
How rows are (de)serialized to and from the on-disk JSON format. TinyStore never
evals, execs, or pickles data — only json.loads into validated Pydantic
models.
serialization
¶
Pydantic <-> JSON row conversion with stable formatting.
TinyStore persists models as rows in JSON table files. Each row is a plain dict
produced by model_dump(mode='json') so that datetime/date/UUID/Enum and
nested JSON-compatible values are encoded as JSON scalars automatically by
Pydantic. Relationship fields are never persisted.
model_to_row
¶
Convert a model instance to a persistable row dict.
exclude is the set of relationship field names to drop. The internal
optimistic-concurrency version is attached under __version.
row_to_model
¶
row_to_model(
model_cls: type[T],
row: dict[str, Any],
*,
exclude: frozenset[str] = frozenset(),
) -> T
Convert a stored row dict back into a validated model instance.
Internal fields (__version) are stripped before validation. Relationship
fields are excluded (left as their default None).