Runtime¶
runtime ¶
Runtime package for deckui device sessions and events.
AsyncHandler
module-attribute
¶
Type alias for an async callback that accepts any arguments and returns None.
DeckEvent
module-attribute
¶
Union type of all events that can be received from a Stream Deck device.
AsyncEvent ¶
A multicast async event that can have multiple subscribers.
Subscribers are async callables registered via :meth:subscribe
or by using the event itself as a decorator. :meth:emit invokes
every registered subscriber sequentially, awaiting each one in
registration order.
The handler list is snapshotted at the start of every :meth:emit,
so subscribers may safely register or unregister during dispatch
without affecting the in-flight emission.
The signature of an event is part of its documented contract, not its static type — events here are intentionally non-generic so they can carry arbitrary positional/keyword payloads.
Examples:
::
on_volume_changed = AsyncEvent()
@on_volume_changed
async def _log(value: int) -> None:
print(f"volume = {value}")
await on_volume_changed.emit(75)
Source code in src/deckui/runtime/async_event.py
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 | |
subscribe ¶
Register handler as a subscriber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
_H
|
Async callable to invoke on every :meth: |
required |
Returns:
| Type | Description |
|---|---|
handler
|
The original handler, unchanged, so this can be used as a decorator. |
Source code in src/deckui/runtime/async_event.py
unsubscribe ¶
Remove handler from the subscriber list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
AsyncHandler
|
A previously-registered subscriber. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If handler is not currently subscribed. |
Source code in src/deckui/runtime/async_event.py
__call__ ¶
Decorator alias for :meth:subscribe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
_H
|
Async callable to register. |
required |
Returns:
| Type | Description |
|---|---|
handler
|
The original handler. |
Source code in src/deckui/runtime/async_event.py
emit
async
¶
Invoke every subscriber sequentially, awaiting each in turn.
A snapshot of the handler list is taken first, so handlers may subscribe or unsubscribe during dispatch without affecting the current emission.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to every handler. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to every handler. |
{}
|
Source code in src/deckui/runtime/async_event.py
DeviceCapabilities
dataclass
¶
Immutable snapshot of a Stream Deck device's hardware capabilities.
Constructed from a connected device via :meth:from_device, this
dataclass captures every property needed to drive layout, rendering,
and event routing without hardcoded constants.
Source code in src/deckui/runtime/capabilities.py
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 | |
has_info_screen
property
¶
Whether the device has a non-touch info screen (e.g. Neo).
from_device
classmethod
¶
Build capabilities from a connected (opened) device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
StreamDeck
|
An open |
required |
Returns:
| Type | Description |
|---|---|
DeviceCapabilities
|
A frozen :class: |
Source code in src/deckui/runtime/capabilities.py
Deck ¶
Per-device handle for an Elgato Stream Deck.
Instances are created and managed by :class:DeckManager. Do not
instantiate Deck directly — use DeckManager.on_connect to
receive connected Deck instances.
The Deck object provides the per-device API for screens, keys,
encoders, touchscreen cards, brightness, and rendering.
Attributes:
| Name | Type | Description |
|---|---|---|
on_brightness_changed |
AsyncEvent
|
Fires after :meth: |
on_screen_changed |
AsyncEvent
|
Fires after :meth: |
Source code in src/deckui/runtime/deck.py
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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 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 283 284 285 286 287 288 289 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 330 331 332 333 334 335 336 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 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 | |
is_connected
property
¶
Whether the device is currently connected and operational.
capabilities
property
¶
The device capabilities for the connected device.
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened. |
metrics
property
¶
Rendering metrics for the connected device.
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened. |
active_screen
property
¶
The currently displayed screen, or None if no screen is set.
__init__ ¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial_number
|
str
|
The serial number of the target device. |
required |
brightness
|
int
|
Initial brightness (0-100). |
80
|
Source code in src/deckui/runtime/deck.py
start
async
¶
Discover the device by serial, open it, and start the event loop.
Source code in src/deckui/runtime/deck.py
stop
async
¶
Stop the event loop and close the device.
Source code in src/deckui/runtime/deck.py
wait_closed
async
¶
set_brightness
async
¶
Set screen brightness.
Pushes the value to the hardware (if connected) and emits
:attr:on_brightness_changed with the clamped result. If the
clamped value equals the current brightness, no event fires —
observers see only confirmed transitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
percent
|
int
|
Brightness level (0-100). Values outside the range are clamped. |
required |
Source code in src/deckui/runtime/deck.py
screen ¶
Get or create a screen by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Screen name. |
required |
Returns:
| Type | Description |
|---|---|
Screen
|
The Screen instance. |
Raises:
| Type | Description |
|---|---|
DeckError
|
If the device is not opened — capabilities are required to
size the screen, and they are only known after :meth: |
Source code in src/deckui/runtime/deck.py
set_screen
async
¶
Switch to a named screen, rendering all keys and cards.
Wires up refresh callbacks on every key and card so that any
handler or background task can call request_refresh() to
trigger a re-render without needing a direct reference to the
deck. After the new screen has finished rendering, fires
:attr:on_screen_changed with the new name. No event fires
if the requested screen is already active.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Screen name (must already exist via |
required |
Raises:
| Type | Description |
|---|---|
DeckError
|
If name does not match a previously-created screen. |
Source code in src/deckui/runtime/deck.py
refresh
async
¶
Re-render and push all dirty controls on the active screen.
Call this after changing card values if you need immediate
updates outside of set_screen(). Also drains any pending
callbacks queued by programmatic set_value() calls on
range controls.
Source code in src/deckui/runtime/deck.py
DeckError ¶
DeviceInfo
dataclass
¶
Information about a connected Stream Deck device.
Attributes:
| Name | Type | Description |
|---|---|---|
deck_type |
str
|
Human-readable device model name (e.g. |
serial |
str
|
Unique serial number reported by the hardware. |
firmware |
str
|
Firmware version string. |
key_count |
int
|
Total number of physical keys on the device. |
key_layout |
tuple[int, int]
|
Key grid dimensions as |
encoder_count |
int
|
Number of rotary encoders (dials) on the device. |
key_pixel_size |
tuple[int, int]
|
Pixel dimensions of a single key image as |
touchscreen_size |
tuple[int, int]
|
Pixel dimensions of the touchscreen as |
key_image_format |
str
|
Image format expected by the device (e.g. |
Source code in src/deckui/runtime/device_info.py
EncoderPressEvent
dataclass
¶
EncoderTurnEvent
dataclass
¶
EventType ¶
KeyEvent
dataclass
¶
TouchEvent
dataclass
¶
A touchscreen interaction event.
Source code in src/deckui/runtime/events.py
compute_zone ¶
Compute which touch-strip zone this touch falls in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
RenderMetrics
|
The render metrics for the connected device. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Zone index (0 to panel_count-1). |
Source code in src/deckui/runtime/events.py
DeckManager ¶
The main entry point for the deckui library.
Manages one or more Stream Deck devices with automatic discovery,
hot-plug detection, and reconnection. Register on_connect and
on_disconnect handlers, then start the manager.
Examples:
::
manager = DeckManager()
@manager.on_connect(deck_type="Stream Deck +")
async def handle(deck: Deck):
screen = deck.screen("main")
@screen.key(0).on_press
async def on_home():
print("Home pressed!")
await deck.set_screen("main")
@manager.on_disconnect
async def lost(info: DeviceInfo):
print(f"Lost: {info.serial}")
async with manager:
await manager.wait_closed()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poll_interval
|
float
|
Seconds between device scans (default 2.0). |
2.0
|
brightness
|
int
|
Default brightness for new Deck instances (0-100). |
80
|
auto_reconnect
|
bool
|
If |
True
|
Source code in src/deckui/runtime/manager.py
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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 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 283 284 285 286 287 288 289 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 | |
on_disconnect
property
¶
Register a callback for when a device disconnects.
Examples:
::
@manager.on_disconnect
async def handle(info: DeviceInfo):
...
__aenter__
async
¶
__aexit__
async
¶
start
async
¶
Start the device scanning loop.
Source code in src/deckui/runtime/manager.py
stop
async
¶
Stop scanning and close all managed decks.
Source code in src/deckui/runtime/manager.py
wait_closed
async
¶
on_connect ¶
on_connect(*, serial: str | None = None, deck_type: str | None = None) -> Callable[[AsyncHandler], AsyncHandler]
Register a callback for when a matching device connects.
The handler is also called on reconnection when
auto_reconnect is enabled.
Examples:
::
@manager.on_connect(deck_type="Stream Deck +")
async def handle(deck: Deck):
...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serial
|
str | None
|
Only match this serial number. |
None
|
deck_type
|
str | None
|
Only match this device type. |
None
|
Returns:
| Type | Description |
|---|---|
Callable
|
Decorator that registers the handler. |
Source code in src/deckui/runtime/manager.py
AsyncTransport ¶
Bridge sync streamdeck callbacks into an asyncio event queue.
Conditionally registers dial and touchscreen callbacks only when the device supports those features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
StreamDeck
|
An open Stream Deck device. |
required |
loop
|
AbstractEventLoop
|
The running asyncio event loop. |
required |
caps
|
DeviceCapabilities | None
|
Device capabilities (used to determine which callbacks to register). |
None
|
Source code in src/deckui/runtime/transport.py
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 | |
start ¶
Register callbacks on the low-level device.
Source code in src/deckui/runtime/transport.py
stop ¶
Unregister callbacks.
Source code in src/deckui/runtime/transport.py
list_devices
async
¶
Enumerate all connected Stream Deck devices.
Discovers devices via HID, opens each briefly to read serial and
firmware information, then closes them. Returns a list of
:class:DeviceInfo snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deck_type
|
str | None
|
If set, only return devices matching this type
(e.g. |
None
|
visual_only
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
list[DeviceInfo]
|
A list of :class: |