Skip to main content
https://pypip.in/d/dj-webhooks/badge.png https://badge.fury.io/py/dj-webhooks.png Wheel Status https://travis-ci.org/pydanny/dj-webhooks.png?branch=master

Django + Webhooks Made Easy

The full documentation is at https://dj-webhooks.readthedocs.org.

Requirements

  • Python 2.7.x or 3.3.2 or higher

  • django>=1.5.5

  • django-jsonfield>=0.9.12

  • django-model-utils>=2.0.2

  • django-rq>=0.6.1

  • webhooks>=0.3.1

Quickstart

Install dj-webhooks:

pip install dj-webhooks

Configure some webhook events:

# settings.py
WEBHOOK_EVENTS = (
    "purchase.paid",
    "purchase.refunded",
    "purchase.fulfilled"
)

Add some webhook targets:

from django.contrib.auth import get_user_model
User = get_user_model()
user = User.objects.get(username="pydanny")

from webhooks.models import Webhook
WebhookTarget.objects.create(
    owner=user,
    event="purchase.paid",
    target_url="https://mystorefront.com/webhooks/",
    header_content_type=Webhook.CONTENT_TYPE_JSON,
)

Then use it in a project:

from django.contrib.auth import get_user_model
User = get_user_model()
user = User.objects.get(username="pydanny")

from djwebhooks.decorators import hook

from myproject.models import Purchase

# Event argument helps identify the webhook target
@hook(event="purchase.paid")
def send_purchase_confirmation(purchase, owner): # Webhook_owner also helps identify the webhook target
    return {
        "order_num": purchase.order_num,
        "date": purchase.confirm_date,
        "line_items": [x.sku for x in purchase.lineitem_set.filter(inventory__gt=0)]
    }

for purchase in Purchase.objects.filter(status="paid"):
    send_purchase_confirmation(purchase=purchase, owner=user)

In a queue using django-rq

Assuming you are running Redis and also have django-rq configured:

from django.contrib.auth import get_user_model
User = get_user_model()
user = User.objects.get(username="pydanny")

# import redis hook
from djwebhooks.decorators import redis_hook

from myproject.models import Purchase

# Event argument helps identify the webhook target
@redis_hook(event="purchase.paid")
def send_purchase_confirmation(purchase, owner): # Webhook_owner also helps identify the webhook target
    return {
        "order_num": purchase.order_num,
        "date": purchase.confirm_date,
        "line_items": [x.sku for x in purchase.lineitem_set.filter(inventory__gt=0)]
    }

for purchase in Purchase.objects.filter(status="paid"):
    job = send_purchase_confirmation(purchase=purchase, owner=user)

Features

  • Synchronous webhooks

  • Delivery tracking via Django ORM.

  • Options for asynchronous webhooks.

Planned Features

  • Delivery tracking via Redis and other write-fast datastores.

History

0.2.1 (2014-05-17)

  • Removed conf.py file as it just added abstraction

  • Created exlicitly importable hooks. Makes settings management easier.

  • Removed utils.py since we no longer do fancy dynamic imports (see previous bullet).

  • Coverage now at 100%

0.2.0 (2014-05-15)

  • Refactored the senders to be very extendable.

  • Added an ORM based sender.

  • Added a redis based sender that uses django-rq.

  • Added a redis-hook decorator.

  • Added admin views.

  • Ramped up test coverage to 89%.

  • setup.py now includes all dependencies.

0.1.0 (2014-05-12)

  • First release on PyPI.

Download files

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

Source Distribution

dj-webhooks-0.2.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

dj_webhooks-0.2.1-py2.py3-none-any.whl (12.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file dj-webhooks-0.2.1.tar.gz.

File metadata

  • Download URL: dj-webhooks-0.2.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dj-webhooks-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1e345baa6c03563c41d391206fd5461a346706610e6fa9fbb3fb7d981b8e31e8
MD5 87f8ac81725090dbdf61cae40965328b
BLAKE2b-256 fa8b355c730b6f4e0ebd48ed51a52e5ed2dc8e80be5b09465d369062e5eeab4f

See more details on using hashes here.

File details

Details for the file dj_webhooks-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for dj_webhooks-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 95d3c987e3a1655c402d55e1f3627a3d63eaa67e949b71699e253c9be364a27b
MD5 fefb968aa6195add3247359a6562a3eb
BLAKE2b-256 3b00168e6e6eec2cd5be07af9bcc8cb07ad55e47a787b6a59ef89c212e372ee6

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

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