How to Turn a pydantic Model into a Dictionary with model_dump
A pydantic model checks your data, but other code often wants a plain dictionary: to save it, to pass it on with **, or to send it as JSON. model_dump() gives you that dictionary, with the values already converted. This guide uses it with pydantic 2.14.4 on Python 3.15.2.
Syntax
<dictionary> = <item>.model_dump()
<dictionary> = <item>.model_dump(exclude={"<field>"})
<json text> = <item>.model_dump_json()
| Part | What it means |
|---|---|
<item> | An instance of a pydantic model |
model_dump() | Returns a dict with one key per field |
exclude={"<field>"} | Optional. Leaves those fields out |
model_dump_json() | Returns the same data as JSON text |
pydantic's serialization guide says that "Pydantic models (and model-like types such as dataclasses) will be (recursively) converted to dictionaries. This is achievable by using the model_dump() method".
The Example
A Settings model has a theme and a font_size. The font size arrives as text, "14", and the script turns the checked settings back into a dictionary.
Prerequisites
- pydantic in your project, for example with
uv add pydantic. This guide uses pydantic 2.14.4 on Python 3.15.2.
Step 1: Write the Script
from pydantic import BaseModel
class Settings(BaseModel):
theme: str
font_size: int
settings = Settings(theme="dark", font_size="14")
data = settings.model_dump()
print(data)
print(type(data).__name__)

Step 2: Run It
uv run python dump.py
{'theme': 'dark', 'font_size': 14}
dict

The dictionary holds the checked values: font_size is the number 14, not the text "14" it came in as. The command works unchanged in PowerShell.
Leave Fields Out, or Get JSON
Settings(theme="dark", font_size=14).model_dump(exclude={"theme"}) and .model_dump_json() printed:
{'font_size': 14}
{"theme":"dark","font_size":14}
exclude dropped theme. model_dump_json() returned JSON text, with double quotes and no spaces.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Calling it on the class: Settings.model_dump() | TypeError: BaseModel.model_dump() missing 1 required positional argument: 'self' | Call it on an instance: settings.model_dump() |
Expecting a JSON string from model_dump() | It returns a Python dict | Use model_dump_json() for text |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| A field you didn't want is in the dictionary | All fields are included by default | Pass exclude={"<field>"} |
FAQ
What happens to nested models?
They become dictionaries too: the guide says models are "(recursively) converted to dictionaries".
Conclusion
settings.model_dump() returned {'theme': 'dark', 'font_size': 14}, a plain dict with the checked values. Use exclude to drop fields and model_dump_json() for JSON text.
Additional Resources
- Serialization —
model_dump,model_dump_jsonand their options. - Models — the models guide.
