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 setup.py sdist
    

    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.2.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.2.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: domain_events-2.2.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.2.0.tar.gz
Algorithm Hash digest
SHA256 7f2506e851ad4a9d4d1c1c9dceee20c26569c51ceccca285280053be2e5b9d22
MD5 ede3f87692e1ddfad64f6b15a8e3c1cb
BLAKE2b-256 e63b6aff69bed71cf17b117f75e22e80abe007599cd585456b1ba73516e33f4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: domain_events-2.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84a319327278cbf51155420e034e1597cf6bc347d28a0029339348fe94702c10
MD5 b5cae2e5095b0c4169f2a620873954fe
BLAKE2b-256 a4e3630246e3df8180939a456575ea1854a969483ed9876184b17e13efd0aaca

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