Small framing primitives for byte streams: buffering, delimiter rules, and zero-copy frame views.
Project description
streamframer
Small, low-level framing primitives for byte streams.
This library provides:
- persistent buffering for stream-oriented I/O (e.g. TCP sockets)
- delimiter-based framing rules
- zero-copy frame views with explicit consumption
It is designed for instrument protocols and other byte streams where messages may span multiple recv() calls.
⚠️ Status: Pre-alpha. API is not yet stable.
Design Goals
- No protocol assumptions
- No background threads
- No hidden buffering
- Zero-copy access to payloads
- Explicit lifecycle control
This is not a full protocol library.
It only solves buffering and framing.
Core Concepts
BufferManager
Owns a single byte buffer and scan position.
Bytes persist across reads until explicitly consumed.
Framing Rules
A rule inspects (buffer, scan_position) and decides:
- whether a complete message exists
- where scanning should resume
- how many bytes belong to the message
Rules may minimize unnecessary rescanning when possible, but no protocol-level guarantees are made.
Included helpers:
until_delim(b"...")until_eot(byte)
Frame
A zero-copy memoryview into the buffer.
Bytes are removed only when Frame.consume() is explicitly called.
While a Frame exists, the underlying buffer must not be mutated.
Important Notes
- Rule selection is the caller’s responsibility.
- Trying multiple rules sequentially (e.g. newline first, then EOT) can cause protocol misclassification if payloads contain overlapping delimiters.
- This library does not attempt to detect or resolve such ambiguities.
Minimal Example
from streamframer import BufferManager, until_delim, read_with_rule
import socket
sock = socket.create_connection(("127.0.0.1", 1234))
mgr = BufferManager()
rule = until_delim(b"\n")
while True:
frame = read_with_rule(sock, mgr, rule)
if frame is None:
continue
data = bytes(frame)
frame.consume()
print(data)
Non-Goals
- No protocol detection
- No message validation
- No concurrency abstractions
If you need a full protocol stack, this library is not for you.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamframer-0.0.1.tar.gz.
File metadata
- Download URL: streamframer-0.0.1.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e114fe2e9aef78fdee2ef70c7374c50c13a4be68c4aacfcd3840603255c1c82d
|
|
| MD5 |
b649c30d9a7ab17ff01cda3d9131e697
|
|
| BLAKE2b-256 |
5171f58f8cc15fd5882f15320996d150c9da68cb658b7bea75449a437ff021ec
|
File details
Details for the file streamframer-0.0.1-py3-none-any.whl.
File metadata
- Download URL: streamframer-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47acd01a11947cae3b8954bcf3ea4fc70e516e34d81309839fe0ae800d0ca61e
|
|
| MD5 |
a40c9c9bcfebeafced4db649b34e78dc
|
|
| BLAKE2b-256 |
19af89ce771c99ed0410b9a196c722f1d905a2fa31548aebdb5df209a248f49f
|