kombu

A Python messaging library giving Celery and other apps one high-level API over AMQP, Redis, SQS, and a dozen other broker transports.

Library
PyPI
v5.6.2
3,136stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
84/100Excellent
Development Activity84
Maintenance72
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
77/100Good
Architecture88
Code Quality74
Innovation62
Learning Curve85

Kombu is the messaging abstraction layer underneath Celery, providing a single, idiomatic Python API for sending and receiving messages regardless of which broker sits behind it. Rather than coding directly against a broker’s client library, applications declare Exchange and Queue objects and use Connection, Producer, and Consumer classes that behave identically whether the transport is native AMQP (via py-amqp or librabbitmq) or one of Kombu’s virtual transports layered on Redis, Amazon SQS, MongoDB, ZooKeeper, and others.

Beyond routing, Kombu handles the cross-cutting concerns every messaging system needs: pluggable serialization and compression of payloads, consistent exception handling across otherwise-incompatible broker client libraries, connection pooling and failover between broker URLs, and an in-memory transport for unit testing message-driven code without a real broker. It has been the transport layer for Celery for over a decade, so its virtual-transport abstraction and connection-recovery logic have been exercised at very large production scale.

What You Get

  • A Connection class with URL-based broker configuration, automatic failover between multiple broker URLs, and connection/channel pooling
  • Exchange, Queue, and binding primitives that map directly onto AMQP semantics and can be declared once and reused across producers and consumers
  • Over a dozen built-in transports — native AMQP via py-amqp/librabbitmq/qpid, plus virtual transports for Redis, SQS, MongoDB, ZooKeeper, SQLAlchemy, Azure Service Bus/Storage Queues, Google Pub/Sub, Kafka (confluent-kafka), Consul, etcd, and an in-memory transport for tests
  • Automatic serialization (JSON, pickle, msgpack, yaml) and compression of message payloads, with a registry for adding custom codecs
  • Consistent, transport-independent exception types (ConnectionError, ChannelError, OperationalError) so application code doesn’t need per-broker except clauses
  • kombu.mixins.ConsumerMixin/ConsumerProducerMixin for building long-running consumer services with minimal boilerplate
  • kombu.pidbox for building remote-control/broadcast command buses on top of a broker (the mechanism Celery itself uses for worker control commands)

Common Use Cases

  • Powering Celery’s broker transport — Kombu is Celery’s messaging layer, so any Celery deployment (RabbitMQ, Redis, or SQS-backed) is running Kombu underneath
  • Building a custom task/event bus for a Python service without adopting a full task-queue framework, using Connection/Producer/Consumer directly
  • Writing broker-agnostic messaging code that can move from RabbitMQ in production to an in-memory or Redis transport in tests and local development
  • Implementing a remote-control or fan-out command channel for a fleet of worker processes via kombu.pidbox
  • Prototyping AMQP-based pub/sub or work-queue patterns (direct, topic, fanout exchanges) without hand-rolling protocol-level code against pika or amqp

Under The Hood

Architecture Kombu is layered around three concerns that stay strictly separate: declarations (kombu/entity.pyExchange, Queue, binding, which are transport-agnostic and picklable), a connection/pooling layer (kombu/connection.py’s Connection, backed by kombu/resource.py’s generic Resource pool and kombu/pools.py’s process-wide connection/producer pools), and the transport layer itself (kombu/transport/, with base.py defining the Transport/StdChannel/Management interface every backend implements). Non-AMQP brokers plug in through kombu/transport/virtual/, which reimplements AMQP routing semantics (direct/topic/fanout matching, via kombu/matcher.py) entirely in Python so that Redis, SQS, MongoDB, and similar key-value or queue-only services can present the same Channel interface as a real AMQP broker. This virtual-transport layer is the load-bearing abstraction: swapping amqp:// for redis:// in a connection URL changes nothing at the Producer/Consumer call sites. An kombu/asynchronous/ submodule (a Hub event loop plus kombu/asynchronous/aws/) supports the SQS and async-capable transports without pulling in an external event loop dependency.

Tech Stack Pure Python 3.9+, with a deliberately small mandatory dependency set (amqp, vine, tzdata) and everything else — redis, pymongo, boto3 (SQS), PyYAML, msgpack, SQLAlchemy, Azure/GCP SDKs, confluent-kafka — pulled in only via extras_require in setup.py, one extra per transport. Packaging is classic setup.py/setup.cfg (not a PEP 621 pyproject.toml-only project, though pyproject.toml carries tool config for codespell, coverage, isort, and mypy). CI (.github/workflows/) runs a linter workflow, a python-package.yml test matrix, CodeQL, and Semgrep scanning.

Code Quality Tests live under t/unit/, mirroring the package layout (t/unit/transport/, t/unit/asynchronous/, etc.) with roughly 80+ test modules, run via pytest (testpaths = t/unit/ in setup.cfg) with branch coverage tracked via .coveragerc. mypy is configured in setup.cfg with disallow_untyped_defs = True but is scoped to an explicit allowlist of ~19 files rather than the whole package, so type coverage is real but partial — most of the codebase (including much of the transport layer) still relies on docstring-style type comments rather than enforced annotations. Exceptions are centralized in kombu/exceptions.py with a common KombuError base and transport errors normalized to it. flake8 and pre-commit hooks (.pre-commit-config.yaml) enforce style; the code is broadly PEP 8 but tolerates docstring omissions in tests and examples by convention.

What Makes It Unique Kombu’s distinguishing design choice is implementing full AMQP routing semantics (exchange types, routing-key matching, queue binding) in pure Python inside the virtual-transport layer, rather than requiring every backend to natively support AMQP concepts. That’s what lets a single Producer.publish()/Consumer call site work unmodified against RabbitMQ, Redis, or SQS — the abstraction is transport equivalence at the routing-semantics level, not just a shared connection-string format. Combined with its role as Celery’s transport since the project’s early years, this makes Kombu’s virtual-transport contract one of the most battle-tested broker-abstraction layers in the Python ecosystem, rather than a novel algorithmic contribution.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search