Makes partial Pydantic models without making fields nullable.
Project description
pydantic-strict-partial
Like pydantic-partial, but respects all the validators, and not nullable field. GitHub homepage.
Installation
pydantic-strict-partial
compatible with Python 3.10+ and Pydantic 2.1+.
Using pip
pip install pydantic-strict-partial
Using poetry
poetry add pydantic-strict-partial
About
Create partial models from your normal pydantic models. Partial models will allow some or all fields to be optional and thus not be required when creating the model instance.
The most common use case is a PATCH request on FastAPI endpoints where you want to allow partial updates.
Usage
from typing import Annotated
from annotated_types import Ge
from pydantic import BaseModel
from pydantic_strict_partial import create_partial_model
class UserSchema(BaseModel):
name: str
nickname: str | None
age: Annotated[int, Ge(18)]
UserPartialUpdateSchema = create_partial_model(UserSchema)
assert UserPartialUpdateSchema(age=20).model_dump(exclude_unset=True) == {
'age': 20
}
UserPartialUpdateSchema(name=None) # raises ValidationError
UserPartialUpdateSchema(age=17) # raises ValidationError
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pydantic_strict_partial-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f3994f0a41938ed4657627db3c8fe03dae0fc556da7ad9111b1b18b5ab3e834 |
|
MD5 | ca302406967c1a6d9206a52df669f430 |
|
BLAKE2b-256 | 5a325dbf89bbc8dbb2db1b3f47b9d72605941723a29a9f4a022d111b1aea64bb |
Close
Hashes for pydantic_strict_partial-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c1b41111c773c1208700ee2544d152615862324aed557ccabf8607ca306fc82 |
|
MD5 | 0587aa7b6adadd1a4cdb74a1b51e3c53 |
|
BLAKE2b-256 | 8471a1912685c2b5f7d96258a62c0c1c31870000ce16ebe4f52683025e94d574 |