Documentation Index
Fetch the complete documentation index at: https://mintlify.com/whitphx/stlite/llms.txt
Use this file to discover all available pages before exploring further.
mount() is the core JavaScript function exported by @stlite/browser. It creates a Streamlit runtime inside any DOM element, accepts fine-grained options for files, packages, configuration, and the virtual file system, and returns a controller object that lets you interact with the running app after startup. The <streamlit-app> custom element is a declarative wrapper around this same function.
Function signature
container defaults to document.body when omitted.
Simple string usage
Pass a Python source string as the first argument to get a running app with minimal boilerplate. The string is written tostreamlit_app.py in the virtual file system and used as the entry point.
Full options object usage
For more control pass aMountOptions object as the first argument.
Options reference
The file path inside the virtual file system that Streamlit will run (equivalent to the argument passed to
streamlit run). Required when options is an object. The file must exist either in files or as a result of unpacking an archives entry.Files to mount onto the Pyodide virtual file system before the app starts. Keys are file paths; values can be a string, a
Uint8Array, an object with a url field (fetched at startup), or an object with data and opts fields. See Files & Archives for full details.Python packages to install via
micropip during the boot phase, using the same syntax as requirements.txt. These are installed alongside Streamlit’s own built-in dependencies in a single micropip.install() call.Packages to install via Pyodide’s
pyodide.loadPackage() rather than micropip. Use this for packages like openssl that are distributed as Pyodide built-in packages and are not installable through micropip.Archive files (e.g. zip, tar) to download, unpack, and mount onto the virtual file system. Each entry is an object with
url or buffer, plus format and optional options forwarded to pyodide.unpackArchive(). See Files & Archives for full details.Additional package install operations with full micropip option control. Use this when you need to pass non-default flags to
micropip.install such as pre, index_urls, or keep_going. Each entry has requirements (string array) and an optional options object.Streamlit configuration key-value pairs. Keys follow the dot-separated format used by
streamlit run -- flags (e.g. "theme.base", "client.toolbarMode"). Values can be strings, numbers, or booleans. See Configuration for a full example.URL of a custom
pyodide.js (or pyodide.mjs) distribution. Use this when your organization restricts CDN access or you need to serve Pyodide from your own infrastructure. Must point to the full Pyodide distribution — not the core-only build — because Stlite loads packages such as micropip that are absent from the core distribution.File system paths to mount with Emscripten’s
IDBFS (IndexedDB-backed) file system. Files written under these paths persist across page reloads. Paths not listed here use the default ephemeral MEMFS backend.When
true, the app runs inside a SharedWorker shared with all other Stlite apps on the page that also have sharedWorker: true. This reduces memory consumption when many apps are mounted simultaneously. Defaults to false. Falls back to a dedicated worker on browsers that do not support SharedWorker (e.g. Chrome for Android).A flat key-value mapping of environment variables to set inside the Pyodide runtime before the app starts. Both keys and values must be strings. These are accessible from Python via
os.environ.When
true, enables the Python language server inside the Pyodide runtime, which allows the controller.getCodeCompletion() method to return meaningful results. Enabling this loads additional Python packages and increases startup time. Defaults to false.When
true, suppresses the loading-progress toast notifications shown while Pyodide and packages are being downloaded. Defaults to false.When
true, suppresses the error toast notifications shown when a runtime error occurs. Defaults to false.When
true, suppresses the toast notifications shown when Stlite automatically detects and installs missing Python packages. Defaults to false.When
true, prevents Stlite from injecting global CSS rules into the host document. Useful when embedding inside an existing application or iframe where Stlite’s default styles would conflict with the host page. Defaults to false.A Content Security Policy nonce to attach to
<style> elements injected by Stlite. Required when your CSP policy enforces 'nonce-…' on inline styles.Returned controller
mount() returns a controller object with the following methods for interacting with the live app.
Tears down the Streamlit app and React root, and disposes the underlying kernel. Call this when the container element is removed from the DOM.
Installs additional Python packages into the running environment via
micropip.install(). Returns a Promise that resolves when the install is complete. Accepts an optional MicropipInstallOptions object as the second argument.Registers a mock Python package in the running environment. Useful for testing or stubbing out packages that are unavailable in the Pyodide runtime.
modules is an optional record mapping module names to their Python source code strings. persistent is an optional boolean controlling whether the mock survives a kernel reboot. Returns a Promise.Writes a file to the virtual file system at runtime.
data can be a string or ArrayBufferView. Returns a Promise.Reads a file from the virtual file system. Returns a
Promise<string | Uint8Array>.Renames (moves) a file within the virtual file system. Returns a
Promise.Deletes a file from the virtual file system. Returns a
Promise.Executes an arbitrary Python code string in the running Pyodide environment. Returns a
Promise that resolves with the result of the last expression.Requests Python code-completion suggestions for the given
code string at the specified { line, column } cursor position. Returns a Promise resolving to an array of completion objects ({ name, type, docstring, complete }).SharedWorker example
installs option example
Use installs when you need micropip options beyond the defaults — for example installing a pre-release from a private index.