signals
this project ports django's signal dispatcher so it can be used with any app
Installation
pip install signals-py
(note that while it's installed as signals-py, the package name is signals)
usage
for a full exploration check django's docs
but in essance:
craete a signal:
from signals.dispatch import Signal
my_costum_signal = Signal()
define receviers
to connect a function/method as a recevier:
from somewhere import my_costum_signal
def my_recevier(**kwargs):
print("signal was sent!!")
my_costum_signal.connect(my_recevier)
or use the decorator
from signals.dispatch import recevier
from somewhere import my_costum_signal
@recevier(my_costum_signal)
def my_recevier(**kwargs):
print("signal was sent!!")
receviers can be async function/methods as well
from somewhere import my_costum_signal
async def my_recevier(**kwargs):
print("signal was sent!!")
my_costum_signal.connect(my_recevier)
or
from signals.dispatch import recevier
from somewhere import my_costum_signal
@recevier(my_costum_signal)
async def my_recevier(**kwargs):
print("signal was sent!!")
send signals
to send a signal, simply call .send():
from somewhere import my_costum_signal
my_costum_signal.send(sender=object())
the sender argument is usually the class that's sending the signal (via self.__class__),
but it can be anything.
if one of the receviers raises an exception, it gets raise right there so other receviers won't be called.
or you can call .send_robust(), which ensures all receviers are called even if exceptions are raised
from somewhere import my_costum_signal
my_costum_signal.send_robust(sender=object())
both .send() and .send_robust() have an async version, called .asend() and .asend_robust()
from somewhere import my_costum_signal
async def do_some_work():
await my_costum_signal.asend(sender=object)
# or
await my_costum_signal.asend_robust(sender=object)
all the sending methods return a list of tuples,
the first item in the tuple is the recevier, the second is the value returned by the recevier
if send_robust or asend_robust is used, if a recevier raises an exception, the exception will be the second item in the tuple.
disconnect a recevier
to disconnect a recevier from a signal simply do:
from somewhere import my_costum_signal
from receviers_home import my_recevier
my_costum_signal.disconnect(my_recevier)
how async/sync receviers are treated
if you use .send() (or other sync ways to send), all sync receviers are called normally,
async receviers are wrappe in a single asgiref.sync.async_to_sync call.
if you use .asend() (or other async ways to send), async receviers are scheduled via asyncio.gather()
sync receviers are wrapped with a single asgiref.sync.sync_to_async then passed to the same asyncio.gather()
Metadata
Release files for signals-py 0.1.0.post1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| signals_py-0.1.0.post1.tar.gz | 57.0 kB | Without provenance | Details for signals_py-0.1.0.post1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| signals_py-0.1.0.post1-py3-none-any.whl | Python 3 | none | any | Details for signals_py-0.1.0.post1-py3-none-any.whl |
Total release size: 65.7 kB
Release files / signals_py-0.1.0.post1.tar.gz
| Download URL | signals_py-0.1.0.post1.tar.gz |
|---|---|
| Size | 57.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a4fcf1140dddd558e782f32dfee5e15b76d4e4ed341446e4176bf7b82877bc0
|
|
BLAKE2b-256 checksum How to use checksums |
209db0f2a69448ae6570fa1fb431efff54876b6fff354c1c4af9bbbd939b308d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.3
|
Release files / signals_py-0.1.0.post1-py3-none-any.whl
| Download URL | signals_py-0.1.0.post1-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0046466a77ba345f54b7b70fc4309f5787a0f8728ef9ed2287144246ba89a9c4
|
|
BLAKE2b-256 checksum How to use checksums |
93e21199567a4465c4193e01778ad68f046b27116b926d34e4d5492c18570623
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.3
|
Security for signals-py 0.1.0.post1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.