Metadata-Version: 2.4
Name: streamframer
Version: 0.0.1
Summary: Small framing primitives for byte streams: buffering, delimiter rules, and zero-copy frame views.
Project-URL: Homepage, https://github.com/Kimu754/streamframer
Project-URL: Issues, https://github.com/Kimu754/streamframer/issues
Author: Kerim Takouti
License: MIT License
        
        Copyright (c) 2025 Kerim Takouti
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: buffer,framing,protocol,socket,tcp
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: System :: Networking
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# 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

```python
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.