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
31 32 33 34 | |
connect
¶
connect(receiver, *, sender=None)
Connect one receiver to the signal.
| PARAMETER | DESCRIPTION |
|---|---|
receiver
|
Callable accepting
TYPE:
|
sender
|
Optional sender filter. When provided, the receiver is
called only when
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
SignalError
|
If the receiver is not callable or does not accept keyword arguments. |
Source code in saffier/core/signals/signal.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
connect_via
¶
connect_via(sender)
Return a decorator that connects a receiver for one sender.
The method mirrors Blinker's connect_via ergonomics for migration
signals while still using Saffier's own dispatcher. It is intentionally
sender-filtered, which lets one global signal handle revision,
upgrade, and downgrade receivers independently.
| PARAMETER | DESCRIPTION |
|---|---|
sender
|
Sender value that must match future
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Callable[[Callable], Callable]
|
Callable[[Callable], Callable]: Decorator registering the receiver. |
Source code in saffier/core/signals/signal.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
disconnect
¶
disconnect(receiver)
Disconnect one receiver from the signal.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
TYPE:
|
Source code in saffier/core/signals/signal.py
82 83 84 85 86 87 88 89 90 91 | |
send
async
¶
send(sender, **kwargs)
Dispatch the signal to all connected receivers concurrently.
| PARAMETER | DESCRIPTION |
|---|---|
sender
|
Model class, migration command name, or other sender value dispatching the signal.
TYPE:
|
**kwargs
|
Signal payload forwarded to every receiver.
TYPE:
|
Source code in saffier/core/signals/signal.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |