Skip to main content

A small command bus with pluggable queue adapters and response stores (e.g. SQS, RabbitMQ, Redis, etc.)

Project description

DeegzLibs CommandBus (Python)

A small command bus with pluggable queue adapters. Define command messages as Pydantic models, register handlers, and execute commands in-process or via a queue (e.g. AWS SQS, RabbitMQ, Redis).

Installation

pip install deegzlibs-command-bus

Optional extras: [sqs], [redis], [rabbitmq]. See Installation.

Quick start

from command_bus import CommandBus, CommandBusRouter, CommandMessage, CommandHandler
from command_bus.adapters import InMemoryCommandBusAdapter

router = CommandBusRouter()
adapter = InMemoryCommandBusAdapter(queue_name="commands")
bus = CommandBus(queue_adapter=adapter, command_router=router)

@router.command()
def on_order_created(order_id: str, amount_cents: int):
    print(f"Order {order_id}: {amount_cents} cents")

# Fire-and-forget
await bus.execute(on_order_created(order_id="ord-1", amount_cents=1999), wait=False)

# Worker: poll and dispatch
await bus.work()

To run workers as separate OS processes (useful when handlers do a lot of CPU work), use the built-in CLI, e.g. command-bus-worker myapp.worker:bus --workers 4 (omit :bus if your bus lives on attribute bus). For several queues in one supervised tree, point at a CommandBusGroup, e.g. myapp.worker:command_bus_group (see Worker CLI).

For full examples (messages, handlers, SQS/Redis, execute-and-wait), see the documentation.

Documentation

Topic Description
Installation Package and extras.
Quick start Messages, handlers, register, execute.
Handler decorator @router.command() and message factory.
Message formats and parsers Repr, JSON, Base64, custom parser.
Client and worker Shared module, producer, consumer.
Worker CLI command-bus-worker module[:attr]CommandBus or CommandBusGroup, fork/spawn.
Queue adapters In-memory, SQS, RabbitMQ, Redis.
Execute and wait Response store, request/response.
API reference Types and methods overview.

License

MIT

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

deegzlibs_command_bus-1.2.0.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deegzlibs_command_bus-1.2.0-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file deegzlibs_command_bus-1.2.0.tar.gz.

File metadata

  • Download URL: deegzlibs_command_bus-1.2.0.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for deegzlibs_command_bus-1.2.0.tar.gz
Algorithm Hash digest
SHA256 76e4f858c493a79b697af9331bab292f232988b21b9f404e4fa81f86f236d0e8
MD5 dcb22802ef9d8937e4b0542104a0b288
BLAKE2b-256 dbea313cb09c000c9bcad95c11810c40ce766ad57ab6c243ce96b33505ff4bb9

See more details on using hashes here.

File details

Details for the file deegzlibs_command_bus-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for deegzlibs_command_bus-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1456071c3e96ef817145472a7ccc33f7516cb639358d75f2a5e9d662c4a2d675
MD5 541d7cef1c68a4a871ee4972b9af7b7b
BLAKE2b-256 f00840f46ab819a753c64bd33d77ba973090ba425fc7a8a25f6fbc04ea96f441

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page