pydoc > pydantic.main.BaseModel

📋 Name

BaseModel — A base class for creating Pydantic models with validation and serialization.

🚀 Quick Reference

Use CaseCommandDescription
📦 Create a modelclass User(BaseModel): name: str; age: intDefine a data model with typed fields
✅ Validate dataUser.model_validate(data)Validate and create a model instance from a dict
📄 Parse JSONUser.model_validate_json(json_str)Validate and create a model from a JSON string
📤 Serialize to dictuser.model_dump()Convert model to a Python dictionary
📤 Serialize to JSONuser.model_dump_json()Convert model to a JSON string
📋 Generate JSON SchemaUser.model_json_schema()Generate JSON Schema for the model
🔧 Construct without validationUser.model_construct(name='x', age=1)Create instance from trusted data (no validation)
📋 Get fields setuser.model_fields_setGet set of fields explicitly set on the instance
📋 Get extra fieldsuser.model_extraGet extra fields if extra='allow'

📖 Description

Base class for creating Pydantic models. Provides data validation, serialization, and schema generation.

Constructor: BaseModel(**data: Any) -> None

🔧 Constructor

__init__(self, /, **data: Any) -> None

Create a new model by parsing and validating input data from keyword arguments.

📋 Attributes

🔧 Instance Methods

📄 copy (deprecated)

copy(self, *, include=None, exclude=None, update=None, deep=False) -> Self

⚠️ Deprecated: Use model_copy instead.

If you need include or exclude, use:

data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)

📄 dict (deprecated)

dict(self, *, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False) -> Dict[str, Any]

📄 json (deprecated)

json(self, *, include=None, exclude=None, by_alias=False, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs) -> str

📄 model_copy

model_copy(self, *, update=None, deep=False) -> Self

Returns a copy of the model. The underlying __dict__ attribute is copied (may have side effects with cached properties).

📤 model_dump

model_dump(self, *, mode='python', include=None, exclude=None, context=None, by_alias=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, exclude_computed_fields=False, round_trip=False, warnings=True, fallback=None, serialize_as_any=False, polymorphic_serialization=None) -> dict[str, Any]

Generate a dictionary representation of the model.

📤 model_dump_json

model_dump_json(self, *, indent=None, ensure_ascii=False, include=None, exclude=None, context=None, by_alias=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, exclude_computed_fields=False, round_trip=False, warnings=True, fallback=None, serialize_as_any=False, polymorphic_serialization=None) -> str

Generates a JSON representation of the model.

🔧 model_post_init

model_post_init(self, context: Any, /) -> None

Override to perform additional initialization after __init__ and model_construct. Useful for validation that requires the entire model to be initialized.

🔧 Class Methods

📖 Readonly Properties

📦 Data Descriptors

📊 Data and Other Attributes

pydantic.main.BaseModel
📋 Name 🚀 Quick Reference 📖 Description 🔧 Constructor 📋 Attributes 🔧 Instance Methods
📄 copy (deprecated) 📄 dict (deprecated) 📄 json (deprecated) 📄 model_copy 📤 model_dump 📤 model_dump_json 🔧 model_post_init
🔧 Class Methods 📖 Readonly Properties 📦 Data Descriptors 📊 Data and Other Attributes

Generated by phpman v4.9.27-5-g2cb901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-20 04:07 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^