Skip to main content

FletApp

Renders another Flet app in the current app, similar to HTML IFrame, but for Flet.

Inherits: LayoutControl

Properties

Events

  • on_connect - Fires when the client allocates an in-process dart_bridge channel for this embedded app (url="dartbridge://").
  • on_error - Called when a connection or any unhandled error occurs.
  • on_guest_request - Called when the embedded app asks its host to do something, with Page.request_host.
  • on_python_output - Fires once per stdout/stderr write inside the embedded Pyodide app.
  • on_route_change - Called when the embedded app navigates itself.
  • on_title_change - Called when the embedded app sets page.title.
  • on_window_event - Called when the embedded app asks its window to do something - a method call like page.window.close(), or a property write like page.window.maximized = True.

Methods

  • act - Taps and types in the embedded app, like a person would.
  • describe - Lists the controls the embedded app shows right now.
  • wait_idle - Waits until the embedded app has rendered its UI and gone quiet.

Properties​

app_error_messageclass-attributeinstance-attribute​

app_error_message: str | None = None

Template message to display when the app fails to load. Use {message} placeholder to include the error message and {details} to include error details.

argsclass-attributeinstance-attribute​

args: dict[str, Any] | None = None

Optional dictionary of arguments to pass to the Flet app.

assets_dirclass-attributeinstance-attribute​

assets_dir: str | None = None

Base location for assets referenced by the embedded app. On web this is a URL prefix joined with relative src values (e.g. on Image/Lottie/Markdown); on desktop it is a filesystem path.

boot_screen_nameclass-attributeinstance-attribute​

boot_screen_name: str | None = None

Name of the boot screen to show while the embedded app starts up.

When None, the built-in "flet" boot screen is used. Custom boot screens are provided by extensions; see the boot screen docs.

boot_screen_optionsclass-attributeinstance-attribute​

boot_screen_options: dict[str, Any] | None = None

Options for the boot screen, passed through to the boot screen widget.

For the built-in "flet" screen these include spinner_size, startup_message, bgcolor_light/bgcolor_dark, etc. See the boot screen docs.

file_storage_quotaclass-attributeinstance-attribute​

file_storage_quota: int | None = None

Most bytes the embedded app may keep in FileStorage: a write that would go past it fails.

None (default) allows 50 MB. The limit covers only the embedded app's own folder. An app sharing its host's folder also inherits the host's limit when it is lower.

force_pyodideclass-attributeinstance-attribute​

force_pyodide: bool = False

Whether to force the use of Pyodide.

isolatedclass-attributeinstance-attribute​

isolated: bool = False

Whether to run the embedded app's Python isolated from the host's page.

On web, isolated=True runs the Pyodide worker in a sandboxed frame with an opaque origin. This prevents access to the host page's IndexedDB, Cache Storage and private file system. The worker creates blob: URLs under its own origin. Nested apps inherit isolation. A page can also isolate its top-level app with window.flet.isolated = true.

The host can cache approved runtime and package downloads. These requests omit credentials and reject redirects. Other requests go directly from the worker and follow browser CORS and cross-site cookie rules. Eligible cookies can accompany a direct request that includes credentials.

With a self-hosted runtime (--no-cdn), serve pyodide/*.mjs with CORS headers that allow the worker to import them. This setting only applies to Python running in the browser.

media_paddingclass-attributeinstance-attribute​

media_padding: PaddingValue | None = None

Overrides the safe-area insets the embedded app sees.

The embedded app normally inherits the host window's MediaQuery, so on a desktop window its insets are zero regardless of what the app is being previewed as. Setting this makes the embedded app lay out as though it had those insets: page.media.padding reports them, and SafeArea avoids them.

Intended for previewing a phone layout inside a desktop window - a device frame in a designer, say - where the chrome drawn around the app is not something the platform knows about.

platform_brightnessclass-attributeinstance-attribute​

platform_brightness: Brightness | None = None

Overrides the system light/dark appearance the embedded app sees.

By default the embedded app follows the host's platform brightness. Set this to preview it as though its device were in light or dark mode: an app whose theme_mode is SYSTEM switches to its dark or light theme, page.platform_brightness reports the value, and on_platform_brightness_change fires when it changes. An app that forces LIGHT or DARK keeps it, as on a real device.

None follows the host.

reconnect_interval_msclass-attributeinstance-attribute​

reconnect_interval_ms: int | None = None

Delay, in milliseconds, between reconnection attempts.

reconnect_timeout_msclass-attributeinstance-attribute​

reconnect_timeout_ms: int | None = None

Total time to try reconnecting.

routeclass-attributeinstance-attribute​

route: str | None = None

The embedded app's current route.

Two-way: setting it navigates the embedded app, and when the embedded app navigates itself this property is updated to match and on_route_change fires. Leave it None to let the embedded app own its own routing.

Note

The embedded app routes locally - it never touches the browser address bar or the platform's deep links, both of which belong to the host app.

shared_preferences_quotaclass-attributeinstance-attribute​

shared_preferences_quota: int | None = None

Most bytes the embedded app's SharedPreferences keys and values may take: a set() that would go past it fails.

None (default) allows 1 MB. On web the host and every embedded app share the browser's localStorage for the page's origin, about 5 MB in all, so this keeps an embedded app from filling it and breaking the host's own writes. Keys under a nested prefix also count toward each enclosing host quota.

storage_prefixclass-attributeinstance-attribute​

storage_prefix: str | None = None

Prefix for the embedded app's SharedPreferences keys and FileStorage folder.

The embedded app runs in the host's process (on web, the host's browser origin), so without a prefix the two would share one store, and see and overwrite each other's keys. The prefix is applied on the client; the app itself uses plain key names and never sees it.

  • None (default): the embedded app is isolated under a prefix derived from its url (or assets_dir when url is empty), fletapp.<hash>.. Its data is kept for as long as that location stays the same.
  • A string such as "app.42.": use that prefix. Set this when the embedded app's URL changes between runs (a cache-busting query, say) but its saved data should stay, or to give each embedded app a readable namespace. End it with a separator so "app.1." and "app.12." don't overlap.
  • "": share the host's keys and files. Only for an embedded app you trust as much as the host.

The prefix nests under the host's own: if the host app itself runs under "app.1.", an embedded app with "preview." stores keys under "app.1.preview.", so it can never reach outside its host's space.

titleclass-attributeinstance-attribute​

title: str | None = None

The embedded app's page.title.

Written by the client whenever the embedded app sets its title, together with on_title_change. A guest's title belongs to whatever window its host draws around it - it does not touch the real OS window, because the window service is suppressed for embedded apps.

urlclass-attributeinstance-attribute​

url: str | None = None

Flet app URL, e.g. http://localhost:8550 or flet.sock.

window_stateclass-attributeinstance-attribute​

window_state: dict[str, Any] | None = None

The simulated window the embedded app should believe it lives in.

Keys are Window property names - width, height, top, left, maximized, minimized, full_screen, focused. What you set here is what the embedded app reads back from page.window, and changing it raises the matching page.window.on_event inside the app (resize, maximize, focus, ...) exactly as a real window would.

An embedded app never drives the real OS window, so without this its page.window is inert.

Events​

on_connectclass-attributeinstance-attribute​

on_connect: ControlEventHandler[FletApp] | None = None

Fires when the client allocates an in-process dart_bridge channel for this embedded app (url="dartbridge://"). The event data is the Dart native port the host must serve with a FletDartBridgeServer so the embedded app connects over it instead of a socket.

Advanced / embedder use — hosts that run another Flet program in-process (e.g. a gallery or preview) start their server on this port in the handler.

on_errorclass-attributeinstance-attribute​

on_error: ControlEventHandler[FletApp] | None = None

Called when a connection or any unhandled error occurs.

on_guest_requestclass-attributeinstance-attribute​

on_guest_request: (
    EventHandler[FletAppGuestRequestEvent] | None
) = None

Called when the embedded app asks its host to do something, with Page.request_host.

The handler's return value is the reply, which the embedded app gets back from request_host(). It can be anything Flet can send: None, numbers, strings, bytes, lists and dicts of them. The handler may be async and may take as long as it needs, for example while the user signs in. Each FletApp can handle up to 16 requests at once. If the guest times out, its handler can finish normally and occupies a slot until it finishes. Additional requests while all slots are in use fail with "failed".

  • Return HostRequest.UNHANDLED for a request this host doesn't handle.
  • Raise HostRequestRefused to decline it, for example when the user said no.
  • Any other exception fails the request; the embedded app gets its message, never the traceback.

While this is not set, every request of the embedded app fails with "unhandled", without reaching the host. Nothing is allowed by default: decide on each request by its name, and treat its args as untrusted input. Never let them choose what the host acts on.

Example
async def on_request(e: ft.FletAppGuestRequestEvent):
if e.request != "share":
return ft.HostRequest.UNHANDLED
if not await confirm(f"Share {e.args.get('title')!r}?"):
raise ft.HostRequestRefused("The user said no.")
return {"shared": True}

ft.FletApp(url=..., on_guest_request=on_request)

on_python_outputclass-attributeinstance-attribute​

on_python_output: (
    EventHandler[FletAppOutputEvent] | None
) = None

Fires once per stdout/stderr write inside the embedded Pyodide app. Pyodide line-buffers by default, so each event is typically one print(...) call. Only fires for embedded FletApps with force_pyodide=True; root-level Pyodide pages have nowhere to bubble the event.

on_route_changeclass-attributeinstance-attribute​

on_route_change: ControlEventHandler[FletApp] | None = None

Called when the embedded app navigates itself. The event data is the new route, which is also written back to route.

Does not fire for navigation the host itself caused by setting route.

on_title_changeclass-attributeinstance-attribute​

on_title_change: ControlEventHandler[FletApp] | None = None

Called when the embedded app sets page.title. The event data is the new title, which is also written back to title.

on_window_eventclass-attributeinstance-attribute​

on_window_event: EventHandler[FletAppWindowEvent] | None = (
    None
)

Called when the embedded app asks its window to do something - a method call like page.window.close(), or a property write like page.window.maximized = True.

A request, not a command: nothing happens unless the host acts on it, which is how a host that does not simulate, say, minimizing simply ignores it.

Methods​

actasync​

act(
    steps: list[dict[str, Any]],
    pointer: str = "touch",
    idle_ms: int = 500,
    timeout_ms: int = 5000,
) -> dict[str, Any]

Taps and types in the embedded app, like a person would.

Each step is a dict with an action:

  • {"action": "tap", "target": ...}, and "long_press" the same way.
  • {"action": "enter_text", "target": ..., "text": "Ada"} replaces a text field's text (its on_change fires). With "submit": True the field is then submitted, as when pressing Enter.
  • {"action": "tap_at", "x": 120, "y": 300} taps a point, in the embedded page's logical pixels. For games and drawing.
  • {"action": "wait", "ms": 500}.

A target picks a control the way describe reports it: {"key": "email"}, {"text": "Save"} (exact, then case-insensitive containing), {"tooltip": "Delete"}, {"type": "Checkbox"} or {"id": 42}, with an optional "index" among the matches. Dialogs come first, so with one open, {"text": "OK"} is its button.

A disabled or covered target fails the step. Coordinate taps also fail if the host covers the point. Read-only fields reject text entry. After the first step, a missing target can appear in a later frame while the embedded app processes the preceding action. Steps stop at the first failure.

Parameters:

  • steps (list[dict[str, Any]]) - The steps, run in order.
  • pointer (str, default: 'touch') - "touch" or "mouse". Mouse also sends hover events.
  • idle_ms (int, default: 500) - After the last step, wait until the app sent no UI update for this long, so the result shows the app's reaction.
  • timeout_ms (int, default: 5000) - Maximum time to wait for each missing target after the first step, and separately for the final idle period, in milliseconds.

Returns:

  • dict[str, Any] - A dict with status ("idle", "timeout" or "error", from the wait after the steps; error holds the message) and steps: one result per step that ran, with action, status ("ok", "not_found", "covered", "disabled", "read_only", "not_a_text_field" or "error"), the target used, the tap point and, when nothing matched, a few candidates.

describeasync​

describe(max_items: int = 100) -> dict[str, Any]

Lists the controls the embedded app shows right now.

For a host that lets someone (for example an AI agent) see and use the embedded app without a screenshot. Use act to tap and type.

Only controls a person can see or use are listed: text, inputs, and controls with event handlers, a key or a tooltip. Layout controls (Row, Column, Container without events) are left out, and so is anything off screen or behind an opaque route.

Parameters:

  • max_items (int, default: 100) - The most controls to return.

Returns:

  • dict[str, Any] - A dict with status ("ok" or "error"), width and height (the embedded page's size in logical pixels), controls and truncated. Each control has id, type, key, text (its label or the first Text in it), value (a field's text or a checkbox's state; never a password), tooltip, disabled, events (its on_* handlers, without the prefix), rect ([x, y, width, height] of its visible part, in the embedded page's logical pixels), covered (something such as a dialog is on top of its centre) and layer ("dialog" for dialogs, sheets and snack bars). Keys without a value are left out. Text drawn by a control without a Text control of its own, such as a navigation bar's labels, is listed with type "label" and in, the id of the control around it.

wait_idleasync​

wait_idle(
    idle_ms: int = 300, timeout_ms: int = 30000
) -> dict[str, Any]

Waits until the embedded app has rendered its UI and gone quiet.

Useful for a host that needs to know when the embedded app is ready, e.g. before taking a screenshot of it or reading its output after a restart.

Parameters:

  • idle_ms (int, default: 300) - How long, in milliseconds, the embedded app must send no UI updates after its first one to count as idle.
  • timeout_ms (int, default: 30000) - Give up after this many milliseconds.

Returns:

  • dict[str, Any] - A dict with status and error. status is "idle" once the
  • dict[str, Any] - app sent at least one UI update, then none for idle_ms, and
  • dict[str, Any] - that update is on screen; "error" if the app failed to start
  • dict[str, Any] - or crashed (error holds the message; on_error fires as
  • dict[str, Any] - well); "timeout" if it didn't settle within timeout_ms, for
  • dict[str, Any] - example an app that updates continuously. A new call supersedes
  • dict[str, Any] - a pending one, which returns "timeout".