A much tested rewrite of strictus-dictus (github repo) which does not extend dict
.
pip install strictus
from typing import List
from strictus.core import strictus, strictus_field
class Item(strictus):
id: str
name: str
class ItemList(strictus):
items: List[Item] = strictus_field(default_factory=list)
item_list = ItemList({"items": [{"id": 1, "name": "first"}]})
print(item_list.items[0].name) # prints "first"
print(item_list.to_dict()) # prints "{'items': [{'id': '1', 'name': 'first'}]}"