The async-first Python task queue that does not lose your work.
RabbitMQ quorum queues for delivery, Valkey for state – and everything a production worker needs in the core.
from swarmq import Task, TaskInfo
class SendEmail(Task):
task_info = TaskInfo(name="send_email", queues=["default"],
rate_limit="100/m", max_retries=5, soft_timeout=30)
async def run(self, to: str, subject: str) -> str:
await mailer.send(to, subject)
return f"sent to {to}"
swarmq worker --module myapp.tasks --processes 4 --autoscale 2,8
One async def, one command. Retries with backoff, a distributed rate limit, timeouts,
a supervisor that restarts crashed workers and autoscaling on queue depth come along –
no plugins, no glue code.
Why SwarmQ
|
⚡ Async to the core |
🛡️ At-least-once by default |
|
🧮 CPU work without blocking the loop |
🎛️ Control built in, not bolted on |
|
🔗 Workflows that finish – or fail loudly |
📈 Operable from day one |
Tested like infrastructure. More than 7 000 tests across unit, integration, e2e, chaos (Toxiproxy), property, fuzz, stress and soak suites, a 100 % diff-coverage gate, mutation testing, and a separate load-test suite that accepts every release with conformance checks, smoke runs and one-hour reference runs (24 hours for larger changes). Deliberate behaviour is recorded in a decision register and pinned by tests.
Quick start
pip install swarmq # Python 3.14+
docker compose up -d # RabbitMQ + Valkey from this repository
1. Define a task – myapp/tasks.py:
from swarmq import Task, TaskInfo
class SendEmail(Task):
task_info = TaskInfo(name="send_email", queues=["default"])
async def run(self, to: str, subject: str) -> str:
return f"sent to {to}"
2. Start a worker:
export SWARMQ_BROKER_URL="amqp://guest:guest@localhost:5672/"
export SWARMQ_BACKEND_URL="valkey://localhost:6379/0"
swarmq worker --module myapp.tasks
3. Schedule from your app and wait for the result:
import asyncio
from swarmq import SwarmQ, RabbitMQBroker, ValkeyBackend
import myapp.tasks # registers SendEmail
async def main() -> None:
app = SwarmQ(
RabbitMQBroker("amqp://guest:guest@localhost:5672/"),
ValkeyBackend("valkey://localhost:6379/0"),
)
async with app:
task_id = await app.schedule("send_email", to="op@example.com", subject="hi")
print(await app.get_result(task_id, timeout=10)) # sent to op@example.com
asyncio.run(main())
The worker drains gracefully on SIGTERM. Next steps: the
getting-started guide and the
first-worker tutorial.
Feature tour
Reliable delivery
- At-least-once on RabbitMQ quorum queues, ack after execution,
x-delivery-limitagainst redelivery loops;DeliveryMode.FIRE_AND_FORGETper task where speed beats durability. - Retries with exponential, linear or fixed backoff and jitter;
Retry(delay=...)andNoRetryfrom inside the task. - Dead-letter queue on exhausted retries, expiry or rejection, with
swarmq dlq list / inspect / retry / purge. - Backend outages before execution defer the message with backoff instead of burning its delivery budget; publish, channel and pub/sub paths reconnect on their own.
- Soft and hard timeouts –
soft_timeoutfails the attempt (retry policy applies),hard_timeoutcancels it (in CPU mode: kills the compute child).
Task control
- Rate limits –
TaskInfo(rate_limit="100/m"), a two-period sliding window in Lua, shared by every worker. - Locks – mutex or semaphore per key:
lock="user:{user_id}". - Unique tasks – deduplicated by canonical arguments until start or completion.
- Priorities, expiry (
max_age), cancellation before and during execution, progress reporting withapp.watch_progress(...). - Scheduler – cron with an IANA time zone per task and a fixed rule for clock
changes, delayed tasks (
eta=), leader election with failover; one Valkey can serve several apps (SWARMQ_NAMESPACE). - Batch API –
schedule_many,get_results,run.
Workflows
from swarmq import chain, chord, group
handle = await app.apply(chord(group(Download.s(u) for u in urls), Merge.s()))
result = await handle.get(timeout=30)
chain,group,chordwithTask.s(), immutableTask.si(),sig("name")and|syntax; construction-time limits on depth and group size.app.apply(...)returns a handle:get(),status(),children(),cancel(), and reattach anywhere withapp.workflow(workflow_id).
Running workers
- Supervisor by default – restarts crashed workers into the same slot, replaces
workers with a stalled heartbeat, reloads on
SIGHUP, takes its children down even onSIGKILL. Exit code78for configuration errors. - Multi-process (
--processes N) with stable slot identities (<host>:<slot>) in logs, metrics and signals. - Autoscaling (
--autoscale MIN,MAX) on queue depth, with cooldown and idle windows. - Control channel (
--max-processes,--group) – change process counts and autoscale bounds at runtime through Valkey, with a status report per supervisor. - CPU mode (
--pool cpu) – forkserver-based compute children, recycled by RSS or task count. - Burst mode (
--burst) for batch jobs; hot reload (--reload) for development.
Extensibility and observability
- Middleware with six hooks and stack semantics; 30 lifecycle signals with
@app.on_signal(...);--configure MODULE:CALLABLEwires both into the CLI worker. - Dependency injection via Dishka (
pip install 'swarmq[dishka]'): annotate parameters withFromDishka[...], one request scope per task. - Structured logging – human or JSON through a bounded, non-blocking queue; every
event inside a task carries
task_id,queue,worker_id,attemptand more. Your owndictConfigand structlog work too. - Prometheus metrics (
pip install 'swarmq[metrics]') and HTTP health (/health,/readywith a structured 503 body). - Bring your own connections – hand an existing aio-pika connection or Valkey client
to
RabbitMQBroker/ValkeyBackend; SwarmQ never closes what it did not open. - Machine-readable spec – JSON schemas for messages, errors, config and CLI plus an
llms.txt, generated from the code and checked by tests.
How it compares
A condensed view of a feature comparison of eleven Python task queues (core features of the current stable release, October 2026). ✅ in the core · ◐ partial or manual · 🔌 plugin only · ❌ not available
| SwarmQ | Celery | Dramatiq | TaskIQ | arq | |
|---|---|---|---|---|---|
| Async tasks in the worker | ✅ | ❌ | ◐ | ✅ | ✅ |
| At-least-once by default | ✅ | ❌ | ✅ | ◐ | ✅ |
| Soft and hard timeout | ✅ | ✅ | ◐ | ◐ | ◐ |
| Distributed rate limit | ✅ | ❌ | ◐ | ❌ | ❌ |
| Locks / concurrency per key | ✅ | ◐ | ◐ | ❌ | ◐ |
| DLQ with requeue tooling | ✅ | ❌ | ◐ | 🔌 | ❌ |
| Cron without duplicates across instances | ✅ | 🔌 | ❌ | ❌ | ✅ |
| Workflows (chain / group / chord) | ✅ | ✅ | ✅ | 🔌 | ❌ |
| Pool for CPU-bound work | ✅ | ✅ | ◐ | ✅ | ❌ |
| Autoscaling | ✅ | ◐ | ❌ | ❌ | ❌ |
| HTTP health endpoint | ✅ | ❌ | ❌ | ❌ | ◐ |
Where SwarmQ is the wrong pick – today: it is young (0.x, one maintainer, no
production users besides the author), needs Python 3.14+ and both RabbitMQ and Valkey,
runs async def tasks only, has no dashboard, no in-memory test broker and no Windows
support. If you need the largest ecosystem, choose Celery; for simple synchronous jobs on
Redis, RQ or Dramatiq.
Configuration at a glance
Everything is set by CLI flag, SWARMQ_* environment variable or constructor argument;
swarmq worker resolves each option once as flag > env > default for the
supervisor, all workers and compute children alike.
| Flag / variable | Default | Purpose |
|---|---|---|
SWARMQ_BROKER_URL |
required | AMQP URL of RabbitMQ |
SWARMQ_BACKEND_URL |
required | Valkey URL for results and coordination |
--queues a,b |
default |
Queues to consume |
--concurrency N |
10 (io) / CPUs ÷ processes (cpu) |
Parallel tasks per worker |
--processes N / --autoscale MIN,MAX |
1 / off |
Process count, fixed or by queue depth |
--pool io|cpu |
io |
Event loop only, or forkserver compute children |
--log-format human|json |
human |
Log output on stderr |
--metrics-port / --health-port |
off | Base ports; slot s binds base + s |
The complete list lives in the configuration and CLI references.
Documentation
| 🚀 Getting started | Install, run a worker, get a result |
| 🎓 Tutorial | Build a complete worker step by step |
| 🧭 How-to guides | Retries, rate limits, locking, workflows, CPU mode, deployment, testing |
| 📚 Reference | API, CLI, configuration, logging, errors, changelog |
| 🧠 Explanation | Architecture, delivery semantics, design decisions |
| 🤖 Agent reference | Machine-readable spec and llms.txt |
The documentation is available in English and German and builds with
uv run --extra docs mkdocs serve.
License
MIT
Metadata
Release files for swarmq 0.16.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 |
|---|---|---|---|---|
| swarmq-0.16.0.tar.gz | 552.4 kB | With provenance | Details for swarmq-0.16.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| swarmq-0.16.0-py3-none-any.whl | Python 3 | none | any | Details for swarmq-0.16.0-py3-none-any.whl |
Total release size: 1.2 MB
Release files / swarmq-0.16.0.tar.gz
| Download URL | swarmq-0.16.0.tar.gz |
|---|---|
| Size | 552.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4032072e8b2c8771a024a95ea7a120488565bf68db844050cbb1e6124680ff8f
|
|
BLAKE2b-256 checksum How to use checksums |
4d84cdbd013c459855123e111ca53854d41b8e427b82d34aea715631072afac4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / swarmq-0.16.0-py3-none-any.whl
| Download URL | swarmq-0.16.0-py3-none-any.whl |
|---|---|
| Size | 662.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59acbf7611ef5e585862f21ef51a134364596faa2799aa7cc26e8d05e1c5d253
|
|
BLAKE2b-256 checksum How to use checksums |
50f485e5c39308daef0e3b86ca39c1c3a64f1143e885ba05e44442cc2f9e7b44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for swarmq 0.16.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for swarmq-0.16.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA 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.