A lightweight ZeroMQ-based framework for high-performance, cross-environment communication across Local Area Networks.
Project description
pyzlc
pyzlc is a lightweight, cross-environment communication framework designed for Python applications running on Local Area Networks (LAN). Built on top of ZeroMQ, it features automatic node discovery, enabling nodes to dynamically find and connect to sockets from other peers without manual configuration.
pyzlc eliminates the need for heavyweight frameworks like ROS or ROS2 when you simply need to establish quick, reliable communication—whether on the same host or distributed across different machines—while maintaining a minimal dependency footprint.
🚀 Key Features
Zero-Config Discovery: Nodes automatically discover and update each other on the LAN using multicast heartbeats—no master node or manual IP configuration required.
ROS-like API: Designed with a familiar workflow for ROS users. simply initialize a node, register your publishers/subscribers, and start communicating with minimal boilerplate.
Automatic Serialization: Native support for dictionaries, lists, and primitives via msgpack, removing the need to manually define encoders or decoders. Future support is planned for Protobuf and Flatbuffers.
Async-First Architecture: Built on top of Python’s asyncio and ZeroMQ for high-performance, non-blocking asynchronous applications.
Rich Logging: Integrated, color-coded logging system to simplify debugging and status monitoring.
📦 Installation
pip install pyzlc
⚡ Quick Start
- Initialization Every script starts by initializing the singleton node.
import pyzlc
# Initialize the node with a unique name and your local IP
pyzlc.init(node_name="MyNode", node_ip="127.0.0.1")
- Pub/Sub Pattern Publish messages to a specific topic and subscribe to updates.
Publisher:
import pyzlc
import time
pyzlc.init("PublisherNode", "127.0.0.1")
pub = pyzlc.Publisher("chat_room")
while True:
# You can send strings, dicts, or lists directly!
pub.publish({"user": "admin", "text": "Hello World"})
pyzlc.info("Message published")
pyzlc.sleep(1)
Subscriber:
import pyzlc
def on_chat_message(msg):
# msg is automatically unpacked into a python dict
pyzlc.info(f"Received from {msg['user']}: {msg['text']}")
if __name__ == "__main__":
pyzlc.init("SubscriberNode", "127.0.0.1")
# Register a callback for the topic
pyzlc.register_subscriber_handler("chat_room", on_chat_message)
# Keep the node running
pyzlc.spin()
- Service (RPC) Pattern Perform Request/Response communication between nodes.
Server (Service Provider):
import pyzlc
def add_two_ints(request):
"""Takes a dict, returns the sum."""
result = request['a'] + request['b']
pyzlc.info(f"Calculated: {result}")
return {"sum": result}
if __name__ == "__main__":
pyzlc.init("ServerNode", "127.0.0.1")
# Register the service
pyzlc.register_service_handler("add_ints", add_two_ints)
pyzlc.spin()
Client (Caller):
import pyzlc
pyzlc.init("ClientNode", "127.0.0.1")
# Wait for service to be discovered on the network
pyzlc.wait_for_service("add_ints")
# Call the service synchronously
response = pyzlc.call("add_ints", {"a": 10, "b": 20})
print(f"Result: {response['sum']}") # Output: 30
🛠 Advanced Usage
Data Streaming For high-frequency data (e.g., sensor readings), use the Streamer class to publish at a fixed FPS.
from pyzlc.sockets.publisher import Streamer
import random
def get_sensor_data():
return {"temp": 20 + random.random(), "timestamp": time.time()}
# Create a streamer that calls get_sensor_data() 30 times per second
streamer = Streamer("sensor_stream", get_sensor_data, fps=30, start_streaming=True)
pyzlc.spin()
Custom Message Structures Because pyzlc uses msgpack, you can use Python TypedDict to define schemas, but you don't need special compilation steps.
from typing import TypedDict, List
class RobotState(TypedDict):
id: int
joints: List[float]
active: bool
# The library handles serialization automatically
msg: RobotState = {"id": 1, "joints": [0.1, 1.2, -0.5], "active": True}
publisher.publish(msg)
🧩 Architecture
pyzlc uses a hybrid architecture to ensure reliability and speed:
- UDP Multicast: Used for node presence (Heartbeats) and discovery.
- TCP (ZeroMQ): Used for actual data transport (PUB/SUB and REQ/REP) to ensure reliable delivery.
- Loop Manager: A dedicated thread pool handles the asyncio event loop, allowing you to run blocking code alongside async communication if needed.
📋 Requirements
Python 3.8+
pyzmq
msgpack
colorama
🧪 Testing
Install the local test dependencies:
pip install -e ".[test]"
Run the default unit suite:
python -m pytest
Run optional integration tests that may use localhost sockets:
python -m pytest -m "integration"
Run optional benchmarks:
pip install -e ".[test,benchmark]"
python -m pytest -m "benchmark" --benchmark-only
Report coverage without enforcing a threshold:
python -m pytest --cov=pyzlc --cov-report=term-missing
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyzlc-2.2.4.tar.gz.
File metadata
- Download URL: pyzlc-2.2.4.tar.gz
- Upload date:
- Size: 32.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
825ac878dfcf296ecc2adbb861596a54a0a45612e064a26ee8d3847f1177865a
|
|
| MD5 |
d86d7080a1b41f021202583511aa5467
|
|
| BLAKE2b-256 |
1731202396f4613c510e09e9d22d8dfe29b815b0ce83567b14e4045aefda6532
|
Provenance
The following attestation bundles were made for pyzlc-2.2.4.tar.gz:
Publisher:
publish.yml on xinkai-jiang/pyzlc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyzlc-2.2.4.tar.gz -
Subject digest:
825ac878dfcf296ecc2adbb861596a54a0a45612e064a26ee8d3847f1177865a - Sigstore transparency entry: 1568218513
- Sigstore integration time:
-
Permalink:
xinkai-jiang/pyzlc@c6378b6778b6a3defb51863b490ea2e55f927a64 -
Branch / Tag:
refs/tags/v2.2.4 - Owner: https://github.com/xinkai-jiang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c6378b6778b6a3defb51863b490ea2e55f927a64 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyzlc-2.2.4-py3-none-any.whl.
File metadata
- Download URL: pyzlc-2.2.4-py3-none-any.whl
- Upload date:
- Size: 31.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b86967ea57c90514c4d696d45565986e36fc7ebb5c1226cdc765a846f325acb1
|
|
| MD5 |
fbb38de2580fd117396ca613a33df4dd
|
|
| BLAKE2b-256 |
654d1d42063f743399f479a34bf9f80ce7dedaf62e46bc6ad8aae7e0c8135bd2
|
Provenance
The following attestation bundles were made for pyzlc-2.2.4-py3-none-any.whl:
Publisher:
publish.yml on xinkai-jiang/pyzlc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyzlc-2.2.4-py3-none-any.whl -
Subject digest:
b86967ea57c90514c4d696d45565986e36fc7ebb5c1226cdc765a846f325acb1 - Sigstore transparency entry: 1568218593
- Sigstore integration time:
-
Permalink:
xinkai-jiang/pyzlc@c6378b6778b6a3defb51863b490ea2e55f927a64 -
Branch / Tag:
refs/tags/v2.2.4 - Owner: https://github.com/xinkai-jiang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c6378b6778b6a3defb51863b490ea2e55f927a64 -
Trigger Event:
push
-
Statement type: