Stlite executes your Python code inside Pyodide, which provides its own Linux-like virtual file system powered by Emscripten. This file system lives entirely in the browser — it is completely isolated from the host operating system. Understanding how it works helps you load data into your app, persist state across reloads, and manipulate files at runtime.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.
How the virtual file system works
Pyodide’s file system looks and behaves like a standard Linux directory tree. Paths like/home/pyodide/, /tmp/, and /mnt/ all exist within the browser’s memory. Because the file system is isolated from the host OS, any Python file operation — open(), os.listdir(), shutil.copy(), etc. — operates on this virtual tree, not on actual files on the user’s computer.
/ and standard directories (including the home directory) are mounted with MEMFS — an in-memory, ephemeral file system. Any files written to a MEMFS-backed path are lost when the page is reloaded or the browser tab is closed.
File system paths in the virtual FS use forward slashes (
/) regardless of
the host operating system, following Linux conventions.Mounting files at startup
Themount() function and the <streamlit-app> tag both provide options to pre-populate the virtual file system before your Python code runs.
files option — string, binary, or URL
Pass an object whose keys are virtual file paths and whose values are the file contents. Three value shapes are supported:
String or binary data — inline the content directly:
opts — pass additional options forwarded to Emscripten’s FS.writeFile(path, data, opts):
mount() options, see /browser/files-and-archives.
archives option — unpack zip files
Use the archives option to download an archive (e.g. a zip file), unpack it, and mount all its contents into the virtual file system in one step. This is useful for loading multiple related files such as a dataset directory.
Each entry is passed to Pyodide’s unpackArchive(buffer, format, options) internally.
Persisting files with IndexedDB (IDBFS)
By default, every MEMFS-backed write is lost on page reload. To persist data across reloads and even across browser sessions, Stlite supports mounting directories withIDBFS — Emscripten’s IndexedDB-backed file system.
Files written to an IDBFS-mounted path are stored in the browser’s IndexedDB and survive page reloads.
Enabling IDBFS in @stlite/browser
Pass the idbfsMountpoints option to mount() with an array of virtual FS paths that should be backed by IndexedDB:
/mnt/ directory persists in IndexedDB between sessions.
IDBFS is tied to the browser origin. Clearing the browser’s site data (cache,
storage) will erase IndexedDB contents, including IDBFS-persisted files.
Runtime file operations (controller methods)
The object returned bymount() exposes methods for reading and writing files in the virtual FS at runtime — without needing to remount the app. These are useful for dynamically pushing data into a running app from the JavaScript side.
writeFile(path, data, opts?)
Write a file to the virtual FS. data can be a string or an ArrayBufferView (e.g. Uint8Array).
readFile(path, opts?)
Read a file from the virtual FS. Returns the contents as a Uint8Array (binary) or string, depending on the opts passed.
renameFile(oldPath, newPath)
Move or rename a file within the virtual FS.
unlink(path)
Delete a file from the virtual FS.
Desktop apps: local file access
When building a desktop application with@stlite/desktop, Stlite can mount real directories from the local file system using Electron’s Node.js-backed NODEFS instead of MEMFS. This gives your Python code direct read/write access to actual files on the user’s disk.
For details, see the Desktop: File System guide.