haive.core.utils.pydantic_utils.ui

Pydantic model utilities for serialization, visualization, and code generation.

This module provides standalone functions for visualizing, comparing, and generating code from Pydantic BaseModel classes and instances, without requiring inheritance from specialized base classes.

Functions

compare_models(model1, model2[, title1, title2])

Compare two Pydantic models side by side.

display_code(model_class[, title])

Display Python code representation of a Pydantic model.

display_model(model[, title])

Display a Pydantic model or instance with clear formatting.

format_default_value(field_info)

Format default value for display.

format_field_info(field_info)

Format field info for comparison display.

format_type_annotation(type_annotation)

Format type annotation for display.

format_value(value)

Format a value for display.

model_to_code(model_class)

Generate Python code representation of a Pydantic model.

pretty_print(model_instance[, title])

Pretty print a Pydantic model instance.

print_model_simple(model[, title])

Simple print fallback when rich is not available.

schema_to_code(schema)

Generate Python code for a schema (possibly ComposedSchema).

Module Contents

haive.core.utils.pydantic_utils.ui.compare_models(model1, model2, title1=None, title2=None)[source]

Compare two Pydantic models side by side.

Parameters:
  • model1 (type[pydantic.BaseModel]) – First model to compare

  • model2 (type[pydantic.BaseModel]) – Second model to compare

  • title1 (str | None) – Optional title for first model

  • title2 (str | None) – Optional title for second model

Return type:

None

haive.core.utils.pydantic_utils.ui.display_code(model_class, title=None)[source]

Display Python code representation of a Pydantic model.

Parameters:
  • model_class (type[pydantic.BaseModel]) – Model class to display

  • title (str | None) – Optional title for the display

Return type:

None

haive.core.utils.pydantic_utils.ui.display_model(model, title=None)[source]

Display a Pydantic model or instance with clear formatting.

Parameters:
  • model (type[pydantic.BaseModel] | pydantic.BaseModel) – Model class or instance to display

  • title (str | None) – Optional title for the display

Return type:

None

haive.core.utils.pydantic_utils.ui.format_default_value(field_info)[source]

Format default value for display.

Parameters:

field_info (Any) – The field info to format

Returns:

Formatted string representation of the default value

Return type:

str

haive.core.utils.pydantic_utils.ui.format_field_info(field_info)[source]

Format field info for comparison display.

Parameters:

field_info (Any) – The field info to format

Returns:

Formatted string representation of the field info

Return type:

str

haive.core.utils.pydantic_utils.ui.format_type_annotation(type_annotation)[source]

Format type annotation for display.

Parameters:

type_annotation (Any) – The type annotation to format

Returns:

Formatted string representation of the type annotation

Return type:

str

haive.core.utils.pydantic_utils.ui.format_value(value)[source]

Format a value for display.

Parameters:

value (Any) – The value to format

Returns:

Formatted string representation of the value

Return type:

str

haive.core.utils.pydantic_utils.ui.model_to_code(model_class)[source]

Generate Python code representation of a Pydantic model.

Parameters:

model_class (type[pydantic.BaseModel]) – Model class to convert to code

Returns:

String containing Python code representation

Return type:

str

haive.core.utils.pydantic_utils.ui.pretty_print(model_instance, title=None)[source]

Pretty print a Pydantic model instance.

Parameters:
  • model_instance (pydantic.BaseModel) – Model instance to print

  • title (str | None) – Optional title for the display

Return type:

None

haive.core.utils.pydantic_utils.ui.print_model_simple(model, title=None)[source]

Simple print fallback when rich is not available.

Parameters:
  • model (type[pydantic.BaseModel] | pydantic.BaseModel) – Model class or instance to display

  • title (str | None) – Optional title for the display

Return type:

None

haive.core.utils.pydantic_utils.ui.schema_to_code(schema)[source]

Generate Python code for a schema (possibly ComposedSchema).

Parameters:

schema (Any) – The schema to convert to code

Returns:

String containing Python code representation

Return type:

str