patito.Model.example_value
- classmethod Model.example_value(field)
Return a valid example value for the given model field.
- Parameters
field (
str
) – Field name identifier.- Return type
Union
[date
,datetime
,float
,int
,str
,None
]- Returns
A single value which is consistent with the given field definition.
- Raises
NotImplementedError – If the given field has no example generator.
Example
>>> from typing import Literal >>> import patito as pt
>>> class Product(pt.Model): ... product_id: int = pt.Field(unique=True) ... name: str ... temperature_zone: Literal["dry", "cold", "frozen"] ... >>> Product.example_value("product_id") -1 >>> Product.example_value("name") 'dummy_string' >>> Product.example_value("temperature_zone") 'dry'