skip to navigation
skip to content

django-eventhandler 0.4.2

RabbitMQ event handler as a Django module


This is an event handler that handles messages from an AMQP server, installable as a Django application. Events are JSON-encoded dicts that have a key called ‘type’. The eventhandler calls functions that have bound themselves to an event using a decorator.

Installation and configuration

Install the application in your Django project. Add ‘eventhandler’ to your INSTALLED_APPS setting. Then, add the following two settings to your project settings file.

LISTENER_URL = 'amqps://<user>:<pass>@<hostname>/<vhost>'
LISTENER_QUEUE = 'my-application'

Optionally, you can also specify these three settings, to have an exchange declared.


Running the event handler

Manually: python event_listener. To daemonize it, you can use something like supervisor to manage the process.


Events that are received from AMQP should be JSON-encoded dicts. Each message should have a key named type, with str value. This value can be used in a decorator, to have the event handler execute a function when receiving an event.


from eventhandler import handles_event

def do_something_clever(event):

Now each event with a ‘type’: ‘my_event’ combo will be passed into this function. Of course it’s possible to have more than one handler for an event, or have one handler handle multiple events.

from eventhandler import handles_event

def do_something_clever(event):

def do_something_else(event):
NB Make sure that your handlers are in a place that’s loaded/scanned on startup of Django,
otherwise the decorators won’t register the handlers. For instance, for a Django-application, my_app/ is scanned on startup (provided my_app is in INSTALLED_APPS). So if your handlers are in my_app/, you could load them from there:
# my_app/

# Load handlers for events, so django-eventhandlers picks 'em up
import  # NOQA (keep pyflakes happy)

Running tests

Just run python test to run tests against your current setup. Run tox to run tests for various versions of Django. Currently, Django 1.6 through 1.9 on Python 2.7 are tested.


This software is brought to you by Byte, a webhosting provider based in Amsterdam, The Netherlands. We specialize in fast and secure Magento hosting and scalable cluster hosting.

Check out our Github page for more open source software or our site to learn about our products and technologies. Look interesting? Reach out about joining the team. Or just drop by for a cup of excellent coffee if you’re in town!

File Type Py Version Uploaded on Size
django-eventhandler-0.4.2.tar.gz (md5) Source 2017-03-31 4KB
django_eventhandler-0.4.2-py2-none-any.whl (md5) Python Wheel py2 2017-03-31 5KB