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_global_registry()

Get the global transformation registry.

register_common_types()

Register commonly-used Python types.

register_type(*args, **kwargs)

Register a type in the global registry.

Classes

InputTransformRegistry()

Registry for custom type transformations.

class uf.trans.InputTransformRegistry[source]#

Bases: object

Registry 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'
... )
from_json(value, py_type)[source]#

Transform a JSON value to Python type.

Parameters:
  • value (Any) – JSON value to transform

  • py_type (Type) – Target Python type

Return type:

Any

Returns:

Transformed value

get_all_registered_types()[source]#

Get list of all registered types.

Return type:

list[Type]

Returns:

List of registered Python types

get_handler(py_type)[source]#

Get handler for a type.

Parameters:

py_type (Type) – Python type to look up

Return type:

Optional[dict]

Returns:

Handler dict or None if not registered

get_ui_config(py_type)[source]#

Get UI configuration for a type.

Parameters:

py_type (Type) – Python type to look up

Return type:

Optional[RjsfFieldConfig]

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:

Callable

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:

Callable

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 register

  • to_json (Optional[Callable[[Any], Any]]) – Function to convert Python type to JSON-serializable

  • from_json (Optional[Callable[[Any], Any]]) – Function to convert JSON to Python type

  • ui_widget (Optional[str]) – RJSF widget to use for this type

  • ui_config (Optional[RjsfFieldConfig]) – Full RjsfFieldConfig for this type

  • json_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:

None

Example

>>> from pathlib import Path
>>> registry.register_type(
...     Path,
...     to_json=str,
...     from_json=Path,
...     ui_widget='text',
...     json_schema_type='string'
... )
to_json(value, py_type=None)[source]#

Transform a Python value to JSON-serializable form.

Parameters:
  • value (Any) – Value to transform

  • py_type (Optional[Type]) – Optional type hint (uses type(value) if not provided)

Return type:

Any

Returns:

JSON-serializable value

uf.trans.get_global_registry()[source]#

Get the global transformation registry.

Return type:

InputTransformRegistry

Returns:

The global InputTransformRegistry instance

uf.trans.register_common_types()[source]#

Register commonly-used Python types.

This includes:

  • datetime.datetime

  • datetime.date

  • datetime.time

  • pathlib.Path

  • uuid.UUID

  • decimal.Decimal

uf.trans.register_type(*args, **kwargs)[source]#

Register a type in the global registry.

This is a convenience function that uses the global registry. See InputTransformRegistry.register_type for full documentation.