Skip to content

Watch

marimo.watch.file

file(path: Path | str) -> FileState

A reactive wrapper for file paths.

This function takes a file path to watch and returns a wrapper to reactively read and write from the file.

The "wrapped" file Path object exposes most of the same methods as the pathlib.Path object, with a few exceptions. The following methods are not available:

  • open()
  • rename()
  • replace()

This object will trigger dependent cells to re-evaluate when the file is changed.

Warning

It is possible to misuse this API in similar ways to state(). Consider reading the warning and caveats in the state() documentation, and using this function only when reading file paths, and not when writing them.

PARAMETER DESCRIPTION
path

Path to watch.

TYPE: Path | str

RETURNS DESCRIPTION
FileState

A reactive wrapper for watching the file path.

marimo.watch.directory

directory(path: Path | str) -> DirectoryState

A reactive wrapper for directory paths.

This function takes a directory path to watch and returns a wrapper to reactively list the contents of the directory.

This object will trigger dependent cells to re-evaluate when the directory structure is changed (i.e., files are added or removed).

Note

This function does NOT react to file content changes, only to changes in the directory structure. Utilize mo.watch.file() to watch for changes in specific files. Additional note: this will not follow symlinks.

PARAMETER DESCRIPTION
path

Path to watch.

TYPE: Path | str

RETURNS DESCRIPTION
DirectoryState

A reactive wrapper for watching the directory.