Zero-copy non-blocking pipe-like structure
Stream primitive extending Python's standard I/O model with zero-copy and scatter/gather semantics.
- Zero-copy operations using
memoryview BufferedIOBasecompatible API- Non-blocking I/O semantics
- Compatible with existing Python I/O tooling and libraries
- Efficient handling of fragmented buffers without unnecessary copies
- Explicit ownership transfer of buffers
- Lightweight stream copies with shared underlying buffers
- Supports both high-level I/O usage and low-level buffer access
- Lightweight and dependency-free
- Designed for high-throughput data pipelines
from streamview import Stream
stream = Stream()
stream.write(b"hello")
stream.write(b"world")
print(stream)
# <Stream views=2 nbytes=10>
print(bytes(stream.read()))
# b"helloworld"pip install streamviewgit clone https://github.com/hpca-uji/streamview.git
cd streamview
pip install -e .-
Stream()Zero-copy non-blocking pipe-like
Interface mimics a non-blocking BufferedIOBase, but operations return memoryviews instead of bytes.
Operations consume the stream. Operations are not thread-safe. Reader is responsible of releasing views. Writer hands off responsibility over views.
Stream has
with,bytes,bool,copyanddeepcopysupport.Extends:
BufferedIOBase-
__len__() -> intNumber of views held in stream
-
nbytes -> intNumber of bytes held in stream
-
views -> Iterable[memoryview]Peeking iterator over views
-
__getitem__(index) -> memoryviewPeek a view from the stream
-
unreadview(v: memoryview) -> intUnread a view into the stream
-
readview() -> memoryviewRead a view from stream
-
readviews() -> Iterable[memoryview]Read all views from stream
-
unwriteview() -> memoryviewUnwrite a view from the stream
-
writeview(v: memoryview) -> intWrite a view into the stream
-
writeviews(vs: Iterable[memoryview]) -> intWrite many views into the stream
-
frombuffer(b: Buffer) -> StreamConstruct a stream from a buffer
-
toview() -> memoryviewTransform stream to contiguous view (may copy)
-
copy() -> StreamShallow copy of stream
-
-
byteview(b: Buffer) -> memoryviewReturn a byte view of a buffer
The library has been partially supported by:
- Project PID2023-146569NB-C22 "Inteligencia sostenible en el Borde-UJI" funded by the Spanish Ministry of Science, Innovation and Universities.
- Project C121/23 Convenio "CIBERseguridad post-Cuántica para el Aprendizaje FEderado en procesadores de bajo consumo y aceleradores (CIBER-CAFE)" funded by the Spanish National Cybersecurity Institute (INCIBE).
