Django + Webhooks Made Easy
Project description
Django + Webhooks Made Easy
The full documentation is at https://dj-webhooks.readthedocs.org.
Requirements
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)
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.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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dj-webhooks-0.2.0.tar.gz
.
File metadata
- Download URL: dj-webhooks-0.2.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3d660b7872354c0a7081ac04139f317cbaf4a4b6273df98dfa00382238023a8 |
|
MD5 | 8e7ce512e1825a3b42fe78e5a8f38c66 |
|
BLAKE2b-256 | 2703939294f917bc2100fd248a0fae28201f460590ea14ad59ea3fee7d927168 |
File details
Details for the file dj_webhooks-0.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: dj_webhooks-0.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f137d4a2f1461b2a2a856e021bd5783eccdf67f9cc53b550ac4e74b8451fcfdd |
|
MD5 | 7bbae87e46e8392575a3a6c434b7ab7d |
|
BLAKE2b-256 | 96c66839326d1faa38d90b3a67ec5cbc0b70279f00298e78ec7431460c0fefda |