Skip to main content

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

  • 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 (terminate or promote).
  • 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=True during 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comm_ipc-0.1.1.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comm_ipc-0.1.1-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file comm_ipc-0.1.1.tar.gz.

File metadata

  • Download URL: comm_ipc-0.1.1.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comm_ipc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2eca1a7d0c5a97b33ef22000a3e20a2f1bbe6ef800f5b99632b847fe841bd31d
MD5 c9813dbed30889100c2340fa1d5fae04
BLAKE2b-256 5651e9e6ab0d5ae55d966048242b2cdbabd30836fe7440f0f551576b684fb7de

See more details on using hashes here.

Provenance

The following attestation bundles were made for comm_ipc-0.1.1.tar.gz:

Publisher: publish.yml on shashstormer/comm_ipc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file comm_ipc-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: comm_ipc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for comm_ipc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e3b182cefad185ccd4c2de89acb6b87d1c4f0d27f9aba6635a389277931aacfe
MD5 274e3e847ef3f790308293921468b005
BLAKE2b-256 86868d99ea4dded5db614f8deba46afdeea924266ee089ee8b6ed931d2d857e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for comm_ipc-0.1.1-py3-none-any.whl:

Publisher: publish.yml on shashstormer/comm_ipc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page