Pychanasync
pychanasync is a lightweight python package which brings Go-style channels to
python's asyncio concurrency world. It is an async-channel implementation,
providing a channel shaped tool for channel shaped problems.
pychanasync is implemented entirely around pythons asyncio event loop.
The implementation is lock free ,taking advantage of the single threaded
cooperative concurrency model.
It is designed and implemented to work with coroutines and not threads, providing safe and deterministic communication patterns without blocking the event loop.
Visit documentation site for more details.
Features
- Buffered and unbuffered channel semantics - use either synchronous or buffered communication
- Async iteration over channels - Consume messages from a channel using
async forloops. - Context manager support - close channels and release resources when done with
async with. - Blocking/ awaitable operations -
await chan.push(value)andawait chan.pull()for safe, cooperative communication. - Non-blocking operations -
chan.push_nowait(value)andchan.pull_nowait()for buffered channels when you don’t want to suspend. - Select-like utility - wait on multiple channel operations concurrently, similar to Go’s select statement, in a clean and Pythonic way
Installation
pychanasync is available on PyPi
pip install pychanasync
Quickstart
Channels can be both buffered and unbuffered.
unbuffered channels have no internal buffer capacity. What this means is
every producer (push) will block/suspend until there is a ready consumer on
the other end of the channel (pull) and every consumer until there is a
ready producer on the other end of the channel.
from pychanasync import channel
#create unbuffered channel
ch = Channel()
# send
async ch.push("item") #blocks here
# receive
value = async ch.pull()
buffered channels have an internal buffer capacity and can hold (N)
number of items at a time. When doing a push into a buffered channel, the
operation will only block when the buffer is full and until there is available
space to send the new item. Other than that the operation completes
and returns quickly.
Below is a buffered channel that can hold 300 items at a time.
from pychanasync import channel
ch = Channel(buffer=300)
# send
async ch.push("item")
# receive
value = async ch.pull()
Async Iteration
pychanasync supports async iteration, allowing you to consume items from a channel
in a clean way using async for loop.
We can rewrite our consumer above as
async def consumer(ch):
async for msg in ch:
print(f"Received: {msg}")
Once the producer closes the channel , the iteration ends .
Context manager support
pychanasync has support for asynchronous context managers for automatic cleanup.
We can rewrite out producer component as
async def producer(channel):
async with channel as ch:
for i in range(3):
await ch.push(f"msg {i}")
print(f"Sent msg {i}")
When the async-with block exits , the channel is closed automatically.
Chanselect
The chanselect utility method allows you to start and wait on multiple channel operations simultaneously,
returning the one that completes first.
synthax
chan, value = await chanselect(
(chan_a, chan_a.pull()),
(chan_b, chan_b.pull())
)
checkout more features
Basic consumer-producer example
import asyncio
from pychanasync import Channel
async def producer(ch):
for i in range(3):
await ch.push(f"msg {i}")
print(f"Sent msg {i}")
ch.close() # gracefully close when done
async def consumer(ch):
while True:
try:
msg = await ch.pull()
print(f"Received {msg}")
except Channel.Closed:
break
async def main():
ch = Channel(buffer=2)
await asyncio.gather(producer(ch), consumer(ch))
asyncio.run(main())
Contributing
To contribute or set up the project locally.
find the project source code on github
Clone the project
git clone https://github.com/Gwali-1/PY_CHANNELS_ASYNC
cd PY_CHANNELS_ASYNC
Install dependencies
pipenv install --dev
Running tests From the project root
pipenv run pytest
Installing the package locally From the project root
pip install -e .
Metadata
Release files for pychanasync 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pychanasync-1.0.0.tar.gz | 9.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pychanasync-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 16.8 kB
Release files / pychanasync-1.0.0.tar.gz
| Download URL | pychanasync-1.0.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c63a2515f09241393bf1a32475022bb6d9f34ed82b27737d0123f5568ab9b60f
|
|
BLAKE2b-256 checksum How to use checksums |
7e4109be1df3be55c0d547273e0b4b947d5fed7bd891334284c6a72b2454a29f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2025.
Transparency logRelease files / pychanasync-1.0.0-py3-none-any.whl
| Download URL | pychanasync-1.0.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11ef3c501a9fe3e2708bcf47476291f4655d1cf74262d9ba402f0369123d80ab
|
|
BLAKE2b-256 checksum How to use checksums |
4a9b6fe8397ea7d8c86f7b3da16f2008d219d98359449811c3f25b4bf5376e54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 21, 2025.
Transparency log