Synchronous API Reference¶
Stream Processing¶
rivusio.sync.stream.SyncStream ¶
A synchronous stream of data that can be processed through a pipeline.
Provides the same functionality as AsyncStream but for synchronous operations. Supports batching, windowing, and error handling for sync data sources.
| ATTRIBUTE | DESCRIPTION |
|---|---|
source |
The iterator providing the data
|
config |
Stream processing configuration
|
metrics |
Optional metrics collector for monitoring
|
Example
def data_source():
for i in range(100):
yield {"value": i}
config = StreamConfig(window_size=timedelta(seconds=30))
stream = SyncStream(data_source(), config=config)
def process_window(items):
return [sum(item["value"] for item in items)]
for result in stream.process(process_window):
print(f"Window sum: {result[0]}")
Source code in src/rivusio/sync/stream.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
__enter__ ¶
__exit__ ¶
__init__ ¶
Initialize the stream with a data source and optional configuration.
Source code in src/rivusio/sync/stream.py
__iter__ ¶
close ¶
is_closed ¶
metrics_dict ¶
Get current metrics including buffer size.
Returns Dictionary containing metrics and buffer size
Source code in src/rivusio/sync/stream.py
process ¶
Process the stream through the provided pipeline.
Synchronous version of AsyncStream.process(). See AsyncStream.process() for detailed documentation.
| PARAMETER | DESCRIPTION |
|---|---|
pipe |
Pipeline to process data through
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
OutputType
|
Processed items/batches/windows depending on processing mode |
| RAISES | DESCRIPTION |
|---|---|
PipeError
|
If processing fails |
Exception
|
If pipe raises an unhandled exception |
Source code in src/rivusio/sync/stream.py
sliding_window ¶
Process items using sliding window.
Source code in src/rivusio/sync/stream.py
time_window ¶
Process items using time-based window.
Source code in src/rivusio/sync/stream.py
tumbling_window ¶
Process items using tumbling window.
Source code in src/rivusio/sync/stream.py
Pipeline Components¶
rivusio.sync.SyncBasePipe ¶
Bases: BasePipe[InputType, OutputType]
Base class for sync pipes.
Source code in src/rivusio/sync/pipeline.py
rivusio.sync.SyncPipeline ¶
Bases: SyncBasePipe[InputType, OutputType], PipelineMetricsMixin
Pipeline for composing sync pipes.
Source code in src/rivusio/sync/pipeline.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
__enter__ ¶
Initialize resources.
__exit__ ¶
__exit__(
exc_type: Optional[type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[types.TracebackType],
) -> None
Clean up resources.
Source code in src/rivusio/sync/pipeline.py
__getstate__ ¶
__init__ ¶
Initialize pipeline.
Source code in src/rivusio/sync/pipeline.py
__rshift__ ¶
Compose this pipeline with another pipe.
__setstate__ ¶
configure_parallel ¶
configure_parallel(
strategy: Union[ExecutionStrategy, str],
max_workers: Optional[int] = None,
chunk_size: int = 1000,
) -> None
Configure parallel execution.
Source code in src/rivusio/sync/pipeline.py
execute_conditional ¶
execute_conditional(
data: InputType, condition: Callable[[InputType], bool]
) -> Union[InputType, OutputType]
Execute pipeline only if condition is met.
Source code in src/rivusio/sync/pipeline.py
execute_parallel ¶
Execute the pipeline on multiple inputs in parallel.
Source code in src/rivusio/sync/pipeline.py
process ¶
Process data through all pipes in the pipeline.
Source code in src/rivusio/sync/pipeline.py
Parallel Execution¶
rivusio.sync.ProcessPoolStrategyHandler ¶
Bases: ExecutionStrategyHandler[T, R]
Process pool execution strategy.
Source code in src/rivusio/sync/parallel.py
__enter__ ¶
__exit__ ¶
__exit__(
exc_type: Optional[type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[types.TracebackType],
) -> None
Shutdown executor.
__init__ ¶
Initialize process pool executor.
Source code in src/rivusio/sync/parallel.py
execute ¶
Execute function on data using process pool.
Source code in src/rivusio/sync/parallel.py
rivusio.sync.ThreadPoolStrategyHandler ¶
Bases: ExecutionStrategyHandler[T, R]
Thread pool execution strategy.