Skip to main content

Live updates (WebSockets)

The Python SDK can listen for real-time updates so new definitions are applied quickly.

Enable​

enable_live_updates defaults to true on TogglyConfig:

from toggly import TogglyClient, TogglyConfig

config = TogglyConfig(
app_key="YOUR_APP_KEY",
environment="Production",
enable_live_updates=True,
)
client = TogglyClient(config)
client.init()

Install the optional WebSocket extra:

pip install toggly[websocket]

Without websocket-client, the SDK skips live updates and continues with background HTTP refresh.

Sync client only

WebSocket live updates are implemented on TogglyClient. AsyncTogglyClient does not open a WebSocket; use the sync client (or HTTP refresh) when you need streaming updates.

How it works​

The SDK connects directly to the definitions worker:

wss://{baseURL}/{appKey}/ws?sdk=python&sdkVersion={semver}&rev={cachedEtag}

When a cached definitions revision (ETag) is available, it is sent as rev.

Update messages:

MessageSDK action
flags-updatedRefresh definitions
updateRefresh definitions (legacy)
signing-key-updatedClear JWKS (+ JWKS snapshot), force refresh
pingIgnored

While connected, periodic HTTP refresh is skipped until the fallback interval elapses. Live updates accelerate freshness; the background refresh loop still provides eventual consistency when the socket is disconnected.

See WebSocket sync (client-side) for the full protocol shared across SDKs.

Framework tip​

configure_toggly (FastAPI) and Django/Flask settings currently expose use_signed_definitions but not enable_live_updates. Live updates stay on by default via TogglyConfig. To override, build a client yourself and pass it in:

from toggly import TogglyClient, TogglyConfig
from toggly_fastapi import configure_toggly

config = TogglyConfig(
app_key="YOUR_APP_KEY",
enable_live_updates=False,
)
client = TogglyClient(config)
client.init()
configure_toggly(client=client)