Skip to main content

FletApp

Handle Flet app WebSocket connections.

Parameters:

  • loop (asyncio.AbstractEventLoop) - asyncio event loop (asyncio.get_running_loop()).
  • executor (ThreadPoolExecutor) - Thread pool executor (app_manager.executor).
  • main (AppCallable) - Application entry point - an async method called for newly connected user. Handler coroutine must have 1 parameter of instance Page.
  • before_main (AppCallable | None) - Called before main.
  • session_timeout_seconds (int, default: DEFAULT_FLET_SESSION_TIMEOUT) - Session lifetime, in seconds, after user disconnected.
  • oauth_state_timeout_seconds (int, default: DEFAULT_FLET_OAUTH_STATE_TIMEOUT) - OAuth state lifetime, in seconds, which is a maximum allowed time between starting OAuth flow and redirecting to OAuth callback URL.
  • upload_endpoint_path (str | None, default: None) - Absolute URL of upload endpoint, e.g. /upload.
  • secret_key (str | None, default: None) - Secret key to sign upload requests.

Inherits: flet.messaging.connection.Connection

Properties

Methods

Properties

executorinstance-attribute

loopinstance-attribute

Methods

data_channel_for

data_channel_for(channel_id: int)

Resolve or construct the muxed DataChannel for channel_id.

dispose

dispose()

Release app-level session reference during teardown.

get_upload_url

get_upload_url(file_name: str, expires: int) -> str

Build signed upload URL for a file.

Parameters:

  • file_name (str) - File name to be uploaded.
  • expires (int) - URL lifetime in seconds.

Returns:

  • str - Signed relative upload URL.

Raises:

  • RuntimeError - If upload endpoint is not configured.

handleasync

handle(websocket: WebSocket)

Handle WebSocket connection.

Parameters:

  • websocket (WebSocket) - WebSocket instance.

oauth_authorize

oauth_authorize(attrs: dict[str, Any])

Persist OAuth state metadata for a pending authorization flow.

Parameters:

  • attrs (dict[str, Any]) - OAuth attributes payload containing state and optional completion page data.

send_data_channel_frame

send_data_channel_frame(
    channel_id: int, payload: bytes
) -> None

Send a raw DataChannel frame [0x01][channel_id:u32 LE][bytes] over the WebSocket. Called by _ProtocolMuxedDataChannel.send.

send_message

send_message(message: ClientMessage)

Serialize and enqueue a server message for transport to the client.

Wire format: one packet per send_bytes call — [0x00][msgpack body]. WebSocket preserves message boundaries so no length prefix is needed.

Parameters:

  • message (ClientMessage) - Outbound protocol message.

unregister_data_channel

unregister_data_channel(channel_id: int) -> None