Experimental API¶
Pipeline API¶
Experimental pipeline API functionality. Be careful with this API, it's subject to change.
_Pipeline
dataclass
¶
_Pipeline(_steps: tuple[_Step, ...])
Bases: Generic[_InT, _OutT]
Abstract representation of a chain of validation, transformation, and parsing steps.
transform ¶
Transform the output of the previous step.
If used as the first step in a pipeline, the type of the field is used. That is, the transformation is applied to after the value is parsed to the field's type.
Source code in pydantic/experimental/pipeline.py
136 137 138 139 140 141 142 143 144 145 |
|
validate_as ¶
validate_as(
tp: EllipsisType, *, strict: bool = ...
) -> _Pipeline[_InT, Any]
validate_as(
tp: type[_NewOutT] | EllipsisType,
*,
strict: bool = False
) -> _Pipeline[_InT, Any]
Validate / parse the input into a new type.
If no type is provided, the type of the field is used.
Types are parsed in Pydantic's lax
mode by default,
but you can enable strict
mode by passing strict=True
.
Source code in pydantic/experimental/pipeline.py
154 155 156 157 158 159 160 161 162 163 164 |
|
validate_as_deferred ¶
Parse the input into a new type, deferring resolution of the type until the current class is fully defined.
This is useful when you need to reference the class in it's own type annotations.
Source code in pydantic/experimental/pipeline.py
166 167 168 169 170 171 172 |
|
constrain ¶
constrain(constraint: Ge) -> _Pipeline[_InT, _NewOutGe]
constrain(constraint: Gt) -> _Pipeline[_InT, _NewOutGt]
constrain(constraint: Le) -> _Pipeline[_InT, _NewOutLe]
constrain(constraint: Lt) -> _Pipeline[_InT, _NewOutLt]
constrain(constraint: Len) -> _Pipeline[_InT, _NewOutLen]
constrain(
constraint: MultipleOf,
) -> _Pipeline[_InT, _NewOutT]
constrain(
constraint: Timezone,
) -> _Pipeline[_InT, _NewOutDatetime]
constrain(constraint: Predicate) -> _Pipeline[_InT, _OutT]
constrain(
constraint: Interval,
) -> _Pipeline[_InT, _NewOutInterval]
constrain(constraint: _Eq) -> _Pipeline[_InT, _OutT]
constrain(constraint: _NotEq) -> _Pipeline[_InT, _OutT]
constrain(constraint: _In) -> _Pipeline[_InT, _OutT]
constrain(constraint: _NotIn) -> _Pipeline[_InT, _OutT]
constrain(constraint: _ConstraintAnnotation) -> Any
Constrain a value to meet a certain condition.
We support most conditions from annotated_types
, as well as regular expressions.
Most of the time you'll be calling a shortcut method like gt
, lt
, len
, etc
so you don't need to call this directly.
Source code in pydantic/experimental/pipeline.py
225 226 227 228 229 230 231 232 233 |
|
predicate ¶
Constrain a value to meet a certain predicate.
Source code in pydantic/experimental/pipeline.py
235 236 237 |
|
gt ¶
gt(gt: _NewOutGt) -> _Pipeline[_InT, _NewOutGt]
Constrain a value to be greater than a certain value.
Source code in pydantic/experimental/pipeline.py
239 240 241 |
|
lt ¶
lt(lt: _NewOutLt) -> _Pipeline[_InT, _NewOutLt]
Constrain a value to be less than a certain value.
Source code in pydantic/experimental/pipeline.py
243 244 245 |
|
ge ¶
ge(ge: _NewOutGe) -> _Pipeline[_InT, _NewOutGe]
Constrain a value to be greater than or equal to a certain value.
Source code in pydantic/experimental/pipeline.py
247 248 249 |
|
le ¶
le(le: _NewOutLe) -> _Pipeline[_InT, _NewOutLe]
Constrain a value to be less than or equal to a certain value.
Source code in pydantic/experimental/pipeline.py
251 252 253 |
|
len ¶
Constrain a value to have a certain length.
Source code in pydantic/experimental/pipeline.py
255 256 257 |
|
multiple_of ¶
multiple_of(
multiple_of: _NewOutDiv,
) -> _Pipeline[_InT, _NewOutDiv]
multiple_of(
multiple_of: _NewOutMod,
) -> _Pipeline[_InT, _NewOutMod]
Constrain a value to be a multiple of a certain number.
Source code in pydantic/experimental/pipeline.py
265 266 267 |
|
eq ¶
eq(value: _OutT) -> _Pipeline[_InT, _OutT]
Constrain a value to be equal to a certain value.
Source code in pydantic/experimental/pipeline.py
269 270 271 |
|
not_eq ¶
not_eq(value: _OutT) -> _Pipeline[_InT, _OutT]
Constrain a value to not be equal to a certain value.
Source code in pydantic/experimental/pipeline.py
273 274 275 |
|
in_ ¶
Constrain a value to be in a certain set.
Source code in pydantic/experimental/pipeline.py
277 278 279 |
|
not_in ¶
Constrain a value to not be in a certain set.
Source code in pydantic/experimental/pipeline.py
281 282 283 |
|
otherwise ¶
Combine two validation chains, returning the result of the first chain if it succeeds, and the second chain if it fails.
Source code in pydantic/experimental/pipeline.py
328 329 330 |
|
then ¶
Pipe the result of one validation chain into another.
Source code in pydantic/experimental/pipeline.py
334 335 336 |
|
Arguments schema API¶
Experimental module exposing a function to generate a core schema that validates callable arguments.
generate_arguments_schema ¶
generate_arguments_schema(
func: Callable[..., Any],
schema_type: Literal[
"arguments", "arguments-v3"
] = "arguments-v3",
parameters_callback: (
Callable[[int, str, Any], Literal["skip"] | None]
| None
) = None,
config: ConfigDict | None = None,
) -> CoreSchema
Generate the schema for the arguments of a function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
The function to generate the schema for. |
required |
schema_type
|
Literal['arguments', 'arguments-v3']
|
The type of schema to generate. |
'arguments-v3'
|
parameters_callback
|
Callable[[int, str, Any], Literal['skip'] | None] | None
|
A callable that will be invoked for each parameter. The callback
should take three required arguments: the index, the name and the type annotation
(or |
None
|
config
|
ConfigDict | None
|
The configuration to use. |
None
|
Returns:
Type | Description |
---|---|
CoreSchema
|
The generated schema. |
Source code in pydantic/experimental/arguments_schema.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|