Experimental
Experimental pipeline API functionality. Be careful with this API, it's subject to change.
_Pipeline
dataclass
¶
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
134 135 136 137 138 139 140 141 142 143 | |
validate_as ¶
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
153 154 155 156 157 158 159 160 161 162 163 | |
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
165 166 167 168 169 170 171 | |
constrain ¶
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
236 237 238 239 240 241 242 243 244 | |
predicate ¶
Constrain a value to meet a certain predicate.
Source code in pydantic/experimental/pipeline.py
246 247 248 | |
gt ¶
gt(gt: _NewOutGt) -> _Pipeline[_InT, _NewOutGt]
Constrain a value to be greater than a certain value.
Source code in pydantic/experimental/pipeline.py
250 251 252 | |
lt ¶
lt(lt: _NewOutLt) -> _Pipeline[_InT, _NewOutLt]
Constrain a value to be less than a certain value.
Source code in pydantic/experimental/pipeline.py
254 255 256 | |
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
258 259 260 | |
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
262 263 264 | |
len ¶
Constrain a value to have a certain length.
Source code in pydantic/experimental/pipeline.py
266 267 268 | |
multiple_of ¶
multiple_of(
multiple_of: _NewOutDiv,
) -> _Pipeline[_InT, _NewOutDiv]
Constrain a value to be a multiple of a certain number.
Source code in pydantic/experimental/pipeline.py
270 271 272 | |
eq ¶
eq(value: _OutT) -> _Pipeline[_InT, _OutT]
Constrain a value to be equal to a certain value.
Source code in pydantic/experimental/pipeline.py
274 275 276 | |
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
278 279 280 | |
in_ ¶
Constrain a value to be in a certain set.
Source code in pydantic/experimental/pipeline.py
282 283 284 | |
not_in ¶
Constrain a value to not be in a certain set.
Source code in pydantic/experimental/pipeline.py
286 287 288 | |
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
333 334 335 | |
then ¶
Pipe the result of one validation chain into another.
Source code in pydantic/experimental/pipeline.py
339 340 341 | |