pyzmq
Python bindings for ZeroMQ, the lightweight messaging library for building distributed, concurrent, and asynchronous applications.
Repository Health
Technical Analysis
PyZMQ is the official Python binding for ZeroMQ (0MQ), a high-performance asynchronous messaging library used to build distributed and concurrent systems without a centralized broker. It exposes ZeroMQ’s socket types (PUB/SUB, REQ/REP, PUSH/PULL, ROUTER/DEALER, and more) as Pythonic Context and Socket objects, letting applications pass messages between threads, processes, and machines over in-process, IPC, TCP, or PGM transports.
The package ships with two backend implementations under the hood: a compiled Cython extension for CPython (the default, built against libzmq via CMake and scikit-build-core) and a pure-Python CFFI backend for PyPy compatibility. On top of the low-level bindings, PyZMQ layers native asyncio support (zmq.asyncio), a Tornado-style event loop integration (zmq.eventloop), gevent-friendly sockets (zmq.green), and built-in device processes (zmq.devices) for proxying and queuing, so the same core API works across blocking, asyncio, and gevent codebases.
What You Get
- Full ZeroMQ socket API - Context and Socket classes covering PUB/SUB, REQ/REP, PUSH/PULL, ROUTER/DEALER, PAIR, and draft socket types with Pythonic option access via attribute-style getters/setters.
- Dual backend architecture - a compiled Cython extension for CPython performance and a pure-Python CFFI backend for PyPy, selected transparently at import time behind one public API.
- Native asyncio integration -
zmq.asyncio.Contextandzmq.asyncio.Socketexpose coroutine-basedrecv/sendmethods that integrate directly with the standard asyncio event loop. - Tornado/eventloop compatibility -
zmq.eventloop.zmqstream.ZMQStreamandIOLoopbindings for callback-driven, non-blocking socket I/O. - gevent support -
zmq.greenprovides greenlet-cooperative socket and poller implementations for gevent-based applications. - Built-in devices -
zmq.devicesships ready-made proxy, queue, and steerable-proxy processes for common ZeroMQ broker topologies without writing custom relay code. - CURVE security and monitoring - built-in CurveZMQ encryption/authentication helpers (
zmq.auth,curve_keygen) and socket monitoring events for diagnosing connection state.
Common Use Cases
- Distributed worker pools - fan out tasks to worker processes over PUSH/PULL sockets without a message broker.
- Publish/subscribe telemetry - stream metrics, logs, or events from many producers to one or more subscribers using PUB/SUB sockets.
- Inter-process communication - use IPC or in-process (inproc) transports to coordinate threads and processes within a single application faster than sockets over TCP.
- Request/reply microservices - build lightweight RPC-style services with REQ/REP or ROUTER/DEALER patterns as an alternative to HTTP.
- Async and gevent-based network services - integrate ZeroMQ messaging into asyncio event loops or gevent-based servers using the asyncio/green backends instead of blocking I/O.
Under The Hood
Architecture
PyZMQ wraps the ZeroMQ C library through two interchangeable backend implementations selected under zmq/backend/ - a compiled Cython extension (zmq/backend/cython/) built against libzmq via CMake and scikit-build-core, and a pure-Python CFFI backend (zmq/backend/cffi/) used on PyPy. Both backends implement the same low-level surface, which the zmq/sugar/ layer (context.py, socket.py, attrsettr.py) wraps into the public, Pythonic Context/Socket API with attribute-style option access and structured ZMQError exceptions. Higher-level integrations - zmq.asyncio, zmq.eventloop (Tornado-style IOLoop/ZMQStream), zmq.green (gevent), and zmq.devices (proxy/queue processes) - each subclass or wrap the sugar layer independently, so changes to the core Socket/Context abstraction ripple through every integration surface.
Tech Stack
Built for Python 3.9+ using scikit-build-core and CMake to compile the Cython extension against the vendored or system libzmq C library; the CFFI backend is used automatically on PyPy. Distribution ships as prebuilt wheels for macOS, Windows, and Linux (built via a dedicated wheels.yml GitHub Actions workflow) so most installs never compile from source. Tooling includes ruff for linting/formatting and Dependabot for dependency upkeep; there is no web or ORM framework involved since this is a low-level networking binding, not an application framework.
Code Quality
The test suite spans dozens of files exercising every socket pattern (test_pubsub.py, test_reqrep.py, test_pair.py, test_proxy_steerable.py), both backends (test_cffi_backend.py, test_cython.py), asyncio and ioloop integration (test_asyncio.py, test_ioloop.py), CURVE auth (test_auth.py, test_curve_keygen.py), and static typing (test_mypy.py), run through a dedicated GitHub Actions test workflow across platforms. The package ships a py.typed marker for typed consumers, uses ruff for consistent style, and wraps native libzmq error codes in a typed ZMQError hierarchy (zmq/error.py) rather than swallowing them.
What Makes It Unique
Rather than exposing a single blocking API, PyZMQ transparently supports three concurrency models - synchronous, asyncio, and gevent - from one package, plus a CFFI fallback that keeps PyPy compatible without recompiling the extension. The bundled zmq.devices proxy/queue implementations and built-in CURVE security helpers mean common ZeroMQ broker topologies and encrypted transport don’t require hand-rolled relay code, which is unusual among low-level networking bindings.
Used by 2 apps in this directory
argilla
AI Development · Data Engineering
Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.
marimo
Developer Tools · Data Engineering
A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.