Easy use and customizable implementation for Value Object and Object Mother patterns.
Getting Started • Value Object Pattern • Object Mother Pattern
|
Sindri replaces ad hoc primitives and fragile validators with a consistent Value Object and Aggregate
toolkit you can adopt quickly.
Spin up validated value objects, aggregates, and test data with a simple and a small, focused API.
Sindripy provides a basic-high-customizable implementation to help you enforce domain invariants and improve code quality with minimal effort. Why use sindripy? Building your domain with Sindri lets you:
|
This project was generated using Instant Python, a fast, easy and reliable project generator for Python projects.
This section provides a high-level overview of the sindripy documentation so you can find quickly what you need.
- Join a discussion 💬 on GitHub Discussions
- Raise an issue on GitHub
The latest version of sindripy can be installed from PyPI:
pip install sindripyHere is a simple example of how to use sindri to create a value object and generate test data using an object mother.
from sindripy.value_objects import Integer, String
age = Integer(30)
name = String("John Doe")
print(f"Name: {name.value}, Age: {age.value}")from sindripy.mothers import IntegerPrimitivesMother, StringPrimitivesMother
random_age = IntegerPrimitivesMother.any()
random_name = StringPrimitivesMother.any()This release includes a breaking change to the validator API used by value objects:
- Validators no longer accept the incoming value as a parameter. Instead, the value is assigned to
self._valuebefore validators run, and validator methods have the signaturedef _validate_xxx(self) -> None:. - This simplifies validator signatures and reduces repetition across validation methods.
Why this is a breaking change
- Existing validator methods that still declare a
valueparameter will receive the wrong signature and raise aTypeErrorwhen the framework calls them. Custom code that expects the old parameter (for example, custom exception constructors or external utilities) may also need small updates.
How to migrate
- Follow the step-by-step migration guide which shows the exact edits and examples: Validator Signature Migration Guide.
- In short: find all methods decorated with
@validate, remove thevalueparameter, replace uses ofvaluewithself._value, and update any error messages or custom exceptions that referenced the old parameter.
A quick checklist:
- Update
@validatemethods todef _... (self) -> None - Replace
valuereferences withself._value - Update error messages and custom exception usages
- Run your tests
To learn more about advanced usage of value objects, including validation, custom value objects, complex objects like aggregates, visit the Value Object Pattern and Object Mother Pattern sections of the documentation.