Skip to main content

A lightweight library with an implementation of Pub-Sub.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Domain Events

Build Status License GPLv3 Python versions

A lightweight library with an implementation of Pub-Sub.

Install

pipenv install domain-events

or

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

Publisher().subscribe(ExampleSubscriber())

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):
    pass

Publisher().publish(AnEvent())

The event will be passed on to the proper subscribers.

Publishing to PyPI

Follow these steps to publish a new version of the package to PyPI:

  1. Update the version number in setup.py

  2. Install build tools (if not already installed):

    pip install build twine
    
  3. Build the distribution packages:

    python -m build
    

    This creates both source distribution (.tar.gz) and wheel (.whl) in the dist/ directory.

  4. Verify the build:

    twine check dist/*
    
  5. Upload to PyPI using twine:

    twine upload dist/*
    

    Note: Use an API token instead of username/password. Configure it in ~/.pypirc:

    [pypi]
    username = __token__
    password = pypi-YOUR-API-TOKEN-HERE
    
  6. Clean up the build artifacts (optional):

    rm -rf build/ dist/ *.egg-info/
    

Best Practices

  • Use version tags: After publishing, tag the release in git:

    git tag -a X.Y.Z -m "Release X.Y.Z"
    git push origin --tags
    

Prerequisites

  • You need a PyPI account with the appropriate permissions to upload this package

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

domain_events-2.3.0.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

domain_events-2.3.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file domain_events-2.3.0.tar.gz.

File metadata

  • Download URL: domain_events-2.3.0.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for domain_events-2.3.0.tar.gz
Algorithm Hash digest
SHA256 c115fd3542c5e912c2a92c0f149cd8d1a401fa0c49ebf3c99d8f222b0f2cd1b1
MD5 9577e43c5a90b6e47621fd823e3c2a69
BLAKE2b-256 50cdf8de6ad0595de1b8a4e3dfbdc1df63ef1303db15c949f8505bba99739103

See more details on using hashes here.

File details

Details for the file domain_events-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: domain_events-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for domain_events-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3617132c995a2aff22448587542b80512addcede7799f5b5288b2e2163c1fad
MD5 8af0b15ddaebb3fda19752de561ba4b1
BLAKE2b-256 bcc61d3458be80cbe793b1e7c3274b556d820e49e13e0bc0ed4868c92c422fa1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page