Streamerate

raw JSON →
1.2.11 verified Sat May 09 auth: no python

streamerate is a fluent and expressive Python library for chainable iterable processing, inspired by Java 8 streams. It provides lazy evaluation, parallel execution options, and a rich set of operations. Current version 1.2.11 requires Python >=3.10 and <4.0. It is actively maintained on GitHub.

pip install streamerate
error ImportError: cannot import name 'stream' from 'streamerate'
cause Old import path 'from streamerate.streams import stream' no longer works.
fix
Use 'from streamerate import stream'.
error ValueError: This stream can only be operated upon once
cause A terminal operation was called on a stream that has already been consumed.
fix
Do not reuse the same stream after a terminal operation; create a new stream if needed.
error TypeError: stream() got an unexpected keyword argument 'parallel'
cause The parallel parameter in stream() constructor was removed in later versions.
fix
Remove the parallel argument and use .parallel() method on the stream.
breaking If you import from 'streamerate.streams' (old import), the module no longer exists. All public API is now under 'streamerate' directly.
fix Change 'from streamerate.streams import stream' to 'from streamerate import stream'.
gotcha stream operations are lazy: they are not executed until a terminal operation (like to_list(), count(), etc.) is called. Repeated terminal operations on the same stream will raise a ValueError because the stream can only be operated upon once.
fix Store the terminal result and reuse it, or recreate the stream.
deprecated The 'parallel' parameter in stream() is deprecated in favor of explicit parallel operations like .parallel() method.
fix Use .parallel() on the stream instead of passing parallel=True to stream().

Creates a stream from a list, filters elements greater than 2, maps each to double, and collects to a list.

from streamerate import stream

# Create a stream from a list and apply operations
result = stream([1, 2, 3, 4, 5])\
    .filter(lambda x: x > 2)\
    .map(lambda x: x * 2)\
    .to_list()
print(result)  # [6, 8, 10]