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.
@stlite/react exports two React components (StliteApp and StliteAppWithToast), a kernel factory function (createKernel), a lifecycle hook (useKernel), and all TypeScript types from @stlite/kernel. Everything documented here is the stable public API as of @stlite/react v1.7.0.
createKernel(options)
StliteKernel — the Pyodide-backed Web Worker that executes your Streamlit app in the browser. The returned kernel instance is passed to StliteApp or StliteAppWithToast as the kernel prop.
Call createKernel outside the React component tree (at module level) so the kernel is created once per page load, not once per render. If you need the kernel’s lifetime to match a component’s lifecycle, use useKernel instead.
When you are done with a kernel, call kernel.dispose() to terminate the underlying worker.
Options (StliteKernelOptions)
The path on the Pyodide virtual file system (Emscripten FS) that Streamlit will run as its entry point. Must match a key in the
files map or a path unpacked from archives.A map of virtual file paths to their contents. Use
EmscriptenFile to provide inline content, or EmscriptenFileUrl to have the kernel fetch a file by URL at startup.A list of archives to unpack into the virtual file system at startup. Each archive can be provided as an in-memory buffer (
PyodideArchive) or fetched from a URL (PyodideArchiveUrl). Pass an empty array if you have no archives.Python packages to install via
micropip during kernel boot, in addition to the built-in Streamlit and stlite-lib packages. Pass an empty array if no additional packages are needed.Packages to install via
pyodide.loadPackage() rather than micropip. A small set of packages (such as openssl) can only be installed through this path. Pass an empty array if none are needed.Additional package installation batches with per-batch
micropip options. Unlike requirements (which shares install options with the built-in Streamlit/stlite-lib batch), each entry here is a separate micropip.install() call and can carry its own MicropipInstallOptions — for example a custom index_urls or pre: true for pre-release packages.The URLs of the bundled
stlite-lib and streamlit Python wheel files. In a Vite project, import this value from @stlite/react/vite-utils — the Vite plugin resolves the hashed asset URLs at build time.The URL of the
pyodide.js (or pyodide.mjs) entry point to load in the worker. If omitted, the default bundled version is used. Override this to pin a specific Pyodide release or load from a CDN.Streamlit configuration key-value pairs, equivalent to the options you would pass to
streamlit run as -- flags. Keys use dot-notation.File system paths inside the Pyodide FS to back with IndexedDB via Emscripten’s IDBFS. Data written to these paths persists across page reloads.
Set to
true to use a SharedWorker instead of a dedicated Worker. Useful when multiple browser contexts (tabs, iframes) need to share a single kernel instance. Defaults to false.The worker type passed to the
Worker constructor. createKernel defaults this to 'module' because Vite serves worker scripts as ES modules in development without bundling. You should not need to change this in a standard Vite setup.Environment variables to expose inside the Pyodide Python environment. Keys must start with a letter or underscore and contain only letters, digits, or underscores.
Set to
true to enable Python code completion. This loads additional packages into the Pyodide environment and makes kernel.getCodeCompletion() available. Defaults to false.Set to
true to enable Streamlit’s module auto-load feature, which detects Python import statements in the running script and automatically installs any missing packages via micropip. Defaults to false.The
pathname used as the base path for custom component URLs and for the main page in multi-page apps. If omitted, window.location.pathname at the time of kernel initialisation is used. Set this explicitly when your server returns the main page for any sub-path, to avoid URL resolution issues.Advanced host-configuration properties forwarded to the Streamlit
ConnectionManager as the host-config response. Most applications do not need this. It is primarily used to configure allowedOrigins for iframe messaging in embedded contexts such as the VS Code extension.An existing
Worker instance to use instead of letting createKernel construct one. This is an advanced escape hatch for environments with a custom worker setup — for example, Electron or Node.js desktop apps that provide their own worker backend.StliteApp component
kernel. This component does not include any toast notification overlay — it only renders the Streamlit frontend. Use this when you want to manage notifications yourself or prefer no loading toasts at all.
Props
A kernel instance returned by
createKernel or useKernel. The component subscribes to the kernel’s message bus and renders the Streamlit UI inside a Styletron-scoped style provider.A CSP nonce value injected into inline
<style> tags generated by Styletron. Use this when your Content Security Policy requires a nonce for inline styles.Set to
true to prevent the component from injecting global document-level styles. Useful when embedding the Streamlit UI inside a shadow DOM or a tightly scoped container.StliteAppWithToast component
StliteApp with a react-toastify toast overlay. Toasts are shown for:
- Load progress — messages emitted while Pyodide and Streamlit are initialising (
loadProgressandloadFinishedkernel events). - Load errors — shown when the kernel encounters an error during startup (
loadErrorkernel event). - Module auto-load — shown when Streamlit auto-installs packages detected in the running script (
moduleAutoLoadkernel event). - File and environment operations — install, writeFile, renameFile, unlink, readFile, and reboot events always generate toasts and cannot be individually disabled.
Props
A kernel instance returned by
createKernel or useKernel.Set to
true to suppress toasts for loadProgress and loadFinished kernel events. The Streamlit app will still load normally — progress information will just not be surfaced to the user.Set to
true to suppress toasts for loadError kernel events. Errors will still be thrown and logged; they simply will not trigger a visible notification.Set to
true to suppress toasts for moduleAutoLoad kernel events. Streamlit will still auto-install detected packages; the user just will not see the toast notification.Passed through to the underlying
StliteApp. A CSP nonce for inline styles.Passed through to the underlying
StliteApp. Prevents global document-level style injection.useKernel()
StliteKernel on mount and disposes it automatically when the component unmounts. Returns null until the kernel object has been created (i.e., during the initial render before the effect runs).
options is only read on mount. Changing the options value on subsequent renders has no effect — the kernel is not re-created. If you need to respond to changing configuration, dispose the current kernel and create a new one.
When to use useKernel vs createKernel:
- Use
createKernelat module level when the kernel should live for the entire page lifetime (the most common case). - Use
useKernelinside a component when the kernel’s lifetime should be scoped to that component — for example, in a modal or a tab panel that may be unmounted and remounted.
Type exports
All types below are re-exported from@stlite/kernel via @stlite/react, so you can import them from @stlite/react directly.
EmscriptenFile
data can be a plain string (for text files) or an ArrayBufferView (for binary files). The optional opts are passed to Emscripten’s FS.writeFile.
EmscriptenFileUrl
opts are passed to Emscripten’s FS.writeFile.
PyodideArchive
pyodide.unpackArchive().
PyodideArchiveUrl
StreamlitConfig
'theme.primaryColor') and values must be primitive types convertible from JavaScript to Python.
MicropipInstallOptions
micropip.install() when installing packages at runtime. Corresponds exactly to micropip’s install keyword arguments.