Serialization Reference¶
from_dict ¶
from_dict(
model_class: type[T],
data: dict[str, Any],
*,
doc_id: str | None = None,
by_alias: bool = False,
registry: TypeRegistry | None = None,
) -> T
Construct a model instance from a dict.
Nested Map dicts are automatically converted to their respective classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_class
|
type[T]
|
The Model class to construct. |
required |
data
|
dict[str, Any]
|
Dict of field values. |
required |
doc_id
|
str | None
|
Optional document ID. |
None
|
by_alias
|
bool
|
If True, read keys by Firestore alias. If False (default), use Python names. |
False
|
Returns:
| Type | Description |
|---|---|
T
|
The constructed model instance. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If required fields are missing. |
to_dict ¶
to_dict(
instance: Model | Map,
*,
by_alias: bool = False,
include_id: bool = False,
registry: TypeRegistry | None = None,
) -> dict[str, Any]
Convert a model/map instance to a dict.
Nested Map instances are recursively converted to dicts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Model | Map
|
Model or Map instance to convert. |
required |
by_alias
|
bool
|
If True, use Firestore alias keys. If False (default), use Python field names. |
False
|
include_id
|
bool
|
If True, include the document ID in the output. |
False
|
registry
|
TypeRegistry | None
|
Optional TypeRegistry. Uses default if not provided. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict representation of the instance. |