Skip to main content

Pydantic++

CI Release PyPI version

Pydantic++ is a suite of utilities to improve upon the core Pydantic library. We stand on the shoulders of giants here. Huge kudos to the Pydantic team for all their hard work building an amazing product.

Utilities

  • Partial Models — type-safe "partial" Pydantic models where some or all fields are optional
  • Model Updater — type-safe immutable builder for updating model instances
  • Model Registry — discover all BaseModel subclasses in a module tree
  • Dummy Models — generate dummy model instances with random data for testing
  • Mypy Plugin — full mypy integration for partial models and model updates

Installation

pip install pydantic-plus-plus

Requires Python 3.10+ and Pydantic 2.0+.

If you use mypy for type checking, please also add our plugin to your mypy configuration.

[tool.mypy]
plugins = ["pydantic.mypy", "pydantic_plus_plus.mypy"]

Partial Models

partial creates a PartialBaseModel, a variant of the given Pydantic BaseModel where every field is Optional with a default of None. This is the type-safe way to represent partial updates (PATCH payloads, upsert data, sparse sync records) without manually duplicating each model with every field made optional.

Model Updater

update provides a type-safe, immutable builder for updating Pydantic model instances. Pydantic's built-in model_copy(update={"field": value}) takes a dict[str, Any] — you lose all type safety, typos are invisible, and nested updates are painful. update fixes all of this.

Model Registry

ModelRegistry scans one or more Python modules (and all submodules) and collects every BaseModel subclass it finds. This is useful when you have a base class — say BasePrompt, AgentConfig, or BaseEvent — and you need to discover all concrete implementations at runtime for dispatching, serialization, CLI tooling, or documentation generation.

Dummy Models

dummy generates an instance of any Pydantic BaseModel populated with random data. This is useful for testing — round-trip serialization, factory fixtures, property-based tests — anywhere you need a valid model instance without hand-writing every field.

Mypy Plugin

Pydantic++ ships a mypy plugin that gives partial models and model updates full type safety. Without it, mypy sees partial(User) as returning a generic type and can't validate field access or constructor arguments. Similarly, ModelUpdater methods like .set() and .append() would accept any keyword argument without type checking.

With the plugin enabled:

  • Partial models get field-level type checking, constructor validation, and IDE autocompletion.
  • ModelUpdater methods get typed keyword arguments — mypy validates field names, value types, and restricts operations to applicable fields (e.g., .append() only accepts sequence fields).

Comparable Packages

Why Pydantic++ over pydantic-partial?

Pydantic++ offers a similar feature set, but takes a different philosophical approach than pydantic-partial that is more aligned with SOLID Object Oriented design principles.

Here's how the two differ:

Pydantic++ pydantic-partial
Partial models All fields optional All fields optional
Selective fields Yes Yes
Dot-notation nesting Yes Yes
Wildcard nesting Yes Yes
Field metadata preservation Yes Yes
Caching Yes Yes
Recursive by default Yes No (opt-in)
Mypy plugin Yes No
.apply() deep merge Yes No
Standalone partial classes Yes — partials don't subclass the original No — partials subclass the original

Philosophical Differences

pydantic-partial's partials subclass the original model, so isinstance(patch, User) is True. This violates the Liskov Substitution Principle — a partial User weakens the preconditions of the original (required fields become optional), meaning code that expects a complete User can silently receive one with None fields. In addition to breaking LSP, this also causes problems for type checkers because the subclass relationship tells type checkers the partial is a User.

Pydantic++ takes a different philosophical approach, where partials are standalone classes. This preserves LSP. Additionally, because isinstance(patch, User) is False, the type checker can enforce the boundary between partial and complete data. Users must go through .apply() to produce a real User, making the conversion explicit and safe.

Mypy plugin

This is a well known limitation of pydantic-partial. Pydantic++ ships a mypy plugin that synthesizes full TypeInfo objects, giving users field-level type checking and constructor validation with zero # type: ignore comments.

.apply() deep merge

pydantic-partial creates partial models but has no built-in way to merge a partial back into an existing instance. Pydantic++ provides .apply() which recursively merges only explicitly-set fields, preserving untouched nested data.

License

MIT

Metadata

Release files for pydantic-plus-plus 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-plus-plus 1.0.0
File Size Uploaded
pydantic_plus_plus-1.0.0.tar.gz 122.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-plus-plus 1.0.0
File Interpreter ABI Platform
pydantic_plus_plus-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 162.1 kB

Release files / pydantic_plus_plus-1.0.0.tar.gz

Download URL pydantic_plus_plus-1.0.0.tar.gz
Size 122.3 kB
Tags Source
SHA-256 checksum
How to use checksums
704c113dbf5dd51c35fc0aa9a7c67dc292a56c4a73736933e5769e6d79cfa0db
BLAKE2b-256 checksum
How to use checksums
d97d8faeced8606764cfd4f8734e827e44ace480ada5297577cb044dc061f659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 31, 2026.

Transparency log

Release files / pydantic_plus_plus-1.0.0-py3-none-any.whl

Download URL pydantic_plus_plus-1.0.0-py3-none-any.whl
Size 39.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4edd1de03ddb64a0fc1735715babd9cb453e08aba3d174d07f992511794d6d53
BLAKE2b-256 checksum
How to use checksums
07ca9eec09633749903bb5f99c0e97b5a758cb75a1d1dd6ce5c9601a3d3bdd81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 31, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page