Skip to main content

Stay informed of it

Project description

Django Whisperer

Build status Documentation status PyPI PyPI - Django version PyPI - Python version PyPI - License

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>',
    }
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj-whisperer-0.2.10b0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_whisperer-0.2.10b0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file dj-whisperer-0.2.10b0.tar.gz.

File metadata

  • Download URL: dj-whisperer-0.2.10b0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for dj-whisperer-0.2.10b0.tar.gz
Algorithm Hash digest
SHA256 ffb96d1755606143c0d55d1ab6cdf13bb5c3d3553a6e69dd00604602d681b968
MD5 3106c6993a322d617a7920b9ffd52890
BLAKE2b-256 a4505c0df636c20d7061fd7f3ab83e7f786c79c1c916ac57f71746a988ed6d04

See more details on using hashes here.

File details

Details for the file dj_whisperer-0.2.10b0-py3-none-any.whl.

File metadata

  • Download URL: dj_whisperer-0.2.10b0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12

File hashes

Hashes for dj_whisperer-0.2.10b0-py3-none-any.whl
Algorithm Hash digest
SHA256 a54a68d65a6410be2b7e008362579e85de7457d8902e75088b170c4c0495e0a7
MD5 eaaa63aa9d0638cda4154f7ceb376316
BLAKE2b-256 1d6642bf2c3e8032b78d801c6bf55bb52d54e1a3a88f9093d67f4200ec906938

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page