ENGLISH | PORTUGUÊS
Python implementation of Domain Notification Pattern inspired by Flunt (.NET)
Flunt is a way to implement a notification pattern in your application to centralize errors and changes in certain actions and entities.
Flunt was born out of two needs: implementing the Domain Notification Pattern to replace domain-level exceptions in the application and reducing the amount of IFs (complexity) by using a contract-based approach.
Thus, basically what Flunt does is add a list of Notifications to your class and various methods to interact with it.
- Python 3.11+ compatible with no runtime dependencies.
- Fluent, chainable validations built on the Domain Notification Pattern.
- Specialized contracts for numbers, datetime, URLs, and Brazilian documents (CPF/CNPJ).
- Centralized notifications via
Notifiable, reducing scatteredifchecks and domain exceptions. - Full documentation in
docs/and on the site (link below).
Beyond the base contract, the library now includes specialized contracts for common scenarios:
NumericValidationContractfor numeric values (ranges, limits, sign)DateTimeValidationContractfor datetime values (intervals, minimum/maximum)UrlValidationContractfor URLsBrazilianDocumentValidationContractfor Brazilian documents (CPF/CNPJ)
Check the docs in docs/validations/ for detailed examples.
- Python 3.11 or newer
- No runtime dependencies (optional dev tooling:
uv,ruff,mypy,pytest)
pip install fluntfrom flunt.notifications.notifiable import Notifiable
class Name(Notifiable):
def __init__(self, name):
super().__init__()
if len(name) < 3:
self.add_notification(
field='name', message='Name must have at least 3 characters'
)
self._name = name"""Module Value Objects."""
from flunt.notifications.notifiable import Notifiable
from flunt.validations.contract import Contract
class Name(Notifiable):
"""Class Value Object Name."""
def __init__(self, first_name, last_name):
"""Found 'Constructor'."""
super().__init__()
self.first_name = first_name
self.last_name = last_name
self.add_notifications(
Contract()
.requires(self.first_name, 'first name', 'First name is required')
.requires(self.last_name, 'last name', 'Last name is required')
.is_greater_than(
value=self.first_name,
comparer=3,
field="first_name",
message="Minimum of 3 characters",
)
.is_greater_than(
value=self.last_name,
comparer=3,
field="last_name",
message="Minimum of 3 characters",
)
.get_notifications()
)
nome = Name('Emerson', 'Delatorre')
if not nome.is_valid:
for notification in nome.get_notifications():
print(notification)Please refer to our DevGuide at the following link: CONTRIBUTING
- Site (MkDocs): https://fazedordecodigo.github.io/PyFlunt/
- Local files:
docs/
Please refer to our changelog at the following link: CHANGELOG
This project contains the MIT license. See the file LICENSE.