haive.core.utils.haive_collectionsΒΆ

from typing import Any Collection utilities for Haive Core.

This module includes advanced collection types and utilities that extend standard Python collections with additional functionality.

ClassesΒΆ

NamedDict

A dictionary that automatically builds keys from object names.

Module ContentsΒΆ

class haive.core.utils.haive_collections.NamedDict(/, **data)[source]ΒΆ

Bases: pydantic.BaseModel, Generic[T], haive.core.utils.getter_mixin.GetterMixin[T]

A dictionary that automatically builds keys from object names.

This class combines dictionary-like access with attributes extraction and rich lookup capabilities from GetterMixin.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

add(item, key=None)[source]ΒΆ

Add an item with automatic or explicit key.

Parameters:
  • item (T) – Item to add

  • key (str | None) – Optional explicit key

Returns:

Key used to store the item

Return type:

str

clear()[source]ΒΆ

Clear all items.

Return type:

None

classmethod convert_input(data)[source]ΒΆ

Process input data into the expected format.

Parameters:

data (Any)

Return type:

Any

get(key, default=None)[source]ΒΆ

Get an item with a default value.

Parameters:
  • key (str)

  • default (Any)

Return type:

Any

items()[source]ΒΆ

Get all key-value pairs.

Return type:

Any

keys()[source]ΒΆ

Get all keys.

Return type:

list[str]

pop(key, default=None)[source]ΒΆ

Remove and return an item with default value.

Parameters:
  • key (str)

  • default (Any)

Return type:

Any

to_dict()[source]ΒΆ

Convert to plain dictionary.

Return type:

dict[str, T]

update(items)[source]ΒΆ

Update with dictionary or iterable.

Parameters:

items (dict[str, T] | collections.abc.Iterable[T]) – Dictionary or iterable of items to add

Return type:

None

values_list()[source]ΒΆ

Get all values as a list.

Return type:

list[T]

model_configΒΆ

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].