Stlite runs Python inside Pyodide, which provides a Linux-like virtual file system (powered by Emscripten FS) that is completely isolated from the host operating system. When your Python code opens a file withDocumentation 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.
open("path/to/file"), it is reading from this virtual file system — not from the user’s hard drive or the web server. The files and archives options on mount() are how you populate that file system before the app starts.
The default file system backend is MEMFS, which is ephemeral: all data is lost when the page is reloaded. For persistent storage across reloads, see the idbfsMountpoints option.
The files option
files is a plain JavaScript object whose keys are virtual file system paths and whose values describe the file content. Three value shapes are supported.
1. Inline string or binary data
Pass the file content directly as a JavaScriptstring or Uint8Array. This is the most straightforward approach for source code and small data files that you want to embed directly in the page.
2. Object with a url field
Provide a { url: "..." } object to have Stlite fetch the file from a URL and write it to the virtual file system at startup. Both absolute and relative URLs are supported — relative URLs are resolved against window.location.href before being passed to the worker.
3. Object with data and opts fields (advanced)
For advanced control over how Emscripten writes the file, supply both a data field (the content) and an opts field (options forwarded to FS.writeFile(path, data, opts)). The url field also accepts an opts sibling.
Relative URLs in the
files option are resolved to absolute URLs before
being sent to the background worker, because the worker operates in a
separate context where the page’s base URL is not available.The archives option
Use archives to load compressed archives — such as zip or tar files — unpack them, and mount the resulting directory tree onto the virtual file system. This is useful for distributing many data or asset files as a single download.
Each entry in the archives array can specify the archive either by URL or as a raw binary buffer, plus a format string and optional options. These are forwarded to pyodide.unpackArchive(buffer, format, options).
Passing binary data directly
If you already have the archive content as aUint8Array (for example fetched manually), pass it via the buffer field instead of url.
archives entry fields
| Field | Type | Required | Description |
|---|---|---|---|
url | string | One of url or buffer | URL of the archive to download. Relative URLs are resolved against window.location.href. |
buffer | ArrayBuffer | Uint8Array | One of url or buffer | Raw binary content of the archive. |
format | string | Yes | Archive format passed to pyodide.unpackArchive(), e.g. "zip", "tar", "tar.gz". |
options | object | No | Additional options forwarded to pyodide.unpackArchive(). |
Just like the
files url field, relative URLs in archives are resolved to absolute URLs before being passed to the worker.Multipage app with files
Build a multipage Streamlit app by including the main entry point and page scripts under pages/.
Persistent file storage with IndexedDB
By default all virtual file system paths useMEMFS and are wiped on page reload. Mount specific directories with the idbfsMountpoints option to back them with IndexedDB and persist data across sessions.