| Name | pychanasync JSON |
| Version |
1.0.0
JSON |
| download |
| home_page | None |
| Summary | 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. |
| upload_time | 2025-10-21 22:31:50 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.11 |
| license | MIT |
| keywords |
async
channel
concurrency
non-blocking
python
asyncio
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
[](https://github.com/Gwali-1/PY_CHANNELS_ASYNC/actions/workflows/test-and-lint.yml)
# 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](https://gwali-1.github.io/PY_CHANNELS_ASYNC/) 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 for` loops._
- **Context manager support** - _close channels and release resources when done with `async with`._
- **Blocking/ awaitable operations** - _`await chan.push(value)` and `await chan.pull()`
for safe, cooperative communication._
- **Non-blocking operations** - _`chan.push_nowait(value)` and `chan.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](https://pypi.org/project/pychanasync/)
```shell
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.
```python
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.
```python
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
```python
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
```python
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**
```python
chan, value = await chanselect(
(chan_a, chan_a.pull()),
(chan_b, chan_b.pull())
)
```
checkout more [features](https://gwali-1.github.io/PY_CHANNELS_ASYNC/#features)
## Basic consumer-producer example
```python
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](https://github.com/Gwali-1/PY_CHANNELS_ASYNC)
**Clone the project**
```shell
git clone https://github.com/Gwali-1/PY_CHANNELS_ASYNC
cd PY_CHANNELS_ASYNC
```
**Install dependencies**
```shell
pipenv install --dev
```
**Running tests**
From the project root
```shell
pipenv run pytest
```
**Installing the package locally**
From the project root
```shell
pip install -e .
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pychanasync",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "async, channel, concurrency, non-blocking, python, asyncio",
"author": null,
"author_email": "Gwalisam Matthew <gwalisammatthew2@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/7e/41/09be1df3be55c0d547273e0b4b947d5fed7bd891334284c6a72b2454a29f/pychanasync-1.0.0.tar.gz",
"platform": null,
"description": "[](https://github.com/Gwali-1/PY_CHANNELS_ASYNC/actions/workflows/test-and-lint.yml)\n\n# Pychanasync\n\n`pychanasync` is a lightweight python package which brings _Go-style_ channels to\npython's _asyncio_ concurrency world. It is an async-channel implementation,\nproviding a channel shaped tool for channel shaped problems.\n\n`pychanasync` is implemented entirely around pythons asyncio event loop.\nThe implementation is **lock free** ,taking advantage of the _single threaded\ncooperative_ concurrency model.\n\nIt is designed and implemented to work with coroutines and **not threads**, providing\nsafe and deterministic communication patterns without blocking the event loop.\n\nVisit [documentation](https://gwali-1.github.io/PY_CHANNELS_ASYNC/) site for more details.\n\n## Features\n\n- **Buffered and unbuffered channel semantics** - _use either synchronous or buffered communication_\n- **Async iteration over channels** - _Consume messages from a channel using `async for` loops._\n- **Context manager support** - _close channels and release resources when done with `async with`._\n- **Blocking/ awaitable operations** - _`await chan.push(value)` and `await chan.pull()`\n for safe, cooperative communication._\n- **Non-blocking operations** - _`chan.push_nowait(value)` and `chan.pull_nowait()` for buffered channels when you don\u2019t want to suspend._\n- **Select-like utility** - _wait on multiple channel operations concurrently, similar to Go\u2019s select statement, in a clean and Pythonic way_\n\n## Installation\n\npychanasync is available on [PyPi](https://pypi.org/project/pychanasync/)\n\n```shell\npip install pychanasync\n```\n\n## Quickstart\n\nChannels can be both **buffered** and **unbuffered**.\n\n**unbuffered** channels have no internal buffer capacity. What this means is\nevery producer (`push`) will block/suspend until there is a ready consumer on\nthe other end of the channel (`pull`) and every consumer until there is a\nready producer on the other end of the channel.\n\n```python\nfrom pychanasync import channel\n\n#create unbuffered channel\nch = Channel()\n\n# send\nasync ch.push(\"item\") #blocks here\n\n# receive\nvalue = async ch.pull()\n\n```\n\n**buffered** channels have an internal buffer capacity and can hold (**N**)\nnumber of items at a time. When doing a `push` into a buffered channel, the\noperation will only block when the buffer is full and until there is available\nspace to send the new item. Other than that the operation completes\nand returns quickly.\n\nBelow is a buffered channel that can hold 300 items at a time.\n\n```python\nfrom pychanasync import channel\n\nch = Channel(buffer=300)\n\n# send\nasync ch.push(\"item\")\n\n# receive\nvalue = async ch.pull()\n\n```\n\n### Async Iteration\n\npychanasync supports async iteration, allowing you to consume items from a channel\nin a clean way using `async for loop`.\n\nWe can rewrite our consumer above as\n\n```python\n\nasync def consumer(ch):\n async for msg in ch:\n print(f\"Received: {msg}\")\n\n```\n\nOnce the producer closes the channel , the iteration ends .\n\n### Context manager support\n\npychanasync has support for asynchronous context managers for automatic cleanup.\n\nWe can rewrite out producer component as\n\n```python\nasync def producer(channel):\n async with channel as ch:\n for i in range(3):\n await ch.push(f\"msg {i}\")\n print(f\"Sent msg {i}\")\n\n```\n\nWhen the `async-with` block exits , the channel is closed automatically.\n\n### Chanselect\n\nThe `chanselect` utility method allows you to start and wait on multiple channel operations simultaneously,\nreturning the one that completes first.\n\n**synthax**\n\n```python\n\n chan, value = await chanselect(\n (chan_a, chan_a.pull()),\n (chan_b, chan_b.pull())\n )\n\n```\n\ncheckout more [features](https://gwali-1.github.io/PY_CHANNELS_ASYNC/#features)\n\n## Basic consumer-producer example\n\n```python\n\nimport asyncio\nfrom pychanasync import Channel\n\nasync def producer(ch):\n for i in range(3):\n await ch.push(f\"msg {i}\")\n print(f\"Sent msg {i}\")\n ch.close() # gracefully close when done\n\nasync def consumer(ch):\n while True:\n try:\n msg = await ch.pull()\n print(f\"Received {msg}\")\n except Channel.Closed:\n break\n\nasync def main():\n ch = Channel(buffer=2)\n await asyncio.gather(producer(ch), consumer(ch))\n\nasyncio.run(main())\n\n```\n\n### Contributing\n\nTo contribute or set up the project locally.\n\nfind the project source code on [github](https://github.com/Gwali-1/PY_CHANNELS_ASYNC)\n\n**Clone the project**\n\n```shell\ngit clone https://github.com/Gwali-1/PY_CHANNELS_ASYNC\ncd PY_CHANNELS_ASYNC\n```\n\n**Install dependencies**\n\n```shell\npipenv install --dev\n\n```\n\n**Running tests**\nFrom the project root\n\n```shell\n\npipenv run pytest\n```\n\n**Installing the package locally**\nFrom the project root\n\n```shell\npip install -e .\n\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "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.",
"version": "1.0.0",
"project_urls": {
"Issues": "https://github.com/Gwali-1/PY_CHANNELS_ASYNC/issues",
"documentation": "https://gwali-1.github.io/PY_CHANNELS_ASYNC",
"homepage": "https://gwali-1.github.io/PY_CHANNELS_ASYNC",
"repository": "https://github.com/Gwali-1/PY_CHANNELS_ASYNC"
},
"split_keywords": [
"async",
" channel",
" concurrency",
" non-blocking",
" python",
" asyncio"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4a9b6fe8397ea7d8c86f7b3da16f2008d219d98359449811c3f25b4bf5376e54",
"md5": "a9ce6927dd624ee7f23171c7709a8706",
"sha256": "11ef3c501a9fe3e2708bcf47476291f4655d1cf74262d9ba402f0369123d80ab"
},
"downloads": -1,
"filename": "pychanasync-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a9ce6927dd624ee7f23171c7709a8706",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 7721,
"upload_time": "2025-10-21T22:31:48",
"upload_time_iso_8601": "2025-10-21T22:31:48.853876Z",
"url": "https://files.pythonhosted.org/packages/4a/9b/6fe8397ea7d8c86f7b3da16f2008d219d98359449811c3f25b4bf5376e54/pychanasync-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "7e4109be1df3be55c0d547273e0b4b947d5fed7bd891334284c6a72b2454a29f",
"md5": "7fc839a365d93a590ace483749b7499e",
"sha256": "c63a2515f09241393bf1a32475022bb6d9f34ed82b27737d0123f5568ab9b60f"
},
"downloads": -1,
"filename": "pychanasync-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "7fc839a365d93a590ace483749b7499e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 9049,
"upload_time": "2025-10-21T22:31:50",
"upload_time_iso_8601": "2025-10-21T22:31:50.146275Z",
"url": "https://files.pythonhosted.org/packages/7e/41/09be1df3be55c0d547273e0b4b947d5fed7bd891334284c6a72b2454a29f/pychanasync-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-21 22:31:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Gwali-1",
"github_project": "PY_CHANNELS_ASYNC",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pychanasync"
}