API Reference¶
Field annotations¶
- pydantic_views.ReadAndWrite: TypeAlias¶
Read and write field annotation. Field could be read and written always.
alias of
Annotated[T,READ_AND_WRITE]
- pydantic_views.ReadOnly: TypeAlias¶
Read only field annotation. Field could be read always but never written.
alias of
Annotated[T,READ_ONLY]
- pydantic_views.WriteOnly: TypeAlias¶
Write only field annotation. Field could be written always but never read.
alias of
Annotated[T,WRITE_ONLY]
- pydantic_views.ReadOnlyOnCreation: TypeAlias¶
Read only on creation field annotation. Field could be read only after creation, and never again.
alias of
Annotated[T,READ_ONLY_ON_CREATION]
- pydantic_views.WriteOnlyOnCreation: TypeAlias¶
Write only on creation field annotation. Field could be written only after creation, and never again.
alias of
Annotated[T,WRITE_ONLY_ON_CREATION]
Classes¶
- 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.- Parameters:
view_name – View name.
- Returns:
Builder configured for Create views.
- 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.- Parameters:
view_name – View name.
- Returns:
Builder configured for CreateResult views.
- 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.- Parameters:
view_name – View name.
- Returns:
Builder configured for Update views.
- 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.- Parameters:
view_name – View name.
- Returns:
Builder configured for Load views.
- 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_to’, ‘view_apply_to’, ‘view_build_from’)
- 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_to’, ‘view_apply_to’, ‘view_build_from’)
- Fields: