Skip to content

irachex/localpub

Repository files navigation

localpub 🥃

A decentralized, brokerless pub/sub for multi-process communication on a single machine.

A local pub for your processes to hang out. 🍻

CI PyPI License: MIT Ruff

Features

  • Multiple backends: Choose the right transport for your workload:
    • Unix Domain Socket Mesh — peer-to-peer, no single point of failure
    • Unix Domain Socket Broker — competitive binding, first process becomes broker
    • mmap Ring Buffer — ultra-low-latency shared memory
  • Async-first: Modern asyncio APIs with convenient sync wrappers
  • Pluggable serialization: Pass any Python object; swap in JSON, msgpack, or your own
  • Zero external dependencies: Pure stdlib for the core package
  • Fully typed: PEP 561 compatible with strict type coverage

Quick Start

import asyncio
from localpub import UnixMeshBus

async def main():
    bus = UnixMeshBus("/tmp/mypub")
    await bus.open()

    await bus.subscribe("greetings", lambda env: print(f"Received: {env.payload}"))
    await bus.publish("greetings", {"msg": "hello from process A"})

    await asyncio.sleep(1)
    await bus.close()

asyncio.run(main())

Synchronous API

from localpub import UnixMeshBus, SyncBus

bus = SyncBus(UnixMeshBus("/tmp/mypub"))
with bus:
    bus.subscribe("greetings", lambda env: print(f"Received: {env.payload}"))
    bus.publish("greetings", "hello")

Pick a backend

Backend Latency Throughput Brokerless Use case
UnixMeshBus Low Medium Yes Resilient, no single point of failure
UnixBrokerBus Low High No (elected) General purpose, simple topology
MmapRingBus Ultra-low Very High Yes High-throughput same-machine IPC

Installation

pip install localpub

Development

# Install dependencies
make install

# Run tests
make test

# Lint & format
make lint
make format

# Type check
make typecheck

# Run all checks (lint + typecheck + test)
make check

# Build wheel and sdist
make build

License

MIT — see LICENSE.

About

Decentralized, brokerless pub/sub for multi-process communication on a single machine.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors