File Browser¶
- class marimo.ui.file_browser(initial_path: str = '', filetypes: Sequence[str] | None = None, selection_mode: str = 'file', multiple: bool = True, restrict_navigation: bool = False, *, label: str = '', on_change: Callable[[Sequence[FileInfo]], None] | None = None)¶
- File browser for browsing and selecting server-side files. - Examples. - Selecting multiple files: - file_browser = mo.ui.file_browser( initial_path="path/to/dir", multiple=True ) # Access the selected file path(s): file_browser.path(index) # Get name of selected file(s) file_browser.name(index) - Attributes. - value: a sequence of file paths representing selected files.
 - Initialization Args. - initial_path: starting directory, default current working directory.
- filetypes: the file types to display in each directory; for example,- filetypes=[".txt", ".csv"]. If- None, all files are displayed.
- selection_mode: either “file” or “directory”.
- multiple: if True, allow the user to select multiple files.
- restrict_navigation: if True, prevent the user from navigating any level above the given path.
- label: text label for the element
- on_change: optional callback to run when this element’s value changes
 - Public methods - list_directory(args)- name([index])- Get file name at index. - path([index])- Get file path at index. - Inherited from- UIElement- form([label, bordered, loading, ...])- Create a submittable form out of this - UIElement.- send_message(message, buffers)- Send a message to the element rendered on the frontend from the backend. - Inherited from- Html- batch(**elements)- Convert an HTML object with templated text into a UI element. - center()- Center an item. - right()- Right-justify. - left()- Left-justify. - callout([kind])- Create a callout containing this HTML element. - style(style)- Wrap an object in a styled container. - Public Data Attributes: - Inherited from- UIElement- value- The element’s current value. - Inherited from- Html- text- A string of HTML representing this element. 
 - name(index: int = 0) str | None¶
- Get file name at index. 
 - path(index: int = 0) str | None¶
- Get file path at index.