Skip to main content
Change of provenance

The repository or configuration that created this release differ from a previous release. View details.

Documentation Supported Python versions Typed package License PyPI version

pydantic-views — typed schemas from one model

Pydantic Views

One domain model. Purpose-built schemas for every operation.

Define your fields and access rules once, then derive Pydantic models for creation, responses, updates, and internal workflows. Keep validation constraints and field metadata consistent as your application grows, without maintaining a separate schema by hand for each operation.

The generated views are Pydantic models: validate input, serialize output, and generate JSON Schema with the APIs you already use.

Installation

Requires Python 3.13 or later and Pydantic 2.

pip install pydantic-views

Install with uv as an alternative:

uv add pydantic-views

From one model to an API boundary

from pydantic import BaseModel, Field
from pydantic_views import (
    LoadPreset, ReadOnly, UpdatePreset, View, WriteOnly,
)

class User(BaseModel):
    id: ReadOnly[int]
    name: str = Field(min_length=1)
    password: WriteOnly[str]

class UserLoad(View[User], preset=LoadPreset):
    pass

class UserUpdate(View[User], preset=UpdatePreset):
    pass

stored = User(id=1, name="Ada", password="stored-hash")
response = UserLoad.view_build_from(stored)
assert response.model_dump() == {"id": 1, "name": "Ada"}

changes = UserUpdate.model_validate({"name": "Grace"})
assert changes.model_dump() == {"name": "Grace"}
updated = changes.view_apply_to(stored)
assert updated.name == "Grace"
assert updated.password == "stored-hash"

The load view excludes the password. The update view excludes the ID and accepts omitted fields, while retaining the name’s validation constraint. Nested models receive matching views automatically.

The generated stub makes these contracts visible to editors and type checkers. The view declarations in models.pyi look like this (source-model definitions are omitted here):

from pydantic_core import MISSING
from pydantic_views import View

class UserLoad(View[User]):
    id: int
    name: str

    def __init__(self, *, id: int, name: str) -> None: ...

class UserUpdate(View[User]):
    name: str | MISSING
    password: str | MISSING

    def __init__(
        self, *, name: str | MISSING = ..., password: str | MISSING = ...
    ) -> None: ...

UserLoad has no password field; UserUpdate has no ID field. Its constructor accepts either change independently, and omitted values remain MISSING.

What you can build

  • Operation-specific schemas: five presets for create, create-result, load, update, and unrestricted partial data; custom presets and builders for other workflows.

  • Explicit field access: read-only, write-only, creation-only, and hidden annotations; combine access modes and use tags for more selective views.

  • Consistent field definitions: retain aliases, defaults, descriptions, JSON Schema metadata, and annotation-based constraints such as Field(min_length=1).

  • Structured data: derive matching views for nested and recursive models, generic models, RootModel, and models inside lists, sets, tuples, dictionaries, and unions.

  • Partial updates: distinguish an omitted field (MISSING) from an explicit None; merge nested models and mappings into existing data.

  • Flexible construction: declare View[Model] subclasses with extra fields or generate and cache classes dynamically with a Builder and per-model Manager.

  • Computed response fields: include computed values in load and create-result views.

  • Static tooling: a mypy plugin for declared views and a runtime .pyi generator for Pyright, Pylance, and other stub-aware tools. The package includes py.typed.

Choose a preset

Preset

Fields included

Behavior

CreatePreset

Writable and write-on-creation

Hides default None values

CreateResultPreset

Readable and read-on-creation

Includes computed fields

LoadPreset

Readable

Includes computed fields

UpdatePreset

Writable

All selected fields optional

PartialPreset

All model fields, regardless of access mode

All optional; no computed fields

Unmarked fields participate in every standard preset. PartialPreset also includes hidden and write-only fields: use it for trusted internal data, not as a filtered public response. Access annotations define schema contents; application authorization remains separate.

Type checking

For mypy, enable both plugins in this order:

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

For stub-aware editors and type checkers, generate stubs from your runtime models:

python -m pydantic_views.stubgen myapp.models

This writes myapp/models.pyi next to the source. Regenerate it when the models change; a type checker uses the adjacent stub in preference to the Python file. The mypy plugin skips stub files, so generated stubs and the plugin can coexist.

Continue reading

  • User guide: access rules, presets, custom views, nested data, and update semantics.

  • Practical examples: complete workflows with executable assertions.

  • Type checking: plugin configuration, stub generation, and current limitations.

  • API reference: public annotations, presets, builders, and view helpers.

Source code and issue tracking are available on GitHub.

Metadata

Release files for pydantic-views 0.14.0

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

Change of provenance

The repository or configuration that created these release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Source distribution (sdist)

Source distribution for pydantic-views 0.14.0
File Size Uploaded Provenance Actions
pydantic_views-0.14.0.tar.gz 30.4 kB With provenance Details for pydantic_views-0.14.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-views 0.14.0
File Interpreter ABI Platform Actions
pydantic_views-0.14.0-py3-none-any.whl Python 3 none any Details for pydantic_views-0.14.0-py3-none-any.whl

Total release size: 62.7 kB

Release files / pydantic_views-0.14.0.tar.gz

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL pydantic_views-0.14.0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
448df9700e849648cb9bdd1083458acb2f62fb370a90c71e758be18fcea5b138
BLAKE2b-256 checksum
How to use checksums
bf7a3a7f2a0e79eecb496b3508af0de5a045ee75bb27ecc97d17b9ae7de640cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 23, 2026.

Transparency log

Release files / pydantic_views-0.14.0-py3-none-any.whl

Change of provenance

This file belongs to a release with changed provenance: the repository or configuration that created the release files differ from that of a previous release.

We recommend inspecting the repository and configuration before proceeding. View details.

Download URL pydantic_views-0.14.0-py3-none-any.whl
Size 32.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ec528488360ce3235e1d80436d532b371c51093aa7872f40374ca401517c245
BLAKE2b-256 checksum
How to use checksums
fb2ee38152694777b02222506df93e731581e43422e1f1cccccab5acd024d519
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 23, 2026.

Transparency log

Security for pydantic-views 0.14.0

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.

Change of provenance

The configuration that created this release differs from a previous release.

While this could reflect a routine change by the project maintainers, it may also indicate that the release files have been compromised.

Select from 2 files

Attestation for pydantic_views-0.14.0.tar.gz

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 Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
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