Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aratz-lasa/async-multiplexer
Python Asyncio TCP multiplexer
https://github.com/aratz-lasa/async-multiplexer
asyncio mplex multiplexer python stream tcp
Last synced: about 2 months ago
JSON representation
Python Asyncio TCP multiplexer
- Host: GitHub
- URL: https://github.com/aratz-lasa/async-multiplexer
- Owner: aratz-lasa
- License: mit
- Created: 2020-04-30T00:50:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-20T19:50:15.000Z (over 3 years ago)
- Last Synced: 2024-10-10T22:52:04.254Z (2 months ago)
- Topics: asyncio, mplex, multiplexer, python, stream, tcp
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# async_multiplexer
[![PyPI version](https://badge.fury.io/py/async-multiplexer.svg)](https://badge.fury.io/py/async-multiplexer)
[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)
[![Build Status](https://travis-ci.com/aratz-lasa/async-multiplexer.svg?branch=master)](https://travis-ci.com/aratz-lasa/async-multiplexer)
[![codecov](https://codecov.io/gh/aratz-lasa/async-multiplexer/branch/master/graph/badge.svg)](https://codecov.io/gh/aratz-lasa/async-multiplexer)[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/)
[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)**async_multiplexer** is a TCP Multiplexer based on [Mplex](https://github.com/libp2p/specs/tree/master/mplex) protocol, but simplified.
It is intended for creating mutiple streams in parallel
on top of a same TCP connection.## Installation
```bash
pip install async-multiplexer
```## Usage
### Client
```python
import asyncio
from async_multiplexer import open_multiplexer_contextasync def echo_client():
async with open_multiplexer_context("127.0.0.1", 7777) as multiplexer:
stream_echo_1 = await multiplexer.multiplex("echo.1")
stream_echo_2 = await multiplexer.multiplex("echo.2")
await stream_echo_1.write(b"echo.1")
await stream_echo_2.write(b"echo.2")if __name__ == "__main__":
asyncio.run(echo_client())
```### Server
```python
import asyncio
from async_multiplexer import bind_multiplex_listener_contextasync def handler(stream):
data = await stream.read()
print(data)async def echo_server():
async with bind_multiplex_listener_context("127.0.0.1", 7777) as listener:
listener.set_handler("echo.1", handler)
listener.set_handler("echo.2", handler)
await asyncio.sleep(10)if __name__ == "__main__":
asyncio.run(echo_server())
```