Pydantic vs Marshmallow
Pydantic vs marshmallow compared for 2026: Pydantic 2.14.4 (type-hint models with a Rust validation core, JSON Schema and OpenAPI output, MIT) vs marshmallow 4.4.0 (class-based schemas for load, dump and validation with no dependencies, MIT). Includes load and dump timings on 50,000 records, coercion and unknown-field behaviour, error formats and install size from runs we did on the same machine, plus a clear pick.
Quick Answer
Pydantic and marshmallow both turn untrusted input into validated Python data, but they start from different places. Pydantic 2.14.4 builds models from type hints, validates with a Rust core (pydantic-core 2.50.5), returns typed objects and generates JSON Schema, which is why FastAPI and most new typed code use it. marshmallow 4.4.0 keeps validation in separate Schema classes that load and dump plain dicts, has no dependencies and gives fine control over output shapes. In our run on 50,000 nested records, Pydantic validated 3-4x faster and serialized 4-12x faster, unless the model used EmailStr: email checking took about three quarters of Pydantic's time and brought both libraries to about 1.25 s. The behavioural differences matter more than speed. marshmallow silently turned 42.7 into 42 for an Integer field, where Pydantic rejected it; Pydantic silently ignored an unknown field, where marshmallow rejected it. Pick Pydantic for new typed code, APIs and settings; keep marshmallow where existing Flask or ORM code depends on its schemas, or where you need one model to produce many output shapes without typed classes.
Last updated November 24, 2026. Covers Pydantic 2.14.4 (19 November 2026, pydantic-core 2.50.5) and marshmallow 4.4.0 (3 November 2026) on Python 3.13.18; docs, changelogs, release data and package metadata read on 24 November 2026, plus same-machine load, dump, coercion and install-size runs we did that day.
| Feature | Pydantic | Marshmallow |
|---|---|---|
| Licence & Repository | MIT; pydantic/pydantic, ~29.6k stars, active (pushed 23 Nov 2026) | MIT; marshmallow-code/marshmallow, ~7.2k stars, active (pushed 24 Nov 2026) |
| Latest Release (Nov 2026) | 2.14.4 on 19 Nov 2026 (pydantic-core 2.50.5); 1.10.27 on 29 Oct 2026 | 4.4.0 (changelog 3 Nov 2026; 4.0.0 on 16 Apr 2025) |
| Supported Python | 3.10+ | 3.11+ (4.4.0 dropped 3.10) |
| Install Footprint | annotated-types, pydantic-core, typing-extensions, typing-inspection; 8 packages, 11.7 MB with [email] | None; 1 package, 0.5 MB |
| How You Define a Schema | BaseModel subclasses with type hints; TypeAdapter for any type | Schema subclasses with field objects and class Meta options |
| Validation Engine | pydantic-core (Rust) for most types | Pure Python |
| What load/validate Returns | Typed model instances | Plain dicts (objects via @post_load) |
| Default Type Coercion | Lax: '42' -> 42, 42.0 -> 42, 'yes' -> True, Unix timestamp -> datetime; 42.7 rejected | Lax: '42' -> 42, 42.7 -> 42, 'yes' -> True; Unix timestamp rejected by DateTime |
| Strict Mode | strict=True per model, field or call; JSON input keeps some string conversions (datetimes) | Per field: fields.Int(strict=True) rejected '42' and 42.7 |
| Unknown Fields (default) | Ignored (extra='ignore'); 'forbid' or 'allow' configurable | Rejected (unknown=RAISE); EXCLUDE or INCLUDE configurable |
| Error Format | List of dicts with type, loc, msg (and input, url) | Dict of field name -> list of messages; valid_data available |
| Serialization (dump) | model_dump / model_dump_json, mode='json', include/exclude | dump / dumps; only, exclude, many; no validation on dump |
| JSON Schema / OpenAPI | Built in: model_json_schema(), Draft 2020-12, OpenAPI 3.1.0 compatible | Not built in |
| Static Typing Support | Native: fields are type hints | Typed Field generics since 4.0; loaded data is a dict |
| Framework Ecosystem | FastAPI and many SDKs; Celery 5.7 tasks accept Pydantic models with pydantic=True 10/10 | Flask-Marshmallow and Django REST Marshmallow integrations (named in its docs); works with any ORM or none 7/10 |
| Our Run: validate 50,000 records (no email check) | 0.26-0.34 s from dicts; 0.25 s from raw JSON (validate_json) | 1.08-1.11 s from dicts (Str email field) |
| Our Run: same, with email validation | 1.25-1.32 s from dicts; 1.21-1.29 s from raw JSON | 1.24-1.26 s from dicts; 1.36-1.44 s from a JSON string (loads) |
| Our Run: serialize 50,000 objects to JSON | 0.045-0.047 s to JSON bytes; 0.10 s to JSON-ready dicts | 0.53-0.54 s to a JSON string; 0.45-0.46 s to dicts |
| Our Run: 42.7 into an int field | Error: int_from_float ('got a number with a fractional part') | Accepted and truncated to 42 (rejected only with strict=True) |
| Our Run: import time / install size | 0.06-0.07 s warm import; 11.7 MB, 8 packages with [email] | 0.03 s warm import; 0.5 MB, 1 package |
Pydantic
Pydantic is a data validation library that uses Python type hints to define models. You subclass BaseModel, annotate fields, and validate dicts, objects or raw JSON into typed instances; validation for most types runs in pydantic-core, written in Rust. It coerces compatible input by default, offers a strict mode, serializes with model_dump and model_dump_json, and generates JSON Schema (Draft 2020-12) compatible with OpenAPI 3.1.0. Pydantic 2.14.4 was released on 19 November 2026, requires Python 3.10 or newer, is MIT-licensed and has about 29.6k GitHub stars; the 1.10.x line still gets releases (1.10.27 on 29 October 2026).
Pros
- Fast where it counts: validated 50,000 nested records in 0.25-0.34 s and dumped them to JSON bytes in 0.045 s in our run, against 1.08-1.11 s and 0.53 s for marshmallow
- Models are typed classes, so editors, mypy and pyright see field types without plugins or a parallel schema
- validate_json parses and validates raw JSON in one step, as fast as validating already-parsed dicts in our run
- Rejects lossy coercion: 42.7 for an int field raised int_from_float instead of truncating
- Built-in JSON Schema (Draft 2020-12) and OpenAPI 3.1.0 compatibility, which FastAPI uses to generate API docs
- Structured errors with a machine-readable type, a location tuple and a message for every failing field
Cons
- Unknown fields are ignored by default: a stray 'role' key was dropped without error unless you set extra='forbid'
- Lax mode coerces more than some teams expect: '42' became 42, 'yes' became True and a Unix timestamp became a UTC datetime
- Heavier install: pydantic-core is a compiled wheel; with the email extra we installed 8 packages and 11.7 MB, against 0.5 MB for marshmallow
- EmailStr depends on the pure-Python email-validator package and made validation about 4x slower in our run (1.25-1.32 s vs 0.26-0.34 s)
- Version 1 to 2 was a large migration, and both lines are still in use in older codebases and tutorials
Best For
New Python code with type hints: FastAPI and other API layers, settings and config loading, parsing third-party JSON, LLM structured output, and anywhere static type checkers should see the same model that validates data.
Marshmallow
marshmallow is an ORM- and framework-agnostic library for converting complex data types to and from native Python types. You declare a Schema class with field objects (fields.Int, fields.Email, fields.Nested), then call load to deserialize and validate input and dump to serialize objects. Schemas return plain dicts unless you add a post_load hook, reject unknown fields by default, and can be narrowed per call with only, exclude and partial. marshmallow 4.4.0 (changelog dated 3 November 2026) requires Python 3.11 or newer, is MIT-licensed, has no dependencies and has about 7.2k GitHub stars.
Pros
- Zero dependencies and a tiny install: 1 package, 0.5 MB, and a 0.03 s warm import in our run
- Rejects unknown fields by default ('Unknown field.'), with unknown=EXCLUDE or INCLUDE when you want otherwise
- Schemas are decoupled from your classes: one schema can dump ORM objects, dicts or dataclasses, and only/exclude produce several output shapes from one definition
- Error messages are a simple field-to-messages dict that is easy to return from an API as-is
- Mature extension points: pre_load, post_load, pre_dump, post_dump hooks, @validates for one or several fields and, since 4.3.0, field-level pre_load/post_load
- Familiar to anyone who used Django REST Framework serializers, which inspired it
Cons
- Silently truncated 42.7 to 42 for a default Integer field in our run; you need strict=True to reject it
- Slower: 1.08-1.11 s to load 50,000 records and 0.53 s to dump them to JSON, against 0.26-0.34 s and 0.045 s for Pydantic
- No built-in JSON Schema or OpenAPI generation; Schema in 4.4.0 has no such method, so you need a separate package
- Schemas duplicate your type information: static type checkers do not see loaded data as typed objects
- dump does not validate: dumping a non-numeric string through an Integer field raised a plain ValueError rather than a ValidationError
Best For
Existing Flask and ORM-backed codebases built around marshmallow schemas, serializers that must reshape the same objects into several outputs, and dependency-free environments.
Models from type hints versus separate schemas
The core difference is where the schema lives. In Pydantic the type hints are the schema: class User(BaseModel) with id: int and address: Address gives you a class that validates on construction, returns a typed instance, and is understood by mypy, pyright and your editor without plugins. TypeAdapter does the same for types that are not models, such as list[User]. In marshmallow the schema is a separate class of field objects: UserSchema with id = fields.Int(required=True). Calling load returns a plain dict (or an object, if you add a post_load hook), and dump serializes whatever object you pass, whether an ORM row, a dataclass or a dict. That separation is marshmallow's strength when one set of objects must be rendered in several shapes: its docs show one schema producing a full game state, a summary with only=('_id', 'last_changed'), and a list view. It is a cost when your code is typed, because the same fields are declared twice. Pydantic's design also explains its speed: validation for most types runs in pydantic-core, written in Rust, while marshmallow is pure Python with no dependencies. Both are maintained: Pydantic 2.14.4 shipped on 19 November 2026 with a 1.10.x maintenance line, and marshmallow 4.4.0 on 3 November 2026 dropped Python 3.10 and added 3.15 testing.
What we measured: 50,000 records in, 50,000 out
We used the same nested record in both libraries: an int id, an email, a name, an int age, an ISO 8601 datetime with offset, a bool, a list of strings, a nested address with three strings and a float score. We generated 50,000 of them and timed each operation on one pinned CPU core (best of five, two rounds) with Python 3.13.18, Pydantic 2.14.4 and marshmallow 4.4.0. With the email field as a plain string, Pydantic validated the list of dicts in 0.26-0.34 s and raw JSON bytes via TypeAdapter.validate_json in 0.25 s; marshmallow's load took 1.08-1.11 s. Serializing was the larger gap: Pydantic's dump_json produced JSON bytes in 0.045-0.047 s and model_dump(mode='json') produced dicts in 0.10 s, against 0.53-0.54 s for marshmallow's dumps and 0.45-0.46 s for dump. Then we switched to real email validation (EmailStr, fields.Email). Pydantic slowed to 1.25-1.32 s and marshmallow to 1.24-1.26 s: email-validator, a pure-Python dependency, dominated Pydantic's time. Import took 0.06-0.07 s for Pydantic and 0.03 s for marshmallow once cached. These are synthetic single-machine runs, not a benchmark; Pydantic's own docs make larger performance claims for specific cases, which we did not test.
Coercion, unknown fields and strictness: the behaviour gaps
We fed both libraries the same edge cases with default settings. Both accepted '42' for an int, 42.0 for an int, 'yes' for a bool and a date-only string for a datetime (midnight, naive); both rejected 5 for a string and 'maybe' for a bool. The differences are where bugs hide. For 42.7 in an int field, Pydantic raised int_from_float, but marshmallow returned 42, silently dropping the fraction; fields.Int(strict=True) rejected it. For a Unix timestamp in a datetime field, Pydantic produced a UTC datetime and marshmallow rejected it. For an unknown key, the defaults are opposite: Pydantic ignored it, because extra='ignore' is the default, while marshmallow raised 'Unknown field.' because unknown=RAISE is its default. If you migrate in either direction, set these explicitly: extra='forbid' in Pydantic, or unknown=EXCLUDE in marshmallow. Strict modes differ too. Pydantic's strict=True rejected '42' for an int and, for Python-dict input, an ISO string for a datetime; with model_validate_json the same strict model accepted the datetime string, as its docs describe. marshmallow's strictness is per Integer field. Errors also differ in shape: Pydantic returns a list of type, loc and msg entries (four entries for our four bad fields), marshmallow a dict of field name to messages.
Serialization, JSON Schema and ecosystem
Output is where marshmallow was born and where Pydantic has caught up. Pydantic serializes with model_dump and model_dump_json, with include, exclude, aliases and a JSON mode that converts datetimes and other types to JSON-safe values. marshmallow's dump and dumps support only, exclude, many and pre_dump and post_dump hooks, and its class-based schemas can be composed and nested, including self-nesting. One trap we hit: marshmallow does not validate on dump, so passing a non-numeric string through an Integer field raised a plain ValueError rather than a ValidationError. For API contracts, Pydantic generates JSON Schema itself: model_json_schema() returned a Draft 2020-12 schema with types, required fields and date-time formats, and its docs state compatibility with OpenAPI 3.1.0. That is how FastAPI builds its OpenAPI docs from your models. marshmallow 4.4.0's Schema has no JSON Schema method, so documentation needs a separate package. Ecosystems follow from this. Pydantic sits under FastAPI and many SDKs, and Celery 5.7.0 now lets tasks declared with pydantic=True accept Pydantic model instances. marshmallow's docs point to Flask-Marshmallow and Django REST Marshmallow integrations and stress that it works with any ORM or none, and it suits codebases where serializers live apart from models.
Limits, migration and when not to use each
Do not choose marshmallow for a new FastAPI service or for code that should be typed end to end: you will declare fields twice and lose built-in JSON Schema. Do not choose Pydantic purely for speed if your validation is dominated by pure-Python checks such as email: our EmailStr run erased its advantage. Do not rely on either library's defaults for untrusted input without checking them: Pydantic's ignored extras and marshmallow's float truncation both passed bad data without an error in our tests. Migration costs are real in both directions. Moving from marshmallow means turning Schema classes into BaseModel classes, replacing post_load object construction (Pydantic returns instances already), translating @validates and @validates_schema into field and model validators, and rewriting error handling from a dict to a list of loc and msg entries. marshmallow 4.0 (April 2025) was itself a breaking release: it removed Schema.context in favour of contextvars, renamed pass_many to pass_collection, and switched date parsing to the standard library's fromisoformat, so a 3.x codebase has its own upgrade to plan. Pydantic's 1-to-2 migration is behind most projects now, but 1.10.x still receives releases, so check which major version a library or tutorial targets before copying code.
Verdict
Pick Pydantic for new code. It validated our records 3-4x faster and serialized them 4-12x faster, its models are the same typed classes your editor and type checker use, it generates JSON Schema for FastAPI and OpenAPI, and it refuses lossy conversions such as 42.7 into an int. Set extra='forbid' on models that face untrusted input, because the default silently drops unknown fields, and use strict mode where '42' must not become 42. Keep marshmallow where it already works: Flask and ORM-backed apps built on its schemas, APIs that dump the same objects into several shapes with only and exclude, or environments where a dependency-free 0.5 MB package matters. If you stay on marshmallow, add strict=True to Integer fields that must not truncate floats, and be aware that dump does not validate. Do not migrate a working marshmallow codebase for speed alone if your schemas use email or URL validation heavily: with EmailStr in the model, both libraries took about 1.25 s for 50,000 records in our run. Migrate when you want typed models end to end or FastAPI integration.