Skip to content

Latest commit

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

commandbus

PyPI versionDownload stats version

📜 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

fromcommandbusimportCommand, CommandHandler, CommandBusclassSomeCommand(Command):
passclassSomeCommandHandler(CommandHandler):
def__init__(self):
self.called=Falsedefhandle(self, cmd: Command):
self.called=Truebus=CommandBus()
handler=SomeCommandHandler()
bus.subscribe(SomeCommand, handler)
assertnothandler.calledbus.publish(SomeCommand())
asserthandler.called

🚩 License

The code is available under the MIT license.

About

Command Bus Pattern in Python

Topics

Resources

Stars

22 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages