From 10941aba63dce7dd72549e26cee8594511956c09 Mon Sep 17 00:00:00 2001 From: PrettyWood Date: Sun, 17 Jan 2021 23:56:18 +0100 Subject: [PATCH] docs: add section for create_model_from_{namedtuple,typeddict} --- docs/usage/models.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/usage/models.md b/docs/usage/models.md index 87312469db9..062808f6f52 100644 --- a/docs/usage/models.md +++ b/docs/usage/models.md @@ -384,6 +384,18 @@ You can also add validators by passing a dict to the `__validators__` argument. {!.tmp_examples/models_dynamic_validators.py!} ``` +## Model creation from `NamedTuple` or `TypedDict` + +Sometimes you already use in your application classes that inherit from `NamedTuple` or `TypedDict` +and you don't want to duplicate all your information to have a `BaseModel`. +For this _pydantic_ provides `create_model_from_namedtuple` and `create_model_from_typeddict` methods. +Those methods have the exact same keyword arguments as `create_model`. + + +```py +{!.tmp_examples/models_from_typeddict.py!} +``` + ## Custom Root Types Pydantic models can be defined with a custom root type by declaring the `__root__` field.