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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for dj-webhooks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 df2afb3e92767ca9d8be3c21563e18bbf126cff57dfe0005bc864ab45e08e458
MD5 11a40ea2518d6c2ef32e6862a4e59e33
BLAKE2b-256 a9be8a791c660b4ff9ab0a74ad87f01c43666eea462631ed5f644d2f33bb0741

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dj_webhooks-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2bf891e41e7553c3e199fed6a89c09ee48afa3853b7d3f654c898aeb7476f24f
MD5 d3bdccc0ad144220e8bef779cff00d06
BLAKE2b-256 bfc05936eb8f79c36bc2d2394ddd916b4090bb73dbd9ea2411ec0870ce283fd4

See more details on using hashes here.

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