Skip to main content

Django + Webhooks Made Easy

Project description

https://badge.fury.io/py/dj-webhooks.png Wheel Status https://travis-ci.org/pydanny/dj-webhooks.png?branch=master

Django + Webhooks Made Easy

Warning: Still in pre-alpha status. Not used in production on ANYTHING.

Documentation

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

Requirements

  • django>=1.5.5

  • webhooks

  • django-jsonfield

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.confirmed",
    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 webhook

from myproject.models import Purchase

# Event argument helps identify the webhook target
@hook(event="purchase.paid")
def send_purchase_confirmation(purchase, webhook_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, user)

Requirements

  • Python 2.7.x or 3.3.2 or higher

  • Django 1.5 or higher

Features

  • Synchronous webhooks

  • Delivery tracking via Django ORM.

Planned Features

  • Options for asynchronous webhooks

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

History

0.1.0 (2014-05-12)

  • First release on PyPI.

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-webhooks-0.1.0.tar.gz (9.9 kB view hashes)

Uploaded Source

Built Distribution

dj_webhooks-0.1.0-py2.py3-none-any.whl (10.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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