Converters¶
The liblaf.conf.converters module exposes lower-level helpers for cases where
you want to pass a converter directly to Field(...) or Var(...).
Use these helpers when the higher-level field_* builders are not quite the
right fit for your config model.
liblaf.conf.converters.identity
¶
Return a value unchanged.
This is the default converter for fields and variables that already receive values in their final Python form.
liblaf.conf.converters.pydantic_model_validate
¶
pydantic_model_validate[T: BaseModel](
model: type[T],
) -> Converter[T]
Return a converter that validates Python objects against a model.
Parameters:
-
model(type[T]) –The Pydantic model class used to validate incoming objects.
Returns:
-
Converter[T]–A callable suitable for
Field(converter=...)orVarthat -
Converter[T]–delegates to
model.model_validate.
Source code in src/liblaf/conf/converters/_pydantic.py
liblaf.conf.converters.pydantic_model_validate_json
¶
pydantic_model_validate_json[T: BaseModel](
model: type[T],
) -> Converter[T]
Return a converter that validates JSON strings against a model.
Parameters:
-
model(type[T]) –The Pydantic model class used to parse JSON payloads.
Returns:
-
Converter[T]–A callable that delegates to
model.model_validate_json.
Source code in src/liblaf/conf/converters/_pydantic.py
liblaf.conf.converters.pydantic_model_validate_strings
¶
pydantic_model_validate_strings[T: BaseModel](
model: type[T],
) -> Converter[T]
Return a converter that validates string inputs against a model.
Parameters:
-
model(type[T]) –The Pydantic model class used to coerce string-based inputs.
Returns:
-
Converter[T]–A callable that delegates to
model.model_validate_strings.
Source code in src/liblaf/conf/converters/_pydantic.py
liblaf.conf.converters.pydantic_type_adapter_validate_json
¶
pydantic_type_adapter_validate_json[T](
type_: type[T],
) -> Converter[T]
Return a converter that validates JSON strings for an arbitrary type.
Parameters:
-
type_(type[T]) –The target Python type validated by
pydantic.TypeAdapter.
Returns:
-
Converter[T]–A callable that parses JSON strings into
type_values.
Source code in src/liblaf/conf/converters/_pydantic.py
liblaf.conf.converters.pydantic_type_adapter_validate_python
¶
pydantic_type_adapter_validate_python[T](
type_: type[T],
) -> Converter[T]
Return a converter that validates Python objects for an arbitrary type.
Parameters:
-
type_(type[T]) –The target Python type validated by
pydantic.TypeAdapter.
Returns:
-
Converter[T]–A callable that validates already-parsed Python objects.
Source code in src/liblaf/conf/converters/_pydantic.py
liblaf.conf.converters.pydantic_type_adapter_validate_strings
¶
pydantic_type_adapter_validate_strings[T](
type_: type[T],
) -> Converter[T]
Return a converter that validates string inputs for an arbitrary type.
Parameters:
-
type_(type[T]) –The target Python type validated by
pydantic.TypeAdapter.
Returns:
-
Converter[T]–A callable that coerces string inputs into
type_values.