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 (Optional[AppCallable]) - 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 (Optional[str], default: None) - Absolute URL of upload endpoint, e.g. /upload.
  • secret_key (Optional[str], default: None) - Secret key to sign upload requests.

Inherits: flet.messaging.connection.Connection

Properties

Methods

  • dispose - Release app-level session reference during teardown.
  • get_upload_url - Build signed upload URL for a file.
  • handle - Handle WebSocket connection.
  • oauth_authorize - Persist OAuth state metadata for a pending authorization flow.
  • send_message - Serialize and enqueue a server message for transport to the client.

Properties

executorinstance-attribute

loopinstance-attribute

Methods

dispose

dispose()

Release app-level session reference during teardown.

get_upload_url

get_upload_url(file_name: str, expires: int)

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_message

send_message(message: ClientMessage)

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

Parameters:

  • message (ClientMessage) - Outbound protocol message.