This release is a pre-release and may not be stable for production use.
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.
Legal disclaimer
pydantic-views is an independent, community-maintained project. It is not affiliated with, endorsed by, sponsored by, or otherwise associated with the Pydantic project or its maintainers.
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.0b3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydantic_views-0.14.0b3.tar.gz | 30.4 kB | With provenance | Details for pydantic_views-0.14.0b3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydantic_views-0.14.0b3-py3-none-any.whl | Python 3 | none | any | Details for pydantic_views-0.14.0b3-py3-none-any.whl |
Total release size: 62.7 kB
Release files / pydantic_views-0.14.0b3.tar.gz
| Download URL | pydantic_views-0.14.0b3.tar.gz |
|---|---|
| Size | 30.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8a93a6fbe1819b60cd652b4f9b62291b2ce35096ca06287b64e4bc761ffed0e1
|
|
BLAKE2b-256 checksum How to use checksums |
06ac7da1a7622f124b143f67ebe790e7bb1e15a7e1fb8343f341e563dd69cf7a
|
| 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 logRelease files / pydantic_views-0.14.0b3-py3-none-any.whl
| Download URL | pydantic_views-0.14.0b3-py3-none-any.whl |
|---|---|
| Size | 32.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52a1cd1860ba69ace77f907cdf993c6d8c50887d7d3d48349842f608c6066be6
|
|
BLAKE2b-256 checksum How to use checksums |
246a966141190a881651a9142f80fe5efbe71b804ddefc2f65db67aa294e2448
|
| 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 logSecurity for pydantic-views 0.14.0b3
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.
Attestation for pydantic_views-0.14.0b3.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 logA 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.