MCPcopy
hub / github.com/pydantic/pydantic / ConfigDict

Class ConfigDict

pydantic/config.py:36–1213  ·  view source on GitHub ↗

A TypedDict for configuring Pydantic behaviour.

Source from the content-addressed store, hash-verified

34
35
36class ConfigDict(TypedDict, total=False):
37 """A TypedDict for configuring Pydantic behaviour."""
38
39 title: str | None
40 """The title for the generated JSON schema, defaults to the model's name"""
41
42 model_title_generator: Callable[[type], str] | None
43 """A callable that takes a model class and returns the title for it. Defaults to `None`."""
44
45 field_title_generator: Callable[[str, FieldInfo | ComputedFieldInfo], str] | None
46 """A callable that takes a field's name and info and returns title for it. Defaults to `None`."""
47
48 str_to_lower: bool
49 """Whether to convert all characters to lowercase for str types. Defaults to `False`."""
50
51 str_to_upper: bool
52 """Whether to convert all characters to uppercase for str types. Defaults to `False`."""
53
54 str_strip_whitespace: bool
55 """Whether to strip leading and trailing whitespace for str types."""
56
57 str_min_length: int
58 """The minimum length for str types. Defaults to `None`."""
59
60 str_max_length: int | None
61 """The maximum length for str types. Defaults to `None`."""
62
63 extra: ExtraValues | None
64 '''
65 Whether to ignore, allow, or forbid extra data during model initialization. Defaults to `'ignore'`.
66
67 Three configuration values are available:
68
69 - `'ignore'`: Providing extra data is ignored (the default):
70 ```python
71 from pydantic import BaseModel, ConfigDict
72
73 class User(BaseModel):
74 model_config = ConfigDict(extra='ignore') # (1)!
75
76 name: str
77
78 user = User(name='John Doe', age=20) # (2)!
79 print(user)
80 #> name='John Doe'
81 ```
82
83 1. This is the default behaviour.
84 2. The `age` argument is ignored.
85
86 - `'forbid'`: Providing extra data is not permitted, and a [`ValidationError`][pydantic_core.ValidationError]
87 will be raised if this is the case:
88 ```python
89 from pydantic import BaseModel, ConfigDict, ValidationError
90
91
92 class Model(BaseModel):
93 x: int

Callers 15

UserExtraAllowClass · 0.90
UserExtraForbidClass · 0.90
MyDictClass · 0.90
ModelClass · 0.90
BaseClass · 0.90
MyTypedDictClass · 0.90
ModelClass · 0.90
PokemonClass · 0.90
PokemonListClass · 0.90
PokemonDictClass · 0.90
PetClass · 0.90

Calls

no outgoing calls