Skip to main content

arraystream

Iterator-style transformations for numeric arrays, similar to itertools but optimized for array.array and buffer-protocol objects.

Overview

arraystream provides composable, allocation-aware transformations for numeric arrays, complementing arrayops which focuses on fast, Rust-backed numeric kernels.

Mental model: itertools, but for numeric arrays and memory buffers.

Where arrayops provides the execution engine (numeric kernels), arraystream provides the transformation language (structural & stream transforms).

Features

  • Operate on array.array and buffer-protocol objects
  • Favor zero-copy views where possible
  • Avoid Python scalar iteration
  • Small, predictable, and fast
  • Composes naturally with arrayops
  • No dependency on NumPy or Pandas

Installation

pip install arraystream

For development:

git clone https://github.com/eddiethedean/arraystream
cd arraystream
pip install -r requirements-dev.txt
maturin develop

Quick Start

import array
from arraystream import windowed, scan, diff

# Create an array
data = array.array('i', [1, 2, 3, 4, 5, 6, 7, 8])

# Sliding windows
for window in windowed(data, size=3):
    print(list(window))  # [1, 2, 3], [2, 3, 4], ...

# Differences between consecutive elements
diffs = diff(data)
print(list(diffs))  # [1, 1, 1, 1, 1, 1, 1]

# Prefix sum (scan)
prefix_sums = scan(data, op="sum")
print(list(prefix_sums))  # [1, 3, 6, 10, 15, 21, 28, 36]

Relationship to arrayops

arrayops arraystream
Numeric kernels Structural & stream transforms
In-place math Shape-changing operations
Minimal API Rich combinators
Low-level Expressive

arrayops acts as the execution engine
arraystream acts as the transformation language

API Categories

Structural Transforms

Operations that rearrange or expose structure without computing new values:

  • chunked(arr, size) - Return views of chunks
  • windowed(arr, size, step=1) - Sliding windows
  • take(arr, n) - First n elements (view)
  • drop(arr, n) - Skip first n elements (view)
  • interleave(a, b) - Interleave two arrays
  • repeat_each(arr, n) - Repeat each element n times

Numeric Stream Operations

Operations that compute new values:

  • scan(arr, op="sum") - Prefix reduce
  • diff(arr) - Differences between consecutive elements
  • pairwise(arr) - Return pairs of consecutive elements
  • clip(arr, min, max) - Clip values to range

Boolean & Index Operations

  • where(arr, predicate) - Filter elements by predicate
  • argwhere(arr) - Return indices where condition is true
  • mask(arr, mask_array) - Apply boolean mask

Grouping & Segmentation

  • run_length_encode(arr) - Run-length encoding
  • groupby_runs(arr) - Group consecutive equal elements
  • segment_by(arr, boundaries) - Split at boundary indices

Supported Types

Supports the same 10 typecodes as arrayops:

  • b - signed char
  • B - unsigned char
  • h - signed short
  • H - unsigned short
  • i - signed int
  • I - unsigned int
  • l - signed long
  • L - unsigned long
  • f - float
  • d - double

Performance

  • Structural operations: Python + buffer protocol (zero-copy views)
  • Numeric transforms: Rust (PyO3) for performance
  • Zero-copy wherever semantics allow
  • Explicit copies when safety or clarity requires them

Use Cases

  • Streaming numeric pipelines
  • Signal processing
  • Sensor data preprocessing
  • Embedded or constrained environments
  • ETL micro-kernels
  • Teaching numeric programming without NumPy

Development

# Run tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=arraystream --cov-report=html

# Format code
ruff format .

# Lint code
ruff check .

# Type checking
mypy arraystream tests

License

MIT License - see LICENSE file for details.

Acknowledgments

  • Built with PyO3 for Python-Rust interop
  • Built with maturin for packaging
  • Complements arrayops

Metadata

Release files for arraystream 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arraystream 0.1.0
File Size Uploaded
arraystream-0.1.0.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for arraystream 0.1.0
File Interpreter ABI Platform
arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl CPython 3.8 CPython 3.8 macOS 11.0+ ARM64 Details

Total release size: 268.5 kB

Release files / arraystream-0.1.0.tar.gz

Download URL arraystream-0.1.0.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e0318489dee852412302099ff63656c54bd635fd2df7a56e282f3787d0e89dd8
BLAKE2b-256 checksum
How to use checksums
7132cf9dd824c4831e3df3481908b1c37060073aca7026bb476bff6d1a16167a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Release files / arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl

Download URL arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
Size 247.6 kB
Tags CPython 3.8 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
abb2c03890773ba746f285eab90c84ada44efbb3cf122cab199fc82ddb857b1b
BLAKE2b-256 checksum
How to use checksums
42dcf95d04702594f5da83e95f0c6e082261423533a4f69b6cc80ee46c83dc45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.18

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page