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 vX.Y.Z -m "Release vX.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.1.tar.gz (15.8 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: domain_events-2.1.tar.gz
  • Upload date:
  • Size: 15.8 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.1.tar.gz
Algorithm Hash digest
SHA256 ca5e0eaa1d6011135da4b87240f98af268a82d619ba559b95c6205ed94a62e0e
MD5 558bafe1abd3c0c9730d0ff6b27c1afe
BLAKE2b-256 3dc50eab91187ffa1eb3a25ac553f0f96c54d1eee4868afd3233f0943aaadad8

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