Iterator-style transformations for numeric arrays, similar to itertools but for array.array
Project description
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.arrayand 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 chunkswindowed(arr, size, step=1)- Sliding windowstake(arr, n)- First n elements (view)drop(arr, n)- Skip first n elements (view)interleave(a, b)- Interleave two arraysrepeat_each(arr, n)- Repeat each element n times
Numeric Stream Operations
Operations that compute new values:
scan(arr, op="sum")- Prefix reducediff(arr)- Differences between consecutive elementspairwise(arr)- Return pairs of consecutive elementsclip(arr, min, max)- Clip values to range
Boolean & Index Operations
where(arr, predicate)- Filter elements by predicateargwhere(arr)- Return indices where condition is truemask(arr, mask_array)- Apply boolean mask
Grouping & Segmentation
run_length_encode(arr)- Run-length encodinggroupby_runs(arr)- Group consecutive equal elementssegment_by(arr, boundaries)- Split at boundary indices
Supported Types
Supports the same 10 typecodes as arrayops:
b- signed charB- unsigned charh- signed shortH- unsigned shorti- signed intI- unsigned intl- signed longL- unsigned longf- floatd- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arraystream-0.1.0.tar.gz.
File metadata
- Download URL: arraystream-0.1.0.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0318489dee852412302099ff63656c54bd635fd2df7a56e282f3787d0e89dd8
|
|
| MD5 |
45875be21bca06de5f9d2ed7a8a5f84d
|
|
| BLAKE2b-256 |
7132cf9dd824c4831e3df3481908b1c37060073aca7026bb476bff6d1a16167a
|
File details
Details for the file arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl.
File metadata
- Download URL: arraystream-0.1.0-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 247.6 kB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abb2c03890773ba746f285eab90c84ada44efbb3cf122cab199fc82ddb857b1b
|
|
| MD5 |
3f9120ca8ef0c8b82c6da1ed0075e92d
|
|
| BLAKE2b-256 |
42dcf95d04702594f5da83e95f0c6e082261423533a4f69b6cc80ee46c83dc45
|