Django Whisperer
Whisperer informs subscribed users via an URL when a specific event occurs.
Installation
Installation using pip:
pip install dj-whisperer
whisperer package has to be added to INSTALLED_APPS and migrate command has to be run.
INSTALLED_APPS = (
# other apps here...
'whisperer',
)
Sample Scenario
Let's give an example using Package model. When an event occurs related to a package, subscribed users are gonna be informed. To do so, firstly which events to subscribe must be determined. In order to learn when a package created:
from django.db.models.signals import post_save
from whisperer.events import WhispererEvent, registry
from whisperer.tasks import deliver_event
class PackageCreateEvent(WhispererEvent):
serializer_class = PackageSerializer
event_type = 'package-created'
registry.register(PackageCreateEvent)
def signal_receiver(instance, created=False, **kwargs):
if created:
deliver_event(instance, 'package-created')
post_save.connect(signal_receiver, Package)
When database transaction succeeds, in short when transaction.on_commit(), deliver_event must be triggered.
Subscribed users now can be informed that a package created if they have created a Webhook.
import requests
requests.post(
url='https://your-app.com/whisperer/hooks/',
headers={
'Authorization': 'Token <secret-login-token>',
},
json={
'event_type': 'package-created',
'secret_key': 'secret',
'target_url': 'https://example.com/',
}
)
When a package created, uuid, type & data passed through PackageSerializer will be posted to https://example.com/.
import requests
requests.post(
url='https://example.com/',
headers={
'Content-Type': 'application/json',
'X-Whisperer-Event': 'package-created',
},
json={
'event': {
'type': 'package-created',
'uuid': 'da81e85139824c6187dd1e58a7d3f971',
},
'data': {
'id': 61,
'transfer_id': 49,
'order_number': '248398923123',
'.....': '......',
}
}
)
In order to cancel the subscription:
import requests
requests.delete(
url='https://your-app.com/whisperer/hooks/<webhook-id>/',
headers={
'Authorization': 'Token <secret-login-token>',
}
)
To re-trigger events that lost on the queue you must call whisperer.tasks.trigger_event_queue_events with scheduler
To automate the removal of outdated event records, schedule the task whisperer.tasks.delete_outdated_webhook_events using a scheduler. By default, it targets records older than 12 weeks.
Metadata
Release files for dj-whisperer 0.5.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dj_whisperer-0.5.3-py3-none-any.whl | Python 3 | none | any | Details |
Release files / dj_whisperer-0.5.3-py3-none-any.whl
| Download URL | dj_whisperer-0.5.3-py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb88153d5643430dab5a3f90bbf75d352fadfe8c92ef7a6e7b8fcd31dc7e0662
|
|
BLAKE2b-256 checksum How to use checksums |
ae9901c8b0967cfbcb10845353efaa7357f4fa6b72e73a6936f0e15c2bb18307
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.17
|
Security for dj-whisperer 0.5.3
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.