Install & Compatibility
Where this runs
tested against v2.13.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.915 runs
installs and imports cleanly · install 0.0s · import 0.252s · 31.1MB
glibcpy 3.10–3.915 runs
installs and imports cleanly · install 3.7s · import 0.229s · 31MB
29MB installed
● package 29MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BaseModel
✓ from pydantic import BaseModel, field_validator, model_validator
class User(BaseModel):
name: str
age: int
@field_validator('age')
@classmethod
def age_must_be_positive(cls, v):
if v <= 0:
raise ValueError('age must be positive')
return v
✗ from pydantic import BaseModel, validator
class User(BaseModel):
name: str
@validator('name')
def validate_name(cls, v):
return v
@validator is deprecated in V2, removed in V3. Use @field_validator. Must add @classmethod decorator in V2.
model_validator
✓ from pydantic import BaseModel, model_validator
class User(BaseModel):
name: str
age: int
@model_validator(mode='before')
@classmethod
def check_root(cls, values):
return values
✗ from pydantic import BaseModel, root_validator
class User(BaseModel):
@root_validator(pre=True)
def check_root(cls, values):
return values
@root_validator deprecated in V2, removed in V3. Use @model_validator(mode='before') or mode='after'.
ConfigDict
✓ from pydantic import BaseModel, ConfigDict
class User(BaseModel):
model_config = ConfigDict(from_attributes=True)
name: str
✗ from pydantic import BaseModel
class User(BaseModel):
class Config:
orm_mode = True
Inner Config class deprecated in V2. Use model_config = ConfigDict(...). orm_mode renamed to from_attributes.
BaseSettings
✓ from pydantic_settings import BaseSettings
class Settings(BaseSettings):
api_key: str
model_config = ConfigDict(env_file='.env')
✗ from pydantic import BaseSettings
BaseSettings moved to separate pydantic-settings package in V2. ImportError if using old import.
Pydantic V2 style model with field validator and config.
from pydantic import BaseModel, field_validator, ConfigDict
class User(BaseModel):
model_config = ConfigDict(from_attributes=True)
name: str
age: int
@field_validator('age')
@classmethod
def age_positive(cls, v):
assert v > 0, 'age must be positive'
return v
user = User(name='Alice', age=30)
print(user.model_dump()) # not .dict()
print(user.model_dump_json()) # not .json()
Errors
Common errors & fixes
AttributeError: 'BaseModel' object has no attribute 'dict'
In Pydantic V2, the `.dict()` method on `BaseModel` instances has been renamed and replaced by `.model_dump()` to avoid confusion with Python's built-in `dict()` function and to support new serialization features.
fixReplace `.dict()` with `.model_dump()` to serialize models to a Python dictionary, or `.model_dump_json()` to get a JSON string.
PydanticUndefinedAnnotation: name 'YourType' is not defined
This error occurs when a type annotation refers to a class or type hint that has not yet been defined in the current scope, often due to forward references, circular imports, or simple typos.
fixFor forward references, use string literal annotations (e.g., `a: 'MyModel'`) and ensure `from __future__ import annotations` is imported for Python versions older than 3.9. If necessary, call `YourModel.model_rebuild()` after all related models are defined.
PydanticImportError: cannot import name 'validator' from 'pydantic'
Pydantic V2 introduced significant changes, including renaming and reorganizing modules and functions. The `@validator` decorator from V1 has been replaced by `@field_validator` and `@model_validator` in V2, requiring an update to import paths and usage.
fixUpdate imports from `pydantic` to use the new validator decorators, e.g., `from pydantic import field_validator` or `from pydantic import model_validator`. Also, ensure other V1-specific imports or configurations are updated according to the V2 migration guide.
ValidationError: 1 validation error for ModelName field_name Input should be a valid integer [type=int_parsing,...]
This is a general validation error indicating that the input data provided for a specific field does not conform to its declared type or any defined constraints (e.g., an integer field received a non-integer string).
fixInspect the `loc` and `type` fields within the `ValidationError.errors()` output to identify the exact field and reason for the failure, then adjust the input data to match the expected type and constraints of the Pydantic model.
PydanticUserError: Field 'x' has 'regex' set but 'pattern' should be used instead
In Pydantic V2, several keyword arguments for the `Field` function were renamed or removed for consistency and clarity. Specifically, `regex` was replaced by `pattern` to specify regular expression constraints.
fixReplace the deprecated `regex` argument in `Field()` with `pattern`, like `field_name: str = Field(pattern='your_regex_pattern')`. Review the V2 migration guide for other renamed `Field` arguments (e.g., `min_items` to `min_length`).
Upgrade
Version history
2.13.4latest on PyPI · released May 6, 2026
Audit
Dependencies
pydantic-corerequiredRust-based core engine. Installed automatically. Do not pin separately.
pydantic-settingsoptionalBaseSettings moved to separate package in V2. Required for settings/env var management.
email-validatoroptionalRequired for EmailStr type. Install via pydantic[email].