Skip to main content
Figranium exposes two Server-Sent Events endpoints, and the Python SDK surfaces both as iterators. On the synchronous Figranium client you use a plain for loop. On AsyncFigranium you use async for. Both return the same StreamEvent shape.

Streams

Both take an optional options keyword argument (headers, timeout).

StreamEvent shape

The SDK tries json.loads on the data lines. If parsing fails, data is the raw string and raw still contains the original payload.

Consume execution events

1

Create a client

Initialize the SDK with your API key.
filename.py
2

Iterate the stream

Use a for loop to consume events as they arrive.
filename.py
Iteration ends when the server closes the connection or when your loop breaks. Breaking out of the loop cancels the underlying reader.

Async execution stream

On AsyncFigranium, use async for:
filename.py

Terminal timeouts

Streams have no default timeout. Set timeout only when you want a hard deadline; the stream raises FigraniumError(code="REQUEST_ABORTED") when the timer fires:
filename.py

Cancel a stream

In Python, cancellation is done by breaking out of the loop or by the terminal timeout expiring. There is no AbortSignal equivalent.
filename.py

Selector stream from a headful browser

The selector stream reports element highlights from a headful browser session. Use it to power visual inspectors:
filename.py
See Browser resource for opening, inspecting, and stopping headful sessions.

Errors

Streams raise FigraniumError in the same conditions as regular requests:
  • REQUEST_ABORTED: the terminal timeout fired.
  • NETWORK_ERROR: the stream could not reach the server.
See Errors for the full error shape.
For long-running streams, prefer breaking out of the loop over a short timeout so you can stop cleanly when your application state changes.