Signal¶
Signals are Saffier's event hooks around model lifecycle operations.
They are most commonly used for:
- side effects around save or delete operations
- keeping denormalized data in sync
- integrating logging, auditing, or background work with ORM events
Common built-in lifecycle signals¶
Model broadcasters expose these built-in hooks:
pre_savepost_savepre_updatepost_updatepre_deletepost_delete
Use the guide page for the narrative walkthrough: Signals
saffier.Signal
¶
Signal()
Minimal async signal dispatcher used by model lifecycle hooks.
Receivers are stored in insertion order and are invoked concurrently when the signal is sent.
Initialize an empty receiver registry for the signal.
Source code in saffier/core/signals/signal.py
30 31 32 | |
connect
¶
connect(receiver)
Connect one receiver to the signal.
| PARAMETER | DESCRIPTION |
|---|---|
receiver
|
Callable accepting
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SignalError
|
If the receiver is not callable or does not accept keyword arguments. |
Source code in saffier/core/signals/signal.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
disconnect
¶
disconnect(receiver)
Disconnect one receiver from the signal.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
Source code in saffier/core/signals/signal.py
54 55 56 57 58 59 60 61 62 | |
send
async
¶
send(sender, **kwargs)
Dispatch the signal to all connected receivers concurrently.
| PARAMETER | DESCRIPTION |
|---|---|
sender
|
Model class sending the signal.
TYPE:
|
**kwargs
|
Signal payload forwarded to every receiver.
TYPE:
|
Source code in saffier/core/signals/signal.py
64 65 66 67 68 69 70 71 72 | |