API Reference¶
Field annotations¶
- pydantic_views.ReadAndWrite¶
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
alias of
Annotated[T, <AccessMode.READ_AND_WRITE: 1>]
Other API¶
- class pydantic_views.AccessMode(*values)¶
Bases:
EnumField access mode.
- READ_AND_WRITE = 1¶
Read and write mark.
- READ_ONLY = 2¶
Read only mark.
- WRITE_ONLY = 3¶
Write only mark.
- READ_ONLY_ON_CREATION = 4¶
Read only on creation mark.
- WRITE_ONLY_ON_CREATION = 5¶
Write only on creation mark.
- HIDDEN = 6¶
Hidden mark.
- class pydantic_views.Builder(
- view_name: str,
- access_modes: tuple[AccessMode, ...],
- all_optional: bool = False,
- all_nullable: bool = False,
- hide_default_null: bool = False,
- include_computed_fields: bool = False,
Bases:
objectView builder. It create a view classes from models following given criterias.
- Parameters:
view_name – View name.
access_modes – Access modes to filter for.
all_optional – Make all fields optionals. On updates it allows to send just fields you want to change.
all_nullable – Make all fields nulleables. On some kinds of updates it could meant set default value.
hide_default_null – Hide
Noneas default value. It produces better examples.include_computed_fields – Whether computed fields must be included on view or not.
- build_from_model(
- model: type[T],
Builds a view from model
- Parameters:
model – Model class.
- Returns:
View of model class.
- pydantic_views.BuilderCreate(view_name: str = 'Create') Builder¶
Default builder for Create view. Views created by it keep fields with
access modeREAD_AND_WRITE,WRITE_ONLYandWRITE_ONLY_ON_CREATION. And hide defaultNonevalue. It produces a better schema examples.
- pydantic_views.BuilderCreateResult(
- view_name: str = 'CreateResult',
Default builder for CreateResult view. Views created by it keep fields with
access modeREAD_AND_WRITE,READ_ONLYandREAD_ONLY_ON_CREATION. And includes computed fields.
- pydantic_views.BuilderUpdate(view_name: str = 'Update') Builder¶
Default builder for Update view. Views created by it keep fields with
access modeREAD_AND_WRITEandWRITE_ONLY. And make all fields optional.
- pydantic_views.BuilderLoad(view_name: str = 'Load') Builder¶
Default builder for Load view. Views created by it keep fields with
access modeREAD_AND_WRITEandREAD_ONLY. And includes computed fields.
- pydantic_views.ensure_model_views(model: type[T])¶
Ensures model has a view manager and returns it.
- Parameters:
model – Model class.
- Returns:
Views manager for model class.
- class pydantic_views.Manager(model: type[TModel])¶
Bases:
GenericViews manager for a given model class.
- pydantic model pydantic_views.View¶
-
View of model.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Show JSON schema
{ "title": "View", "description": "View of model.", "type": "object", "properties": {} }
- Config:
protected_namespaces: tuple = (‘view_class_root’, ‘view_build’, ‘view_apply’)
- view_apply_to(model: T) T¶
Apply view data to associated model.
- Parameters:
model – Model instance to use as base..
- Returns:
Associated model instance with view data merged to given model data.
- classmethod view_build_from(model: T)¶
Build view from given model.
- Parameters:
model – Model class to build view from.
- Returns:
View of model class.
- view_build_to() T¶
Build associated model from view data.
- Returns:
Associated model instance with view data.
- pydantic model pydantic_views.RootView¶
Bases:
View[RootModel[TypeVar]],RootModel[TypeVar],GenericView for root models.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Show JSON schema
{ "title": "RootView", "description": "View for root models." }
- Config:
protected_namespaces: tuple = (‘view_class_root’, ‘view_build’, ‘view_apply’)
- Fields: