uf.trans#
Input transformation integration for uf.
Provides a registry for custom type transformations that bridges between RJSF form data and qh’s input transformation system.
Functions
Get the global transformation registry. |
|
Register commonly-used Python types. |
|
|
Register a type in the global registry. |
Classes
Registry for custom type transformations. |
- class uf.trans.InputTransformRegistry[source]#
Bases:
objectRegistry for custom type transformations.
Integrates with qh’s type registry and extends it for UI needs, allowing custom types to be properly handled in both the form interface and the HTTP service layer.
Example
>>> from datetime import datetime >>> registry = InputTransformRegistry() >>> >>> # Register a custom type >>> registry.register_type( ... datetime, ... to_json=lambda dt: dt.isoformat(), ... from_json=lambda s: datetime.fromisoformat(s), ... ui_widget='datetime' ... )
- get_ui_config(py_type)[source]#
Get UI configuration for a type.
- Parameters:
py_type (
Type) – Python type to look up- Return type:
- Returns:
RjsfFieldConfig or None if not registered
- mk_input_trans_for_funcs(funcs)[source]#
Create input transformation compatible with qh.
This creates a transformation function that can be passed to qh.mk_app as the input_trans parameter.
- Parameters:
funcs (
list[Callable]) – List of functions to create transformation for- Return type:
- Returns:
Transformation function for qh
Example
>>> from uf import mk_rjsf_app >>> registry = InputTransformRegistry() >>> # ... register types ... >>> input_trans = registry.mk_input_trans_for_funcs([my_func]) >>> app = mk_rjsf_app([my_func], input_trans=input_trans)
- mk_output_trans()[source]#
Create output transformation for qh.
- Return type:
- Returns:
Transformation function for qh output
Example
>>> output_trans = registry.mk_output_trans() >>> app = mk_rjsf_app([my_func], output_trans=output_trans)
- register_type(py_type, *, to_json=None, from_json=None, ui_widget=None, ui_config=None, json_schema_type=None, json_schema_format=None)[source]#
Register a type with both qh and UI configuration.
- Parameters:
py_type (
Type) – Python type to registerto_json (
Optional[Callable[[Any],Any]]) – Function to convert Python type to JSON-serializablefrom_json (
Optional[Callable[[Any],Any]]) – Function to convert JSON to Python typeui_widget (
Optional[str]) – RJSF widget to use for this typeui_config (
Optional[RjsfFieldConfig]) – Full RjsfFieldConfig for this typejson_schema_type (
Optional[str]) – JSON Schema type (e.g., ‘string’, ‘number’)json_schema_format (
Optional[str]) – JSON Schema format (e.g., ‘date-time’, ‘email’)
- Return type:
Example
>>> from pathlib import Path >>> registry.register_type( ... Path, ... to_json=str, ... from_json=Path, ... ui_widget='text', ... json_schema_type='string' ... )
- uf.trans.get_global_registry()[source]#
Get the global transformation registry.
- Return type:
- Returns:
The global InputTransformRegistry instance