message-channel
This library provides a message channel object which subtract particular messages from mass of messages. It's like group by of SQL or ReactiveX but for asynchronous reader.
Installation
pip install python-message-channel
Usage
For example, assume that you have a string stream which messages are prefixed by a, b, ... e and you'd like to split subchannels for messages prefixed by b or d like below.
=============================================
---------------------------------> a:foo
--------------------+
--------------------|------------> c:foo
--------------------|------------> d:foo
--------------------|------------> e:foo
====================|========================
channel |
=|========================
+------------> b:foo
==========================
subchannel `m.startswith('b')`
This library is a tool for handling such situation.
First, create a Channel instance from a steram reader and you can receive messages by
channel.recv() method.
In this example, we use asyncio.Queue as a stream.
import asyncio
from message_channel import Channel
async def main():
# Create original stream
stream = asyncio.Queue()
# Create stream reader
async def reader():
return await stream.get()
# Create stream channel
async with Channel(reader) as channel:
stream.put_nowait('a:foo')
stream.put_nowait('b:foo')
stream.put_nowait('c:foo')
stream.put_nowait('d:foo')
stream.put_nowait('e:foo')
assert (await channel.recv()) == 'a:foo'
assert (await channel.recv()) == 'b:foo'
assert (await channel.recv()) == 'c:foo'
assert (await channel.recv()) == 'd:foo'
assert (await channel.recv()) == 'e:foo'
if __name__ == '__main__':
asyncio.run(main())
And you can split the channel by channel.split() method by a predicator like
async with Channel(reader) as channel:
def predicator(m):
return m.startswith('b:')
async with channel.split(predicator) as sub:
stream.put_nowait('a:foo')
stream.put_nowait('b:foo')
stream.put_nowait('c:foo')
stream.put_nowait('d:foo')
stream.put_nowait('e:foo')
# sub receive messages starts from 'b:'
assert (await sub.recv()) == 'b:foo'
# channel (original) receive messages other than above
assert (await channel.recv()) == 'a:foo'
assert (await channel.recv()) == 'c:foo'
assert (await channel.recv()) == 'd:foo'
assert (await channel.recv()) == 'e:foo'
API documentation
https://fixpoint.github.io/python-message-channel/
powered by pdoc.
License
Distributed under the terms of the MIT License
Metadata
Release files for python-message-channel 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python-message-channel-0.2.3.tar.gz | 5.5 kB | Without provenance | Details for python-message-channel-0.2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_message_channel-0.2.3-py3-none-any.whl | Python 3 | none | any | Details for python_message_channel-0.2.3-py3-none-any.whl |
Total release size: 11.2 kB
Release files / python-message-channel-0.2.3.tar.gz
| Download URL | python-message-channel-0.2.3.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2fc6a060a601823b6f338f9201d377f2629937de71c3856b9c956ffd9a745426
|
|
BLAKE2b-256 checksum How to use checksums |
632c294d8ec1c88ecf8094e97de96fb86d1846817ae736c173c21861cb0e0b4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.1 Linux/5.4.0-1036-azure
|
Release files / python_message_channel-0.2.3-py3-none-any.whl
| Download URL | python_message_channel-0.2.3-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a466caf4c295d9f25a6550ef6d4f6cb8541933f65e0dcd26e7d16b17e4efa7c
|
|
BLAKE2b-256 checksum How to use checksums |
4f3450c42fb8ad637da75c264eaa2c7268c246d93c923659eb19e57fcb3fd03d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.4 CPython/3.9.1 Linux/5.4.0-1036-azure
|
Security for python-message-channel 0.2.3
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.