Frame Streams implementation in Python
Project description
Frame Streams implementation in Python
Frame Streams is a lightweight, binary-clean protocol that allows for the transport of arbitrarily encoded data payload sequences with minimal framing overhead.
This package provides a pure Python implementation based on https://github.com/farsightsec/fstrm/.
Installation
This module can be installed from pypi website
pip install fstrm
Example
The example shows how to read raw data and decode-it with the fstrsm library.
import fstrm
import asyncio
def do_something(payload):
print(payload)
async def on_connect():
f = fstrm.FstrmCodec()
while data := await reader.read(f.pending_nb_bytes())
f.append(data=data)
# process the buffer and check if we have enough data
if f.process():
# a frame is complete, decode-it
ctrl, ct, payload = f.decode()
# data frame ?
if ctrl == fstrm.FSTRM_DATA_FRAME:
do_something(data=payload)
# or control frame for handshake ?
if ctrl == fstrm.FSTRM_CONTROL_READY:
accept = f.encode(ctrl=fstrm.FSTRM_CONTROL_ACCEPT, ct=[b"protobuf:dnstap.Dnstap"])
writer.write(accept)
await writer.drain()
# control frame ?
if ctrl == fstrm.FSTRM_CONTROL_START:
pass
# control frame ?
if ctrl == fstrm.FSTRM_CONTROL_STOP:
f.reset()
loop = asyncio.get_event_loop()
coro = asyncio.start_server(on_connect, '127.0.0.1', 8888, loop=loop)
server = loop.run_until_complete(coro)
loop.close()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fstrm-0.2.0.tar.gz
(4.1 kB
view hashes)
Built Distribution
fstrm-0.2.0-py3-none-any.whl
(4.5 kB
view hashes)