dramatiq-eager-broker
An eager broker for Dramatiq that executes tasks synchronously and immediately, without queuing. Perfect for testing and development environments.
Features
- Synchronous task execution
- No message broker required (Redis, RabbitMQ, etc.)
- Pipeline support
- Middleware support
- Drop-in replacement for testing
Installation
pip install dramatiq-eager-broker
Or with uv:
uv add dramatiq-eager-broker
Usage
import dramatiq
from dramatiq_eager_broker import EagerBroker
broker = EagerBroker(middleware=[])
dramatiq.set_broker(broker)
@dramatiq.actor
def send_email(email, message):
print(f"Sending email to {email}: {message}")
# Tasks are executed immediately and synchronously
send_email.send("user@example.com", "Hello!")
Testing Example
import dramatiq
import pytest
from dramatiq_eager_broker import EagerBroker
@pytest.fixture
def eager_broker():
broker = EagerBroker(middleware=[])
dramatiq.set_broker(broker)
yield broker
dramatiq.set_broker(None)
def test_my_actor(eager_broker):
results = []
@dramatiq.actor
def my_task(value):
results.append(value)
my_task.send("test")
assert results == ["test"]
Pipeline Support
The eager broker supports Dramatiq pipelines:
from dramatiq.middleware import Pipelines
@pytest.fixture
def eager_broker():
broker = EagerBroker(middleware=[Pipelines()])
dramatiq.set_broker(broker)
yield broker
dramatiq.set_broker(None)
@dramatiq.actor
def add(x, y):
return x + y
@dramatiq.actor
def multiply(result, factor):
return result * factor
# Create and execute a pipeline
pipeline = add.message(2, 3) | multiply.message(factor=10)
broker.enqueue(pipeline.messages[0])
Results Support
The eager broker supports Dramatiq get_result() if the Results middleware is loaded:
from dramatiq.middleware import Pipelines
from dramatiq.results import Results
from dramatiq.results.backends import StubBackend
@pytest.fixture
def eager_broker():
broker = EagerBroker(middleware=[Pipelines(), Results(backend=StubBackend())])
dramatiq.set_broker(broker)
yield broker
dramatiq.set_broker(None)
@dramatiq.actor(store_result=True)
def add(x, y):
return x + y
@dramatiq.actor
def multiply(result, factor):
return result * factor
# Create and execute a pipeline
pipeline = add.message(2, 3) | multiply.message(factor=10)
broker.enqueue(pipeline.messages[0])
assert pipeline.get_result() == 60
Results with exceptions
If the task should be executed synchronously but the actor should not raise an exception, use fail_fast=False.
This mimics the conventional Dramatiq behavior which stuffs the exception into the message.
from dramatiq.middleware import Pipelines, Retries
from dramatiq.results import Results, ResultFailure
from dramatiq.results.backends import StubBackend
@pytest.fixture
def eager_broker():
broker = EagerBroker(middleware=[Pipelines(), Retries(), Results(backend=StubBackend())], fail_fast=False)
dramatiq.set_broker(broker)
yield broker
dramatiq.set_broker(None)
@dramatiq.actor(store_result=True, throws=ValueError)
def add(x, y):
if x < y:
raise ValueError("x < y")
message = add.send(2, 3)
with pytest.raises(ResultFailure):
message.get_result()
Metadata
Release files for dramatiq-eager-broker 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dramatiq_eager_broker-0.3.0.tar.gz | 2.9 kB | Without provenance | Details for dramatiq_eager_broker-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dramatiq_eager_broker-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for dramatiq_eager_broker-0.3.0-py3-none-any.whl |
Total release size: 6.0 kB
Release files / dramatiq_eager_broker-0.3.0.tar.gz
| Download URL | dramatiq_eager_broker-0.3.0.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5f1491195df2299251275c1390f1c33fac26ba8aff9feec5496555441df9a02
|
|
BLAKE2b-256 checksum How to use checksums |
9182eab853b2822803ff9b5b7b17ab8737524c8ed888b9070612cc4ebd821f86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Release files / dramatiq_eager_broker-0.3.0-py3-none-any.whl
| Download URL | dramatiq_eager_broker-0.3.0-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
332cfee6d6b598ad322b0e768eb05a97c591e8c365a0d275ce64fad2bdfb4402
|
|
BLAKE2b-256 checksum How to use checksums |
1e9cbdfdeae6c63dfbdf6688784471ac3ecf7a6071d7e0600d4856a81f4e01f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.5
|
Security for dramatiq-eager-broker 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.