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.
Metadata
Release files for streamframer 0.0.2
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 |
|---|---|---|---|---|
| streamframer-0.0.2.tar.gz | 11.1 kB | Without provenance | Details for streamframer-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamframer-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for streamframer-0.0.2-py3-none-any.whl |
Total release size: 19.1 kB
Release files / streamframer-0.0.2.tar.gz
| Download URL | streamframer-0.0.2.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f359624b0fccce73fb4e110286a04620a2c85df8ed8985911754190abfc244eb
|
|
BLAKE2b-256 checksum How to use checksums |
345aac2a5987b69d68e7afc79208dddfda64b84e07e62c39d40a25c2ebac5775
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / streamframer-0.0.2-py3-none-any.whl
| Download URL | streamframer-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b87957bdf061ad6cfbc2df15bd8c3d8e2b5256aac5ba2d4d5f14e0708054de72
|
|
BLAKE2b-256 checksum How to use checksums |
7d429fcf60bb3f85c5402c91cc0242b4ed46489c148b2807b6f2ab0bfe594df3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for streamframer 0.0.2
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.