Context & layout¶
The proxies importable from interactive_pipe for sharing state and controlling the display — see the Context & events and Layout guides for usage patterns.
get_context
¶
get_context() -> Dict[str, Any]
Get shared context for passing data between filters.
This returns a simple dictionary for user-defined state only. Framework internals (keys starting with __) are not accessible here.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A shared dictionary for user-defined state. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of pipeline execution. |
Example
# In filter A
@interactive(threshold=(0.5, [0.0, 1.0]))
def detect_objects(img, threshold=0.5):
objects = find_objects(img, threshold)
ctx = get_context()
ctx["detected_objects"] = objects
ctx["detection_count"] = len(objects)
return img_with_boxes
# In filter B (runs after A)
@interactive()
def analyze_objects(img):
ctx = get_context()
objects = ctx.get("detected_objects", [])
count = ctx.get("detection_count", 0)
layout.style("analysis", title=f"Found {count} objects")
return analysis_result
Source code in src/interactive_pipe/core/context.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
_ContextProxy
¶
Proxy object for direct dict-like access to user context.
This allows using context["key"] or context.key directly instead of ctx = get_context(); ctx["key"].
Example
from interactive_pipe import context
@interactive()
def my_filter(img):
# Direct dict-style access
context["my_data"] = value
other_data = context.get("other_key", default)
# Or attribute-style access
context.my_data = value
other_data = context.other_key
return img
Source code in src/interactive_pipe/core/context.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
__getitem__
¶
__getitem__(key: str) -> Any
Get item from context using dict-style access.
Source code in src/interactive_pipe/core/context.py
361 362 363 | |
__setitem__
¶
__setitem__(key: str, value: Any) -> None
Set item in context using dict-style access.
Source code in src/interactive_pipe/core/context.py
365 366 367 | |
__getattr__
¶
__getattr__(name: str) -> Any
Get item from context using attribute-style access.
Source code in src/interactive_pipe/core/context.py
369 370 371 372 373 374 | |
__setattr__
¶
__setattr__(name: str, value: Any) -> None
Set item in context using attribute-style access.
Source code in src/interactive_pipe/core/context.py
376 377 378 | |
__delitem__
¶
__delitem__(key: str) -> None
Delete item from context.
Source code in src/interactive_pipe/core/context.py
380 381 382 | |
__contains__
¶
__contains__(key: str) -> bool
Check if key exists in context.
Source code in src/interactive_pipe/core/context.py
384 385 386 | |
get
¶
get(key: str, default: Any = None) -> Any
Get item from context with default value.
Source code in src/interactive_pipe/core/context.py
388 389 390 | |
setdefault
¶
setdefault(key: str, default: Any = None) -> Any
Set default value if key doesn't exist.
Source code in src/interactive_pipe/core/context.py
392 393 394 | |
pop
¶
pop(key: str, *args) -> Any
Pop item from context.
Source code in src/interactive_pipe/core/context.py
396 397 398 | |
keys
¶
keys()
Get context keys.
Source code in src/interactive_pipe/core/context.py
400 401 402 | |
values
¶
values()
Get context values.
Source code in src/interactive_pipe/core/context.py
404 405 406 | |
items
¶
items()
Get context items.
Source code in src/interactive_pipe/core/context.py
408 409 410 | |
update
¶
update(*args, **kwargs) -> None
Update context with dict or kwargs.
Source code in src/interactive_pipe/core/context.py
412 413 414 | |
clear
¶
clear() -> None
Clear context.
Source code in src/interactive_pipe/core/context.py
416 417 418 | |
__repr__
¶
__repr__() -> str
String representation.
Source code in src/interactive_pipe/core/context.py
420 421 422 423 424 425 | |
_LayoutProxy
¶
Proxy for display and layout operations using contextvars.
This class provides a clean API for controlling output display properties and grid arrangements without polluting function signatures.
Available methods
- style(): Set display properties (title, colormap, etc.)
- grid(): Set the output grid layout
- row(): Convenience for single-row layout
Source code in src/interactive_pipe/core/context.py
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 | |
style
¶
style(name: str, *, title: Optional[str] = None, **style_kwargs: Any) -> None
Set display properties for an output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Output variable name (must match the variable name in the return statement) |
required |
title
|
Optional[str]
|
Display title for the output |
None
|
**style_kwargs
|
Any
|
Additional style properties (colormap, vmin, vmax, etc.) |
{}
|
Example
layout.style("processed", title=f"Brightness: {brightness:.2f}")
layout.style("heatmap", title="Heat Map", colormap="viridis", vmin=0, vmax=1)
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
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 | |
grid
¶
grid(arrangement: Union[List[str], List[List[str]]]) -> None
Set the output grid layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arrangement
|
Union[List[str], List[List[str]]]
|
Either a flat list of output names (treated as a single row) or a 2D list of output names defining the grid arrangement |
required |
Example
# Single row (flat list)
layout.grid(["img1", "img2", "img3"])
# Single row (nested list - equivalent to above)
layout.grid([["img1", "img2", "img3"]])
# 2x2 grid
layout.grid([
["original", "processed"],
["histogram", "stats"]
])
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
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 | |
row
¶
row(outputs: List[str]) -> None
Convenience method for single-row layout.
This is equivalent to calling grid([outputs]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outputs
|
List[str]
|
List of output names to display in a single row |
required |
Example
layout.row(["original", "filtered", "result"])
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
_AudioProxy
¶
Proxy for audio playback control using contextvars.
This class provides a clean API for controlling audio playback without polluting function signatures with global_params.
Source code in src/interactive_pipe/core/context.py
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 212 213 214 215 216 217 218 219 220 221 222 223 | |
set
¶
set(audio_path: str) -> None
Set the audio file to play.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio_path
|
str
|
Path to the audio file |
required |
Example
audio.set("path/to/track.mp3")
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
play
¶
play() -> None
Start audio playback.
Example
audio.play()
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
183 184 185 186 187 188 189 190 191 192 193 194 195 | |
pause
¶
pause() -> None
Pause audio playback.
Example
audio.pause()
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
197 198 199 200 201 202 203 204 205 206 207 208 209 | |
stop
¶
stop() -> None
Stop audio playback.
Example
audio.stop()
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
211 212 213 214 215 216 217 218 219 220 221 222 223 | |
_EventsProxy
¶
Read-only proxy for key-bound context events.
GUI backends raise an event flag when a key registered through InteractivePipeGUI.bind_key_to_context is pressed; filters read the flags here. An event stays True only for the single pipeline run triggered by the key press - the GUI resets it right after.
Example
from interactive_pipe import events, interactive
@interactive()
def denoise(img):
strength = 0.5 if events.get("boost_denoise") else 0.1
return smooth(img, strength)
Prefer events.get(name): it returns False for events that were never bound, so the same filter also runs headless or in a GUI without the key binding.
Source code in src/interactive_pipe/core/context.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
__getitem__
¶
__getitem__(name: str) -> bool
Strict access: raises KeyError if the event was never bound.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
254 255 256 257 258 259 260 | |
get
¶
get(name: str, default: bool = False) -> bool
Return the event flag, or default when the event is not bound.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If called outside of filter execution context. |
Source code in src/interactive_pipe/core/context.py
262 263 264 265 266 267 268 | |
__contains__
¶
__contains__(name: str) -> bool
Check whether an event name is bound.
Source code in src/interactive_pipe/core/context.py
270 271 272 | |
keys
¶
keys()
Names of all bound events.
Source code in src/interactive_pipe/core/context.py
274 275 276 | |
Backend
¶
Bases: str, Enum
Supported GUI backends for interactive pipelines.
Source code in src/interactive_pipe/core/backend.py
4 5 6 7 8 9 10 11 12 | |
FilterError
¶
Bases: Exception
Clean, user-friendly exception for filter errors.
Displays only the relevant error information without the full framework traceback, making it easier to identify issues in user code.
Source code in src/interactive_pipe/core/engine.py
13 14 15 16 17 18 19 20 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 | |
print_compact
¶
print_compact(file=None)
Print a compact version of the error to stderr or specified file.
Source code in src/interactive_pipe/core/engine.py
68 69 70 71 72 73 74 75 76 | |