liblaf.conf.converters
¶
Expose converter helpers used by liblaf.conf fields and variables.
Most applications will reach for the higher-level field_* helpers first.
This module is the lower-level escape hatch for cases where you want to pass a
converter directly to Field or
Var.
The exported helpers either leave values unchanged or delegate validation to Pydantic models and type adapters.
Functions:
-
identity–Return a value unchanged.
-
pydantic_model_validate–Return a converter that validates Python objects against a model.
-
pydantic_model_validate_json–Return a converter that validates JSON strings against a model.
-
pydantic_model_validate_strings–Return a converter that validates string inputs against a model.
-
pydantic_type_adapter_validate_json–Return a converter that validates JSON strings for an arbitrary type.
-
pydantic_type_adapter_validate_python–Return a converter that validates Python objects for an arbitrary type.
-
pydantic_type_adapter_validate_strings–Return a converter that validates string inputs for an arbitrary type.
identity
¶
Return a value unchanged.
Parameters:
-
x(T) –Value to return.
Returns:
-
T–The same value object. This is the default converter for fields and
-
T–variables that already receive values in their final Python form.
Source code in src/liblaf/conf/converters/_misc.py
pydantic_model_validate
¶
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=...)orVar(...)that -
Converter[T]–delegates to
model.model_validate.
Source code in src/liblaf/conf/converters/_pydantic.py
pydantic_model_validate_json
¶
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
pydantic_model_validate_strings
¶
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
pydantic_type_adapter_validate_json
¶
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
pydantic_type_adapter_validate_python
¶
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
pydantic_type_adapter_validate_strings
¶
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.