Skip to main content

A lightweight library with an implementation of Pub-Sub.

Project description

# Domain Events

[![Build Status](](
[![License GPLv3](](
![Python versions](

A lightweight library with an implementation of Pub-Sub.

## Install

$ pipenv install domain-events


$ pip install domain-events

## Usage

In order to have the pub-sub working in your application, you'll need to write your own subscribers and to subscribe them to the publisher.

`domain-events` provides an interface for subscribers that needs to be implemented by your own subscribers in the first place. Two methods are mandatory: `handle(self, event)` and `_events_subscribed_to(self)`. Following is an example of how to do it.


from domain_events import Subscriber

class ExampleSubscriber(Subscriber):

def handle(self, event):
# Logic to handle the occurring event

def _events_subscribed_to(self):
""" Return the tuple of events it is subscribed to. """

return (AnEvent, AnotherEvent)

Once the subscriber is implemented, you'll need to subscribe it to the event publisher.


from domain_events import Publisher


Now, in order to publish an event, just call the `publish` method on the `Publisher` with one of your domain events.

from domain_events import Event, Publisher

class AnEvent(Event):


The event will be passed on to the proper subscribers.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for domain-events, version 2.0
Filename, size File type Python version Upload date Hashes
Filename, size domain_events-2.0-py3-none-any.whl (15.9 kB) File type Wheel Python version 3.5 Upload date Hashes View
Filename, size domain-events-2.0.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page