haive.core.schema.compatibility.utils¶
from typing import Any. Utility functions for the schema compatibility module.
Functions¶
|
Calculate similarity between two strings (0-1). |
|
Create an example value for a type hint. |
|
Create a diff between two schemas. |
|
Estimate memory usage of a schema instance in bytes. |
|
Extract value from nested dict using path. |
|
Extract a readable name from a type hint. |
|
Find similar field names with scores. |
|
Flatten nested dictionary. |
|
Format a type conversion path for display. |
|
Generate a hash for schema comparison. |
|
Get all subclasses of a class recursively. |
|
Simple memoization decorator. |
|
Merge multiple dictionaries. |
|
Suggest a valid field name from invalid one. |
|
Unflatten a dictionary. |
|
Validate that a field name is valid Python identifier. |
Module Contents¶
- haive.core.schema.compatibility.utils.calculate_similarity(str1, str2)[source]¶
Calculate similarity between two strings (0-1).
Uses sequence matcher for basic similarity.
- haive.core.schema.compatibility.utils.create_example_value(type_hint)[source]¶
Create an example value for a type hint.
- Parameters:
type_hint (type)
- Return type:
Any
- haive.core.schema.compatibility.utils.create_schema_diff(schema1, schema2)[source]¶
Create a diff between two schemas.
Returns dict with: - added_fields: Fields in schema2 but not schema1 - removed_fields: Fields in schema1 but not schema2 - modified_fields: Fields with different types/properties - unchanged_fields: Fields that are the same
- Parameters:
- Return type:
- haive.core.schema.compatibility.utils.estimate_memory_usage(schema)[source]¶
Estimate memory usage of a schema instance in bytes.
- Parameters:
- Return type:
- haive.core.schema.compatibility.utils.extract_path_value(data, path, separator='.', default=None)[source]¶
Extract value from nested dict using path.
Supports: - Dot notation: “user.profile.name” - Array indices: “items[0].name” - Wildcards: “items[*].name”
- haive.core.schema.compatibility.utils.extract_type_name(type_hint)[source]¶
Extract a readable name from a type hint.
- haive.core.schema.compatibility.utils.find_similar_fields(target_field, source_fields, threshold=0.6)[source]¶
Find similar field names with scores.
Returns list of (field_name, similarity_score) tuples.
- haive.core.schema.compatibility.utils.flatten_nested_dict(data, parent_key='', separator='.')[source]¶
Flatten nested dictionary.
Examples
{“user”: {“name”: “John”, “age”: 30}} becomes {“user.name”: “John”, “user.age”: 30}
- haive.core.schema.compatibility.utils.format_type_path(types)[source]¶
Format a type conversion path for display.
- haive.core.schema.compatibility.utils.generate_schema_hash(schema)[source]¶
Generate a hash for schema comparison.
- Parameters:
schema (type[pydantic.BaseModel] | haive.core.schema.compatibility.types.SchemaInfo)
- Return type:
- haive.core.schema.compatibility.utils.get_all_subclasses(cls)[source]¶
Get all subclasses of a class recursively.
- haive.core.schema.compatibility.utils.memoize(func)[source]¶
Simple memoization decorator.
- Parameters:
func (collections.abc.Callable[Ellipsis, T])
- Return type:
collections.abc.Callable[Ellipsis, T]
- haive.core.schema.compatibility.utils.merge_dicts(*dicts, deep=True, list_strategy='extend')[source]¶
Merge multiple dictionaries.
- haive.core.schema.compatibility.utils.suggest_field_name(invalid_name)[source]¶
Suggest a valid field name from invalid one.