Pydantic Plugins
Usage docs: https://docs.pydantic.dev/2.8/concepts/plugins#build-a-plugin
Plugin interface for Pydantic plugins, and related types.
Bases: NamedTuple
Path defining where schema_type was defined, or where TypeAdapter was called.
Type: str
Type: str
Bases: Protocol
Protocol defining the interface for Pydantic plugins.
def new_schema_validator(
schema: CoreSchema,
schema_type: Any,
schema_type_path: SchemaTypePath,
schema_kind: SchemaKind,
config: CoreConfig | None,
plugin_settings: dict[str, object],
) -> tuple[ValidatePythonHandlerProtocol | None, ValidateJsonHandlerProtocol | None, ValidateStringsHandlerProtocol | None]
This method is called for each plugin every time a new SchemaValidator
is created.
It should return an event handler for each of the three validation methods, or None if the plugin does not
implement that method.
tuple[ValidatePythonHandlerProtocol | None, ValidateJsonHandlerProtocol | None, ValidateStringsHandlerProtocol | None] — A tuple of optional event handlers for each of the three validation methods -
validate_python, validate_json, validate_strings.
The schema to validate against.
The original type which the schema was created from, e.g. the model class.
Path defining where schema_type was defined, or where TypeAdapter was called.
The kind of schema to validate against.
The config to use for validation.
Any plugin settings.
Bases: Protocol
Base class for plugin callbacks protocols.
You shouldn’t implement this protocol directly, instead use one of the subclasses with adds the correctly
typed on_error method.
on_enter is changed to be more specific on all subclasses
Type: Callable[..., None]
def on_success(result: Any) -> None
Callback to be notified of successful validation.
None
The result of the validation.
def on_error(error: ValidationError) -> None
Callback to be notified of validation errors.
None
The validation error.
def on_exception(exception: Exception) -> None
Callback to be notified of validation exceptions.
None
The exception raised during validation.
Bases: BaseValidateHandlerProtocol, Protocol
Event handler for SchemaValidator.validate_python.
def on_enter(
input: Any,
strict: bool | None = None,
from_attributes: bool | None = None,
context: dict[str, Any] | None = None,
self_instance: Any | None = None,
) -> None
Callback to be notified of validation start, and create an instance of the event handler.
None
The input to be validated.
Whether to validate the object in strict mode.
Whether to validate objects as inputs by extracting attributes.
The context to use for validation, this is passed to functional validators.
An instance of a model to set attributes on from validation, this is used when running
validation from the __init__ method of a model.
Bases: BaseValidateHandlerProtocol, Protocol
Event handler for SchemaValidator.validate_json.
def on_enter(
input: str | bytes | bytearray,
strict: bool | None = None,
context: dict[str, Any] | None = None,
self_instance: Any | None = None,
) -> None
Callback to be notified of validation start, and create an instance of the event handler.
None
The JSON data to be validated.
Whether to validate the object in strict mode.
The context to use for validation, this is passed to functional validators.
An instance of a model to set attributes on from validation, this is used when running
validation from the __init__ method of a model.
Bases: BaseValidateHandlerProtocol, Protocol
Event handler for SchemaValidator.validate_strings.
def on_enter(
input: StringInput,
strict: bool | None = None,
context: dict[str, Any] | None = None,
) -> None
Callback to be notified of validation start, and create an instance of the event handler.
None
The string data to be validated.
Whether to validate the object in strict mode.
The context to use for validation, this is passed to functional validators.
Type: TypeAlias Default: 'tuple[ValidatePythonHandlerProtocol | None, ValidateJsonHandlerProtocol | None, ValidateStringsHandlerProtocol | None]'
Type: TypeAlias Default: Literal['BaseModel', 'TypeAdapter', 'dataclass', 'create_model', 'validate_call']
Type: TypeAlias Default: 'dict[str, StringInput]'