_Note: This project is in the process of being reactivated and modernized. It's not ready to work anywhere._
Python + Webhooks Made Easy
- Free software: BSD license
- Documentation: http://webhooks.rtfd.org.
WARNING This project is in a beta state. It's still undergoing some changes and documentation is in-progress.
Currently works in:
- Python 2.7
- Python 3.3
- Easy to integrate into any package or project
- Comes with several built-in senders for synchronous webhooks.
- Comes with a RedisQ-powered asynchronous webhook.
- Extendable functionality through the use of custom senders and hash functions.
- Comes with many built-in senders for synchronous and asynchronous webhooks.
- Special functions for combining multiple sends of identical payloads going to one target into one.
- Follows http://resthooks.org patterns
- Great documentation
- Compatibility with PyPy
Follow these easy steps:
- Import the
webhook
decorator. - Define a function that returns a JSON-serializable dictionary or iterable.
- Add the
webhook
decorator and pass in asender_callable
. - Define timeout, any custom headers such as authentication, signing_secret, and encoding (application/json|application/x-www-form-urlencoded)
- Call the function!
Synchronous example (async examples to come soon):
>>> from webhooks import webhook
>>> from webhooks.senders import targeted
>>> @webhook(sender_callable=targeted.sender)
>>> def basic(wife, husband, url, encoding, timeout, custom_headers, signing_secret):
>>> return {"husband": husband, "wife": wife}
>>> r = basic("Audrey Roy Greenfeld", "Daniel Roy Greenfeld", url="http://httpbin.org/post", encoding="application/json", \
>>> timeout=10, custom_headers = {"Basic" : "dXNlcjpzdXBlcnNlY3JldA=="}, signing_secret="secret1")
>>> import pprint
>>> pprint.pprint(r)
{'attempt': 1,
'error': None,
'hash': '9d930cc754004d5790869fdfb6064f62',
'husband': 'Daniel Roy Greenfeld',
'post_attributes': {'headers': {'Basic': 'dXNlcjpzdXBlcnNlY3JldA==',
'x-hub-signature': 'sha256=e67a669f944fe752f9d9da15c5bcb4d332fceb4940ab512090e124c52c44cfa5'},
'json': '{"hash": "9d930cc754004d5790869fdfb6064f62", "husband": "Daniel Roy Greenfeld", "wife": "Audrey Roy Greenfeld"}',
'timeout': 10},
'response': '{\n "args": {}, \n "data": "\\"{\\\\\\"hash\\\\\\": \\\\\\"9d930cc754004d5790869fdfb6064f62\\\\\\", \\\\\\"husband\\\\\\": \\\\\\"Daniel Roy Greenfeld\\\\\\", \\\\\\"wife\\\\\\": \\\\\\"Audrey Roy Greenfeld\\\\\\"}\\"", \n "files": {}, \n "form": {}, \n "headers": {\n "Accept": "*/*", \n "Accept-Encoding": "gzip, deflate", \n "Basic": "dXNlcjpzdXBlcnNlY3JldA==", \n "Connection": "close", \n "Content-Length": "125", \n "Content-Type": "application/json", \n "Host": "httpbin.org", \n "User-Agent": "python-requests/2.18.4", \n "X-Hub-Signature": "sha256=e67a669f944fe752f9d9da15c5bcb4d332fceb4940ab512090e124c52c44cfa5"\n }, \n "json": "{\\"hash\\": \\"9d930cc754004d5790869fdfb6064f62\\", \\"husband\\": \\"Daniel Roy Greenfeld\\", \\"wife\\": \\"Audrey Roy Greenfeld\\"}", \n "origin": "38.104.237.126", \n "url": "http://httpbin.org/post"\n}\n',
'status_code': 200,
'success': True,
'wife': 'Audrey Roy Greenfeld'}