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 two Pydantic models side by side. |
|
Display Python code representation of a Pydantic model. |
|
Display a Pydantic model or instance with clear formatting. |
|
Format default value for display. |
|
Format field info for comparison display. |
|
Format type annotation for display. |
|
Format a value for display. |
|
Generate Python code representation of a Pydantic model. |
|
Pretty print a Pydantic model instance. |
|
Simple print fallback when rich is not available. |
|
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.
- haive.core.utils.pydantic_utils.ui.display_code(model_class, title=None)[source]¶
Display Python code representation of a Pydantic model.
- haive.core.utils.pydantic_utils.ui.display_model(model, title=None)[source]¶
Display a Pydantic model or instance with clear formatting.
- 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:
- 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:
- 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:
- 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:
- haive.core.utils.pydantic_utils.ui.model_to_code(model_class)[source]¶
Generate Python code representation of a Pydantic model.
- 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