Pydantic
Pydantic is a data validation library that defines data models through standard Python type annotations. PyCharm provides dedicated support for Pydantic models, built on top of the same type engine that powers other type-hinting features.
The support covers pydantic.BaseModel and its subclasses, pydantic.dataclasses.dataclass, generic models, and related constructs such as Field, model and field validators, and ConfigDict options. PyCharm recognizes both Pydantic v1 and v2, but it does not read the options of the v1 class Config, such as allow_population_by_field_name.
Code insight for model fields
When you instantiate a Pydantic model, PyCharm treats the declared fields as keyword arguments of __init__ and provides the following code insight:
Completion of field names as keyword arguments, considering their declared types and default values, also for fields declared with
AnnotatedType checking of values passed for each field against the corresponding annotation
An inspection that highlights missing required fields
Navigation from a keyword argument in an
__init__call to the field declaration and back, including across subclasses and base classes
Field aliases and validation config
PyCharm accepts fields declared with an alias through Field(alias=...) as keyword arguments in constructor calls, without a false "unexpected argument" warning.
PyCharm respects the model configuration, so code insight in the editor matches the runtime validation behavior. PyCharm reads the options from the class keyword arguments, model_config, and the config argument or __pydantic_config__ of pydantic.dataclasses.dataclass. A subclass inherits the options of its base classes.
populate_by_name=Trueorvalidate_by_name=True: PyCharm accepts the field name in addition to its alias.validate_by_alias=False: PyCharm accepts only the field name. By default, PyCharm accepts the alias.
When both options are enabled, PyCharm accepts the field name and its alias as keyword arguments:
Refactorings and validators
Renaming a model field also renames the keyword arguments in the __init__ calls of the model. Renaming such a keyword argument renames the field declaration.
When @field_validator, @model_validator, or @validator is combined with @classmethod, the Problematic nesting of decorators inspection does not report it.