Skip to main content

dramatiq_sqs

A Dramatiq broker that can be used with Amazon SQS.

The backend uses boto3 under the hood. For details on how authorization works, check out its docs.

Installation

pip install dramatiq_sqs

Usage

import dramatiq

from dramatiq.middleware import (
    AgeLimit,
    TimeLimit,
    Callbacks,
    Pipelines,
    Prometheus,
    Retries,
)
from dramatiq_sqs import SQSBroker

broker = SQSBroker(
    namespace="dramatiq_sqs_tests",
    middleware=[
        Prometheus(),
        AgeLimit(),
        TimeLimit(),
        Callbacks(),
        Pipelines(),
        Retries(min_backoff=1000, max_backoff=900000, max_retries=96),
    ],
)
dramatiq.set_broker(broker)

Performance considerations

Prefetch

SQS is limited to returning a maximum of 10 messages per ReceiveMessage call. dramatiq_sqs is able to prefetch more than that by making multiple SQS requests - keep this in mind when setting your dramatiq_queue_prefetch.

Long polling

The consumer uses SQS long polling by default, with the maximum allowed WaitTimeSeconds of 20. There seem to be no reasons to support values that are lower or zero, so this is not configurable.

With a reasonably high number of worker threads, the botocore connection pool (max 10 by default) may be too small. If the overhead of no connection reuse is of concern, consider increasing the pool size. Staying above the total number of worker threads + consumer threads per process is a good rule of thumb.

config = botocore.config.Config(max_pool_connections=64)
client = boto3.client("sqs")
broker = SQSBroker(client)

Dead-letter queues

DLQs are enabled and used by default. Note that SQS-native "dead-letter queues" aka redrive policies are not used. These are normal queues and the nacks are handled client-side by Dramatiq.

DLQs may be disabled globally, in this case failed messages will simply get deleted:

broker = SQSBroker(dl_queues_enabled=False)

Keep in mind that while you may still set up redrive policies externally, some mechanisms like Retries and graceful shutdowns will not work as advertised anymore, as Dramatiq can't have any control over SQS ReceiveCounts.

Automatic queue provisioning

By default, in line with the behaviour of the built-in brokers, dramatiq-sqs will attempt to create all declared queues in SQS if they don't exist and set the queue attributes and tags. This includes DLQs, if enabled. None of the attribute defaults are decided by dramatiq-sqs, nor is setting them required for normal operation, so this is a purely optional customization mechanism.

broker = SQSBroker(
    queue_attributes={"MaximumMessageSize": str(1024 * 1024)},
    dl_queue_attributes={
        "MaximumMessageSize": str(1024 * 1024),
        "MessageRetentionPeriod": str(24 * 3600),
    },
    tags={"managed-by": "dramatiq"},
)

Supported Amazon SQS attributes

If all this is undesired (e.g. if the queues are defined statically via IaC), queue management may be disabled completely:

broker = SQSBroker(manage_queues=False)

SQS IAM permissions required

Below is an example of an identity-based IAM policy that allows queue usage as well as auto-provisioning.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "UseSQSQueues",
            "Effect": "Allow",
            "Action": [
                "sqs:ChangeMessageVisibility",
                "sqs:ChangeMessageVisibilityBatch",
                "sqs:DeleteMessage",
                "sqs:GetQueueAttributes",
                "sqs:GetQueueUrl",
                "sqs:PurgeQueue",
                "sqs:ReceiveMessage",
                "sqs:SendMessage",
                "sqs:SendMessageBatch",
            ],
            "Resource": ["*"]
        },
        {
            "Sid": "ManageSQSQueues",
            "Effect": "Allow",
            "Action": [
                "sqs:CreateQueue",
                "sqs:SetQueueAttributes",
                "sqs:TagQueue",
            ],
            "Resource": ["*"]
        }
    ]
}

License

dramatiq_sqs is licensed under Apache 2.0.

Metadata

Release files for dramatiq-sqs 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dramatiq-sqs 0.7.0
File Size Uploaded Provenance Actions
dramatiq_sqs-0.7.0.tar.gz 9.5 kB Without provenance Details for dramatiq_sqs-0.7.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dramatiq-sqs 0.7.0
File Interpreter ABI Platform Actions
dramatiq_sqs-0.7.0-py3-none-any.whl Python 3 none any Details for dramatiq_sqs-0.7.0-py3-none-any.whl

Total release size: 20.7 kB

Release files / dramatiq_sqs-0.7.0.tar.gz

Download URL dramatiq_sqs-0.7.0.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
af23622cd520aedc70ad2feb7392de1cc89ad98dbdd7630ee0c45cbd1d76b639
BLAKE2b-256 checksum
How to use checksums
a6a727b18b718d1af60d44d7cf0971e5f11afb28a793a060dd5b96e3fc0f56a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / dramatiq_sqs-0.7.0-py3-none-any.whl

Download URL dramatiq_sqs-0.7.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
209962d0193abc5b800ae1c76cc3cc37d5385bd1c6afddec049c7ab026b74bc7
BLAKE2b-256 checksum
How to use checksums
7a34e7a60e202c8e4aeed1b66f1772c5a627025b297d5d96ecf382d0cdb4a192
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for dramatiq-sqs 0.7.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page