Skip to main content
client.apps.realtime(app_id) opens a live stream of an app’s logs, status and system events. With SquareCloud it is an iterator consumed with for; with AsyncSquareCloud it is an async iterator consumed with async for. Use it in a with / async with block so leaving the block closes the connection. Examples use the client from Creating the client. app_id is the id of one of your apps: client.account.me() lists them.
With AsyncSquareCloud, apps.realtime(app_id) returns an AsyncRealtime directly: do not await it. A background reader thread feeds the events to your event loop, so no executor thread is held while you wait.

Events

Every event is a dict with event, data (the raw frame text) and id (None when the frame has none).

The status object

Ending the stream

The loop ends on its own when:
  • the server closes the connection cleanly (each connection lasts up to 10 minutes);
  • the server sends REALTIME_DISCONNECTED;
  • you break out of the loop (then leave the with block, which closes the connection);
  • you call stream.close(), from any thread, even while the loop waits for data or for a reconnection (the loop just ends, it does not raise).
close() is synchronous on both Realtime and AsyncRealtime. To keep watching past 10 minutes, open a new stream when the loop ends.

Reconnection

A dropped connection, or the server handing reconnection to the client (REALTIME_RECONNECT), reopens the stream on its own:
  • up to 3 times in a row; any logs or status event resets the count;
  • each reopen at least 5.5 s after the previous open, to stay under the API’s pace of one open per 5 seconds per app.
Past 3 failed reconnections, the loop raises a SquareCloudAPIError with NETWORK_ERROR. Each open is a GET, so a network error while opening is also retried up to max_retries times; an open that still fails raises.

Limits and errors

  • 5 concurrent connections per account and 30 per app, across all users. Going over is 429 REALTIME_MAX_CONNECTIONS or REALTIME_MAX_CONNECTIONS_APP.
  • The HTTP status is checked before streaming, so these errors (and 404 for an unknown app) raise on the first iteration.
  • The timeout only covers the open, until the response headers arrive. The stream itself has no timeout: a half-open connection (a laptop resuming from sleep) waits until you call close().

Next steps

Snapshots

Back up and restore apps and databases.

Realtime API reference

The REST endpoint behind this stream.

Logs from the CLI

The same stream from the terminal.