Streaming¶
Streaming Module¶
streaming
¶
Streaming(central_conn, event, reconnect_delay=5, max_retries=None, filters=None)
¶
Minimal WebSocket streaming client for Central.
Responsibilities
- Build the WSS URL for the selected streaming endpoint.
- Maintain a single WebSocket connection with optional auto-reconnect.
- Decode protobuf payloads and deliver them to a user callback.
- Allow graceful stop and cleanup of the WebSocket connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
central_conn
|
NewCentralBase
|
Central connection object, used for tokens, base URL and logging. |
required |
event
|
str
|
Streaming event name. Must be one of the keys in SUPPORTED_EVENTS (for example, "audit-trail-events"). |
required |
reconnect_delay
|
int
|
Delay in seconds before attempting to reconnect after an unexpected disconnection. Defaults to 5. |
5
|
max_retries
|
int | None
|
Maximum number of reconnection
attempts after an unexpected disconnection. |
None
|
filters
|
str | list[str]
|
Either a single filter string or a list of filter strings. If a list is provided, its elements will be joined with commas to form the header value. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported event is provided or filters are of an unexpected type. |
Source code in pycentral/streaming/streaming.py
stream(callback=None)
¶
Start streaming messages for the configured event.
This method establishes the WebSocket connection, listens for
messages, and optionally auto-reconnects on unexpected closure
until stop() is called or a fatal error occurs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
callable
|
Function to be invoked for each decoded message. It must accept a single argument (dict) representing the decoded protobuf message. If not provided, decoded messages are logged. |
None
|
Raises:
| Type | Description |
|---|---|
KeyboardInterrupt
|
If interrupted by the user (Ctrl+C) while streaming in a foreground loop. |
Source code in pycentral/streaming/streaming.py
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 | |
stop()
¶
Request the streaming loop to stop and close the WebSocket.
This method can be called from another thread or from within the user callback to stop streaming gracefully.