Skip to main content

Zero-copy non-blocking pipe-like structure

Project description

streamview

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
  • BufferedIOBase compatible 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

Example

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"

Install

Production

pip install streamview

Development

git clone https://github.com/hpca-uji/streamview.git
cd streamview
pip install -e .

Documentation

Classes

  • 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, copy and deepcopy support.

    Extends: BufferedIOBase

    • __len__() -> int

      Number of views held in stream

    • nbytes -> int

      Number of bytes held in stream

    • views -> Iterable[memoryview]

      Peeking iterator over views

    • __getitem__(index) -> memoryview

      Peek a view from the stream

    • unreadview(v: memoryview) -> int

      Unread a view into the stream

    • readview() -> memoryview

      Read a view from stream

    • readviews() -> Iterable[memoryview]

      Read all views from stream

    • unwriteview() -> memoryview

      Unwrite a view from the stream

    • writeview(v: memoryview) -> int

      Write a view into the stream

    • writeviews(vs: Iterable[memoryview]) -> int

      Write many views into the stream

    • frombuffer(b: Buffer) -> Stream

      Construct a stream from a buffer

    • toview() -> memoryview

      Transform stream to contiguous view (may copy)

    • copy() -> Stream

      Shallow copy of stream

Functions

  • byteview(b: Buffer) -> memoryview

    Return a byte view of a buffer

Acknowledgments

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).

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

streamview-3.0.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

streamview-3.0.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file streamview-3.0.0.tar.gz.

File metadata

  • Download URL: streamview-3.0.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for streamview-3.0.0.tar.gz
Algorithm Hash digest
SHA256 b290b8e423f14f1950ed23d772a1e5b917750fd8e46d8e146784b1cb3e7921b6
MD5 8eaf6babe61641fcd44e02c40d3e4129
BLAKE2b-256 0de9adf67fe931106fd6e56b0fdbc2694789347312f6db1de937bec32b176b15

See more details on using hashes here.

File details

Details for the file streamview-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: streamview-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for streamview-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ff790c1ad41616d15cdcb1faec0ea4daeb2d23ad88e8d9883c572ea9d5411ad
MD5 3d3dc043cdfec49a1a30d7adb5b245c1
BLAKE2b-256 d26253e944b075b612a301f46d6ef44292e984d2ff1bff291010e019dbd216eb

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