Skip to main content

Eager broker for dramatiq

Project description

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()
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:

@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])

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

dramatiq_eager_broker-0.1.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

dramatiq_eager_broker-0.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file dramatiq_eager_broker-0.1.0.tar.gz.

File metadata

File hashes

Hashes for dramatiq_eager_broker-0.1.0.tar.gz
Algorithm Hash digest
SHA256 785d33ba31933cc186f02b62f0c900d483c26f206bd638422ae5c087da598ec3
MD5 127058fd278bd1854ee18fae6cbb35e9
BLAKE2b-256 a99ac109a0673546dace75ed0d0eb6fc01b46755d0bb724917f84a9c0e054b68

See more details on using hashes here.

File details

Details for the file dramatiq_eager_broker-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dramatiq_eager_broker-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0e092197794d3a7dbc09d967d7a97a87593c529a166ccb3a6c7040b8995f848
MD5 c30d024432038f96e94ad640bc82b548
BLAKE2b-256 286e9b9bf0e9b1653183dc996a0b77cf8313900dc3dd2ed01037472d7eada9ec

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