Skip to content

ambient-innovation/django-queuebie

Repository files navigation

PyPI release Downloads Coverage Linting Coding Style Documentation Status

A simple and synchronous message queue for commands and events for Django.

Features

  • Split up your business logic in commands and events
  • Commands are imperatives telling your system what to do, events reflect that something has happened
  • Register light-weight functions via a decorator to listen to your commands and events
  • Message handlers receive the context of the message (command or event), providing an explicit API
  • No magic, no side effects since the queue works synchronously
import dataclasses

from queuebie.runner import handle_message
from queuebie.messages import Command, Event
from queuebie import message_registry


# Example command
@dataclasses.dataclass(kw_only=True)
class BuyProduct(Command):
    product_id: int
    customer_id: int
    price: float
    currency: str


# Example event
@dataclasses.dataclass(kw_only=True)
class ProductBought(Event):
    product_id: int
    customer_id: int


# Example handler
@message_registry.register_command(BuyProduct)
def handle_buy_product(context: BuyProduct) -> Event:
    # Here lives your business logic

    return ProductBought(
        product_id=context.product_id,
        customer_id=context.customer_id,
    )


# Start queue and process messages
handle_message(
    BuyProduct(
        product_id=product.id,
        customer_id=customer.id,
        price=12.99,
        currency="EUR",
    )
)

Installation

  • Install the package via pip:

    pip install django_queuebie

    or via pipenv:

    pipenv install django_queuebie

  • Add module to INSTALLED_APPS within the main django settings.py:

    INSTALLED_APPS = (
        # ...
        "queuebie",
    )

Publish to ReadTheDocs.io

  • Fetch the latest changes in GitHub mirror and push them
  • Trigger new build at ReadTheDocs.io (follow instructions in admin panel at RTD) if the GitHub webhook is not yet set up.

Publish to PyPi

  • Update documentation about new/changed functionality

  • Update the Changelog

  • Increment version in main __init__.py

  • Create pull request / merge to main

  • This project uses the flit package to publish to PyPI. Thus, publishing should be as easy as running:

    flit publish
    

    To publish to TestPyPI use the following to ensure that you have set up your .pypirc as shown here and use the following command:

    flit publish --repository testpypi
    

Maintenance

Please note that this package supports the ambient-package-update. So you don't have to worry about the maintenance of this package. This updater is rendering all important configuration and setup files. It works similar to well-known updaters like pyupgrade or django-upgrade.

To run an update, refer to the documentation page of the "ambient-package-update".

About

A simple and synchronous message queue for commands and events for Django.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.md

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages