This project has been archived by its maintainers, and is no longer receiving any updates.
Domain Events
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:
-
Update the version number in
setup.py -
Install build tools (if not already installed):
pip install build twine
-
Build the distribution packages:
python -m build
This creates both source distribution (.tar.gz) and wheel (.whl) in the
dist/directory. -
Verify the build:
twine check dist/*
-
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
-
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
Release files for domain-events 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| domain_events-2.3.0.tar.gz | 15.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| domain_events-2.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.2 kB
Release files / domain_events-2.3.0.tar.gz
| Download URL | domain_events-2.3.0.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c115fd3542c5e912c2a92c0f149cd8d1a401fa0c49ebf3c99d8f222b0f2cd1b1
|
|
BLAKE2b-256 checksum How to use checksums |
50cdf8de6ad0595de1b8a4e3dfbdc1df63ef1303db15c949f8505bba99739103
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|
Release files / domain_events-2.3.0-py3-none-any.whl
| Download URL | domain_events-2.3.0-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c3617132c995a2aff22448587542b80512addcede7799f5b5288b2e2163c1fad
|
|
BLAKE2b-256 checksum How to use checksums |
bcc61d3458be80cbe793b1e7c3274b556d820e49e13e0bc0ed4868c92c422fa1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.19
|