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
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 setup.py sdist
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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f2506e851ad4a9d4d1c1c9dceee20c26569c51ceccca285280053be2e5b9d22
|
|
| MD5 |
ede3f87692e1ddfad64f6b15a8e3c1cb
|
|
| BLAKE2b-256 |
e63b6aff69bed71cf17b117f75e22e80abe007599cd585456b1ba73516e33f4f
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84a319327278cbf51155420e034e1597cf6bc347d28a0029339348fe94702c10
|
|
| MD5 |
b5cae2e5095b0c4169f2a620873954fe
|
|
| BLAKE2b-256 |
a4e3630246e3df8180939a456575ea1854a969483ed9876184b17e13efd0aaca
|