Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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.0rc0

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-views 0.14.0rc0
File Size Uploaded Provenance Actions
pydantic_views-0.14.0rc0.tar.gz 30.4 kB With provenance Details for pydantic_views-0.14.0rc0.tar.gz

Built distribution (wheel)

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

Total release size: 62.7 kB

Release files / pydantic_views-0.14.0rc0.tar.gz

Download URL pydantic_views-0.14.0rc0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
922590be41f243bcf96c742f4b33d80e686300bb774d315f7c170041f0a1ee54
BLAKE2b-256 checksum
How to use checksums
e278a2da042266f175d6b4ebf841cf12cf4ef3166ce6f7119b473bbb9c6faf8d
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.0rc0-py3-none-any.whl

Download URL pydantic_views-0.14.0rc0-py3-none-any.whl
Size 32.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccae211de82f57b965f0539c2b781a9b99dcc7b672b52d77f86687601d8f29cc
BLAKE2b-256 checksum
How to use checksums
890b8e6738a2e4cb325976c032deda040bb83ce8b0bc68d5b6f6402aaf4ea7e8
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.0rc0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_views-0.14.0rc0.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