Create partial models from your pydantic models. Partial models may allow None for certain or all fields.
Project description
pydantic-partial
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.
Partial models can be used to support PATCH HTTP requests where the suer only wants
to update some fields of the model and normal validation for required fields is not
required. It may also be used to have partial response DTO's where you want to skip
certain fields, this can be useful in combination with exclude_none
. It is - like
shown in these examples - intended to be used with API use cases, so when using
pydantic with for example FastAPI.
Disclaimer: This is the first public release of pydantic-partial. Things might change in the future.
Usage example
pydantic-partial provides a mixin to generate partial model classes. The mixin can be used like this:
# Something model, than can be used as a partial, too:
class Something(PartialModelMixin, pydantic.BaseModel):
name: str
age: int
# Create a full partial model
FullSomethingPartial = Something.as_partial()
FullSomethingPartial(name=None, age=None)
# You could also create a "partial Partial":
#AgeSomethingPartial = Something.as_partial("age")
Project details
Release history Release notifications | RSS feed
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
Hashes for pydantic_partial-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95fdd5d2e47af0203aac7b6b3119e350fb852090d8d3f10c6c01e63fdcd3f2a1 |
|
MD5 | 8a41f805ebb9be37261c1328100ca06d |
|
BLAKE2b-256 | d29228b5f9a7627d7546add18d7c2d64c4f0640f7f754dfc69065861cc244964 |