Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamframer-0.0.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

streamframer-0.0.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file streamframer-0.0.2.tar.gz.

File metadata

  • Download URL: streamframer-0.0.2.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

Hashes for streamframer-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f359624b0fccce73fb4e110286a04620a2c85df8ed8985911754190abfc244eb
MD5 e3b61667b05eb33f5c5d1e7a41a1b0a6
BLAKE2b-256 345aac2a5987b69d68e7afc79208dddfda64b84e07e62c39d40a25c2ebac5775

See more details on using hashes here.

File details

Details for the file streamframer-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: streamframer-0.0.2-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

Hashes for streamframer-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b87957bdf061ad6cfbc2df15bd8c3d8e2b5256aac5ba2d4d5f14e0708054de72
MD5 228451ab1ad02b1a5d87465fd74e222b
BLAKE2b-256 7d429fcf60bb3f85c5402c91cc0242b4ed46489c148b2807b6f2ab0bfe594df3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page