skillfed

pydantic-partial

Create partial models from your pydantic models. Partial models may allow None for certain or all fields.

pydantic-partial v0.11.1 194.6K downloads/30d#9,830 on PyPI78
Permissive license MIT Active released

What it is and what it does

pydantic-partial is a mixin and utility library that generates optional variants of pydantic models. It lets you take a normal pydantic BaseModel and create a version where all fields, or just selected ones, become optional and accept None values. This is particularly useful for API endpoints handling PATCH requests, where clients only send fields they want to update, or for response DTOs where you want to omit certain fields without validation errors.

The library provides two main interfaces: a PartialModelMixin you can inherit from, and a standalone create_partial_model() function for models you don't control. It also supports recursive partials for nested model structures. The tradeoff is that type checkers cannot see the optionality changes—partial models appear to type checkers as identical to their originals—so the library is best suited for API data-transfer scenarios rather than complex type-aware logic.

Use it for:

  • Handle PATCH HTTP requests where only some fields are provided and should not trigger validation errors for missing required fields.
  • Create response DTOs that omit certain fields without raising validation errors when combined with exclude_none.
  • Build flexible API request/response models that adapt field optionality based on use case without duplicating model definitions.
  • Support partial updates in database operations where only changed fields need to be validated and persisted.
  • Generate test fixtures and mock objects where you need to construct models with minimal required data.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts pydantic models into partial variants where all or selected fields become optional, enabling flexible validation for PATCH requests and partial response DTOs.

Yes, if you are building APIs with pydantic and FastAPI. The library solves a real gap in pydantic's design for PATCH requests and partial responses. Install friction is negligible, maintenance is active, and the MIT license carries no restrictions. The main caveat is that type checkers will not understand the partial optionality, so use it only for DTO/serialization contexts, not for type-critical business logic.

Install

pydantic-partial on PyPI

pip

pip install pydantic-partial

uv

uv add pydantic-partial

poetry

poetry add pydantic-partial

Installing pydantic-partial

Before you install

Low install friction with a single pydantic dependency. Actively maintained with recent releases; last commit 2026-08-08 and latest release 2026-06-26 indicate ongoing support.

License in practice

MIT license permits use in commercial and private projects with minimal restrictions, requiring only license and copyright notice retention.

Quickstart

pip install pydantic-partial

import pydantic
from pydantic_partial import PartialModelMixin

class User(PartialModelMixin, pydantic.BaseModel):
    name: str
    age: int

UserPartial = User.model_as_partial()
user = UserPartial()  # Both fields now optional

Requires Python 3.10 or later and pydantic 2.x; type checkers will not recognize partial field optionality.

Verify before relying

  • Whether partial models work correctly with pydantic validators and computed fields beyond the documented examples.
  • Performance impact when creating many partial model variants from large model hierarchies.
  • Compatibility with pydantic serialization modes (mode='json', mode='python') in partial contexts.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — pydantic
Maintenance actively maintained — 49 days since the last release
Last repo commit
First released
Downloads 194,591/month — #9,830 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pydantic_partial-0.11.1-py3-none-any.whl

Tags

pydantic optional fieldspartial models pydanticpatch request validationoptional pydantic fieldspydantic dto partialflexible field validationpydantic model variants
pydantic-extensionapi-dtopatch-requests

More Application Frameworks packages