Go‑style channels in Python — simple, safe, and powerful inter‑process communication.
PyChannel brings the elegance of Go’s concurrency model into Python, enabling subprocesses to communicate through typed channels with synchronous or buffered semantics.
- Go‑like Channels — send and receive values between processes with a clean API.
- Unbuffered & Buffered Modes — synchronous handoff or FIFO/LIFO buffering.
- Composable — designed to integrate with
multiprocessing
and task orchestration. - Lightweight — built on top of Python’s
multiprocessing.Pipe
.
Clone the repo and install locally:
git clone https://github.com/rawbytedev/pychannel.git
cd pychannel
from pychannel import Channel
import multiprocessing
def worker(conn):
ch = Channel("str", main=False, conn=conn)
ch.send("Hello from subprocess!")
if __name__ == "__main__":
ch = Channel("str")
p = multiprocessing.Process(target=worker, args=(ch.Child(),))
p.start()
msg = ch.receive()
print("Main received:", msg)
p.join()
Output:
Main received: Hello from subprocess!
from pychannel.fifo import fifo
q = fifo("str", capacity=2)
q.add("first")
q.add("second")
print(q.pop()) # "first"
print(q.pop()) # "second"
Run the included test suite:
pytest testunit.py -v
pychannel/
│
├── channel.py # Core Channel abstraction
├── fifo.py # FIFO / LIFO buffer implementations
├── exceptions.py # (planned) custom exceptions
├── subproc.py # (planned) orchestration helpers
├── testunit.py # Demo + unit tests
└── README.md
- Buffered channels integrated with
fifo
-
select
‑like API for waiting on multiple channels - Rich error handling (
ChannelClosedError
,DeadlockError
) - Async/await integration for modern Python concurrency
- Real‑world demos (task queues, pipelines, agent communication)
Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to add.
MIT License. See LICENSE for details.