Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/psincraian/commandbus
Command Bus Pattern in Python
https://github.com/psincraian/commandbus
commandbus cqrs cqrs-pattern patterns python python-library python3
Last synced: 3 days ago
JSON representation
Command Bus Pattern in Python
- Host: GitHub
- URL: https://github.com/psincraian/commandbus
- Owner: psincraian
- License: mit
- Created: 2018-03-05T18:35:21.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-26T11:43:27.000Z (over 6 years ago)
- Last Synced: 2024-12-13T23:35:28.501Z (21 days ago)
- Topics: commandbus, cqrs, cqrs-pattern, patterns, python, python-library, python3
- Language: Python
- Size: 10.7 KB
- Stars: 20
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
commandbus
## 📜 About
Command bus is a pattern from CQRS. In this pattern we have three components:* `Command`: represents the desired action to be done, like `RegisterUserCommand`.
* `CommandHandler`: retrieves the data from the command and executes all the actions to accomplish the command
objective. In the previous case creates a new user and saves it do database.
* `CommandBus`: routes the command to the handler## ⚒️ Installation
Installation is so easy, you only need to execute
```
pip install commandbus
```## 🚀 Using commandbus
Using command is as easy as type
```python3
from commandbus import Command, CommandHandler, CommandBusclass SomeCommand(Command):
passclass SomeCommandHandler(CommandHandler):
def __init__(self):
self.called = Falsedef handle(self, cmd: Command):
self.called = True
bus = CommandBus()
handler = SomeCommandHandler()
bus.subscribe(SomeCommand, handler)
assert not handler.called
bus.publish(SomeCommand())
assert handler.called
```## 🚩 License
The code is available under the MIT license.