A lightweight IPC library with bridge and streaming support
Project description
CommIPC: Asynchronous Secure Distributed Inter-Process Communication
CommIPC is an asynchronous Inter-Process Communication (IPC) system designed for Linux environments. Written in pure Python, it provides communication through Unix Domain Sockets for local processes and TCP for cross-network communication, featuring integrated bridging, synchronization, and security mechanisms.
Table of Contents
- Key Features
- Architecture Overview
- Components
- Usage Guide
- Performance and Scalability
- Testing
- License
Key Features
- Zero-Trust Security:
- HMAC-SHA256 Handshake: Mandatory cryptographic challenge for every client connection.
- End-to-End Signature: All channel messages are signed with HMAC-SHA256 based on channel passwords, ensuring data integrity even if the server is compromised.
- Advanced Channel Management:
- Owner-Based Administration: The first client to join a channel is the Admin/Owner, with exclusive rights to manage security.
- Explicit Password Protection: Support for protecting channels (including system channels) with unique, cryptographically derived keys.
- Flexible Lifecycle Policies: Configurable policies for handling owner disconnection (
terminateorpromote).
- High Resilience:
- Auto-Reconnect: Robust reconnection logic with exponential backoff and transparent state restoration (channels, providers).
- Synchronous Persistence: Client APIs wait for server confirmation for registrations and security changes, preventing communication hangs.
- Dependency-Free: Implemented entirely using the Python standard library, requiring no external packages.
Architecture Overview
The system operates as a hub-and-spoke model locally, which can be extended into a mesh or linear topology using bridges.
graph TD
subgraph "Local Network A"
SrvA["CommIPCServer (Primary)"]
CliA1["Client A1"] <--> SrvA
CliA2["Client A2"] <--> SrvA
end
subgraph "Bridge Link"
Bridge["CommIPCBridge"]
end
subgraph "Remote Network B"
SrvB["CommIPCServer (Secondary)"]
CliB1["Client B1"] <--> SrvB
end
SrvA <--> Bridge <--> SrvB
Components
- CommIPCServer: The central message coordinator responsible for client lifecycle management, authentication, and message routing.
- CommIPC: The primary client interface for application integration.
- CommIPCChannel: A high-level abstraction layer for interacting with specific logical communication channels.
- CommIPCBridge: A specialized interconnect service that synchronizes providers and subscribers across discrete server instances.
Usage Guide
Basic RPC (Request-Response)
Service Provider
import asyncio
from comm_ipc.client import CommIPC
async def main():
client = CommIPC(client_id="math_service")
channel = await client.open("math_operations")
def add(params):
return params.data["a"] + params.data["b"]
await channel.add_event("sum", call=add)
# Maintain the service loop
await asyncio.Future()
if __name__ == "__main__":
asyncio.run(main())
Service Consumer
import asyncio
from comm_ipc.client import CommIPC
async def main():
client = CommIPC(client_id="application_client")
channel = await client.open("math_operations")
response = await channel.event("sum", {"a": 15, "b": 25})
print(f"Calculated Sum: {response.data}") # Expected Output: 40
if __name__ == "__main__":
asyncio.run(main())
Streaming Responses
Stream Provider
async def sequence_generator(request):
n = request.data.get("limit", 10)
for i in range(n):
yield i
await asyncio.sleep(0.05)
await channel.add_stream("data_feed", call=sequence_generator)
Stream Consumer
async for chunk in channel.stream("data_feed", {"limit": 5}):
print(f"Received Chunk: {chunk.data}")
Cross-Network Bridging
from comm_ipc.bridge import CommIPCBridge
# Establishes a link between a local Unix socket and a remote TCP server
bridge = CommIPCBridge(socket_path1="/tmp/local_service.sock")
await bridge.connect(
target1_params={},
target2_params={"host": "192.168.1.100", "port": 9000}
)
Security & Channel Management
Protecting a Channel (Owner)
# The first client to open the channel becomes the owner
channel = await client.open("secure-data")
await client.set_password("secure-data", "strong-password")
Joining a Protected Channel
# Fails if password is wrong or missing
channel = await client.open("secure-data", password="strong-password")
Protecting System Channels
You can secure internal system channels (logs, errors, registration events) by providing a system_passwords dictionary when initializing the server:
server = CommIPCServer(
system_passwords={
"__comm_ipc_logs": "log-secret",
"__comm_ipc_errors": "error-secret",
"__comm_ipc_system": "sys-secret"
}
)
Performance and Resilience
CommIPC is optimized for reliability:
- Auto-Reconnect: Automatically recovers from server restarts and network interruptions.
- State Preservation: Transparently restores all active channel memberships and event providers after a reconnection event.
- Optional Client Logging: Clients are silent by default; set
verbose=Trueduring initialization to enable terminal logging. - Unix Domain Sockets: Minimizes latency for local-host communication by bypassing the network stack.
Testing
The project maintains a comprehensive verification suite located in the tests/ directory.
# Execute the full validation suite
PYTHONPATH=. pytest tests/
The test coverage includes:
- Zero-Trust Verification: HMAC handshakes, signature integrity, and E2E verification.
- Advanced Management: Ownership logic, lifecycle policies, and resource cleanup.
- Resilience: Auto-reconnect stability and state restoration.
- Distributed Systems: Bridge synchronization and circular path detection.
- Streaming: Asynchronous iterator support across local and remote instances.
License
This project is licensed under the LGPLv3 License.
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 comm_ipc-0.1.2.tar.gz.
File metadata
- Download URL: comm_ipc-0.1.2.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd1c51a3388c40010792c392cd813d5b5f14e4ec69c08c3d21a6bc66e937a5cc
|
|
| MD5 |
c012c0e7855d04ccdc642e7a882047c3
|
|
| BLAKE2b-256 |
7ad2698e489999be5fd46e5ebac361f906d5796261a1e1f7510f3cd3bc15d6e0
|
Provenance
The following attestation bundles were made for comm_ipc-0.1.2.tar.gz:
Publisher:
publish.yml on shashstormer/comm_ipc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
comm_ipc-0.1.2.tar.gz -
Subject digest:
dd1c51a3388c40010792c392cd813d5b5f14e4ec69c08c3d21a6bc66e937a5cc - Sigstore transparency entry: 1228613662
- Sigstore integration time:
-
Permalink:
shashstormer/comm_ipc@1e65f4e851078aa1a214fcae074134451ecec8e0 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/shashstormer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1e65f4e851078aa1a214fcae074134451ecec8e0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file comm_ipc-0.1.2-py3-none-any.whl.
File metadata
- Download URL: comm_ipc-0.1.2-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6b80d99b944f8b5a0c4ae12eab476b8d75da296e62a735864868f5c25e4d2c9
|
|
| MD5 |
ada6fb367003e223dce29e2dcd1492be
|
|
| BLAKE2b-256 |
bc0fe4b931723de0619e9f4883f8e3f19c7855803c8d433500442467ecad6f27
|
Provenance
The following attestation bundles were made for comm_ipc-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on shashstormer/comm_ipc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
comm_ipc-0.1.2-py3-none-any.whl -
Subject digest:
c6b80d99b944f8b5a0c4ae12eab476b8d75da296e62a735864868f5c25e4d2c9 - Sigstore transparency entry: 1228613671
- Sigstore integration time:
-
Permalink:
shashstormer/comm_ipc@1e65f4e851078aa1a214fcae074134451ecec8e0 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/shashstormer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1e65f4e851078aa1a214fcae074134451ecec8e0 -
Trigger Event:
push
-
Statement type: