Skip to main content

streamz-zmq

PyPI version GitHub release Python 3.10+

ZeroMQ integration for streamz - enabling high-performance streaming data processing with distributed messaging.

Features

  • ZMQ Source (from_zmq): Receive data streams from ZeroMQ publishers
  • ZMQ Sink (to_zmq): Send processed data to ZeroMQ sockets
  • Async Support: Built with asyncio for high-performance streaming
  • Multiple Patterns: Support for PUB/SUB, PUSH/PULL, and other ZMQ patterns
  • Seamless Integration: Extends streamz with familiar API patterns

Installation

pip install streamz-zmq

Or with uv:

uv add streamz-zmq

Quick Start

Receiving data from ZMQ (Source)

from streamz import Stream
import streamz_zmq  # Register the ZMQ extensions
import zmq

# Create a stream that receives from a ZMQ publisher (connect mode, default)
source = Stream.from_zmq("tcp://localhost:5555")
source.sink(print)  # Print received messages

# Start the stream
source.start()

# Or, act as a collector/server and accept connections from publishers:
collector = Stream.from_zmq("tcp://*:6000", sock_type=zmq.PULL, bind=True)
collector.sink(print)
collector.start()

Sending data to ZMQ (Sink)

from streamz import Stream
import streamz_zmq  # Register the ZMQ extensions

# Create a stream and send results to an existing ZMQ service (default: connect mode)
source = Stream.from_iterable([1, 2, 3, 4, 5])
source.map(lambda x: x * 2).to_zmq("tcp://localhost:5556")

# Or, act as a service and accept connections from ZMQ clients (bind mode)
source.map(...).to_zmq("tcp://*:5556", bind=True)

# Start the stream
source.start()

Complete Example: Pipeline with ZMQ

import asyncio
from streamz import Stream
import streamz_zmq

async def main():
    # Receive from one ZMQ socket, process, send to another
    source = Stream.from_zmq("tcp://localhost:5555")

    processed = (source
                .map(lambda x: x.decode('utf-8'))  # Decode bytes
                .map(str.upper)                    # Process data
                .map(str.encode))                  # Encode back to bytes

    processed.to_zmq("tcp://*:5556")

    # Start processing
    await source.start()

if __name__ == "__main__":
    asyncio.run(main())

Examples

Check out the examples/ directory for demonstrations:

  • simple_example.py: Basic example showing ZMQ publisher thread + streamz subscriber
  • comprehensive_example.py: Advanced demonstration showing multiple ZMQ patterns:
    • PUB/SUB: Publisher broadcasts weather updates to topic-specific subscribers
    • PUSH/PULL: Load balancing work distribution across multiple workers
    • Pipeline: Multi-stage data processing pipeline

Run the simple example:

uv run python examples/simple_example.py

Run the comprehensive example:

uv run python examples/comprehensive_example.py

API Reference

Stream.from_zmq(connect_str, sock_type=zmq.SUB, subscribe=b"", bind=False)

Creates a stream source that receives messages from a ZMQ socket.

Parameters:

  • connect_str (str): ZMQ connection string (e.g., "tcp://localhost:5555" for connect, or "tcp://*:5555" for bind)
  • sock_type (int, optional): ZMQ socket type. Defaults to zmq.SUB
  • subscribe (bytes, optional): Subscription topic for SUB sockets. Defaults to b"" (all messages)
  • bind (bool, optional): If True, bind the socket (act as a server/collector). If False (default), connect to the address.

stream.to_zmq(connect_str, sock_type=zmq.PUSH, bind=False)

Sends stream elements to a ZMQ socket.

Parameters:

  • connect_str (str): ZMQ connection string (e.g., "tcp://*:5556" for bind, or "tcp://localhost:5556" for connect)
  • sock_type (int, optional): ZMQ socket type. Defaults to zmq.PUSH
  • bind (bool, optional): If True, bind the socket (act as a service). If False (default), connect to the address.

ZMQ Patterns Supported

  • PUB/SUB: Publisher broadcasts to multiple subscribers
  • PUSH/PULL: Load balancing across workers
  • REQ/REP: Request-response (less common for streaming)

Requirements

  • Python 3.9+
  • streamz >= 0.6.4
  • pyzmq >= 27.0.0

Development

# Clone the repository
git clone https://github.com/izzet/streamz-zmq.git
cd streamz-zmq

# Install with uv (uses uv.lock for reproducible builds)
uv sync --dev

# Set up pre-commit hooks (recommended)
uv run pre-commit install

# Run tests
uv run pytest

# Format code
uv run ruff format .

# Check linting
uv run ruff check .

# Build package
uv build

Note: This project uses uv.lock for reproducible dependency management. The lock file is committed to ensure all developers and CI/CD use identical dependency versions.

Pre-commit hooks: The project includes pre-commit hooks that automatically format code, check linting, and run tests before each commit to maintain code quality.

License

MIT License. See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Metadata

Release files for streamz-zmq 0.1.5

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

Source distribution (sdist)

Source distribution for streamz-zmq 0.1.5
File Size Uploaded Provenance Actions
streamz_zmq-0.1.5.tar.gz 49.0 kB With provenance Details for streamz_zmq-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for streamz-zmq 0.1.5
File Interpreter ABI Platform Actions
streamz_zmq-0.1.5-py3-none-any.whl Python 3 none any Details for streamz_zmq-0.1.5-py3-none-any.whl

Total release size: 56.6 kB

Release files / streamz_zmq-0.1.5.tar.gz

Download URL streamz_zmq-0.1.5.tar.gz
Size 49.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7f9381a49a801aeb1898fe5166a3d26629b265dc46d8e34cc1750b56a258aa5a
BLAKE2b-256 checksum
How to use checksums
d8d8117d077de8fdbbc65bc24f7cc41276e3199877bb959c83bac26a9a9dd0f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Sep 2, 2025.

Transparency log

Release files / streamz_zmq-0.1.5-py3-none-any.whl

Download URL streamz_zmq-0.1.5-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a006a072109f68e5a4617ddd45b26c1f8f3fbc39526131f09c1dc83f9591aa97
BLAKE2b-256 checksum
How to use checksums
1d44da2a9cf1bad781f084a01dd4daf95218027ad25b1be2255eab47a73fc534
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Sep 2, 2025.

Transparency log

Security for streamz-zmq 0.1.5

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.

Select from 2 files

Attestation for streamz_zmq-0.1.5.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 Sep 2, 2025.

Transparency log

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