pleroma
πλήρωμα — Greek; Sum total.
pleroma provides base classes that add a composable merge operation to dataclasses and pydantic v2 models.
What it does
Given a collection of instances of the same type, merge folds them into a
single instance using a last non-None wins strategy by default. Both the
traversal order and the field-level resolution can be overridden per subclass.
import dataclasses
from pleroma import MergeableMixin
@dataclasses.dataclass
class Config(MergeableMixin):
host: str | None = None
port: int | None = None
debug: bool | None = None
defaults = Config(host="localhost", port=8080, debug=False)
overrides = Config(port=9090)
Config.merge([defaults, overrides])
# Config(host='localhost', port=9090, debug=False)
Features
MergeableMixin— drop-in mixin for any@dataclassMergeableModel— frozen pydantic v2 base class with the same interface- Predefined iteration strategies —
iter_all,iter_reversed,iter_first,iter_last - Customisable traversal via
_iter_instances - Customisable field resolution via
_merge_two - Fully typed (PEP 561,
py.typedmarker)
Navigation
- Installation — how to install and configure
- MergeableMixin — dataclass usage and customisation
- MergeableModel — pydantic v2 integration
- Iteration strategies — predefined traversal helpers
- API Reference — full API documentation