Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

API reference

Pydantic API reference

Pydantic data validation

Identifiers
107
With full guides
14
Types
6

Topics covered

  • BaseModel
  • Fields
  • Validators
  • Settings
  • Serialization
  • Type adapters
  • Custom types
  • V2 features

Class

NameWhat it does
BaseModelClass
ConfigDictConfigDict is Pydantic's TypedDict for configuring model behavior. Assign it to model_config to control validation and schema-related options.
ValidationErrorValidationError is raised when Pydantic rejects input during validation. Catch it to access a readable report describing the model, location, expected value, error type, and received input.
BaseSettingsClass
TypeAdapterClass
EmailStrClass
RootModelClass
PydanticUserErrorClass
SettingsConfigDictSettingsConfigDict configures Pydantic settings models through named options such as environment-variable prefixes and dotenv-file loading. It is used as model_config data on a settings class.
AliasGeneratorClass
ImportStringClass
ByteSizeClass
InstanceOfClass
SkipValidationClass
SerializeAsAnyClass
PlainSerializerClass
WrapSerializerClass
StrictClass

Function

NameWhat it does
FieldField configures an annotated Pydantic model field with validation constraints and metadata. It can also participate in aliases and generated schema.
model_dumpFunction
model_validateFunction
constrFunction
model_serializerFunction
field_serializerFunction

Type Alias

NameWhat it does
BeforeValidatorType Alias
AfterValidatorType Alias
PlainValidatorType Alias
WrapValidatorType Alias
AnyUrlType Alias
HttpUrlType Alias
SecretStrType Alias
SecretBytesType Alias
JsonType Alias
conintType Alias
confloatType Alias
conlistType Alias
consetType Alias
PositiveIntType Alias
NegativeIntType Alias
NonNegativeIntType Alias
StrictStrType Alias
StrictIntType Alias
StrictBoolType Alias
UUID4Type Alias
IPvAnyAddressType Alias
FilePathType Alias
DirectoryPathType Alias
PastDateType Alias
FutureDateType Alias
NaiveDatetimeType Alias
AwareDatetimeType Alias
Base64StrType Alias
AnnotatedType Alias
AliasChoicesType Alias
AliasPathType Alias
DiscriminatorType Alias
TagType Alias
WithJsonSchemaType Alias
PositiveFloatType Alias
NegativeFloatType Alias
NonNegativeFloatType Alias
NonPositiveIntType Alias
FiniteFloatType Alias
PastDatetimeType Alias
FutureDatetimeType Alias
UUID1Type Alias
UUID5Type Alias
PaymentCardNumberType Alias
ColorType Alias
NameEmailType Alias
NewPathType Alias
RedisDsnType Alias
PostgresDsnType Alias
AmqpDsnType Alias
MongoDsnType Alias
KafkaDsnType Alias

Decorator

NameWhat it does
validatorDecorator
field_validatorDecorator
model_validatorDecorator
computed_fieldDecorator
validate_callDecorator

Module

NameWhat it does
model_validate_jsonModule
model_dump_jsonModule
model_copyModule
model_constructModule
model_json_schemaModule
model_fieldsModule
model_rebuildModule
model_validate_stringsModule
model_fields_setModule
TypeAdapter.validate_pythonModule
TypeAdapter.dump_pythonModule
TypeAdapter.json_schemaModule
RootModel.rootModule
model_dump(by_alias)model_dump(by_alias=True) serializes a Pydantic model to a dictionary using configured field aliases as keys. Leave it false or unset to use Python attribute names.
model_dump(exclude_unset)Module
model_dump(exclude_none)Module

Pipe

NameWhat it does
model_configmodel_config assigns a ConfigDict to a Pydantic model, controlling validation and schema behavior. Options include handling extra fields and enabling strict validation.
str_strip_whitespacePipe
populate_by_nameEnables aliased fields to accept input by their Python attribute names as well as their aliases. It defaults to false and is not recommended from Pydantic v2.11 onward because it will be deprecated in v3.
frozenSet frozen=True to make a Pydantic model faux-immutable and generate a __hash__() method. Hashing is only possible when all attribute values are hashable.
extraThe extra configuration controls how Pydantic handles input keys that are not declared model fields. Choose ignore, forbid, or allow; the default is ignore.
validate_assignmentvalidate_assignment enables validation when fields are changed after a Pydantic model is created. It defaults to False, so post-construction assignments are otherwise not revalidated.
use_enum_valuesuse_enum_values=True makes Pydantic populate enum fields with their underlying values rather than enum members. Optional enum defaults need validate_default=True for this conversion to apply.
arbitrary_types_allowedAllows model fields to use ordinary Python classes that Pydantic does not know how to validate. When enabled, Pydantic checks the supplied value's instance type rather than validating the object's internals.
alias_generatoralias_generator is a ConfigDict option that derives field aliases from their names. A callable applies to both validation and serialization; AliasGenerator supports different rules for each.
json_schema_extrajson_schema_extra adds custom properties to a Pydantic model's generated JSON Schema. Configure it with a dictionary or callable; its default is None.

Search across every package and filter by type in your dashboard.

Start learning