modal.file_io

modal.file_io.FileIO 

[Alpha] FileIO handle, used in the Sandbox filesystem API.

The API is designed to mimic Python’s io.FileIO.

Currently this API is in Alpha and is subject to change. File I/O operations may be limited in size to 100 MiB, and the throughput of requests is restricted in the current implementation. For our recommendations on large file transfers see the Sandbox filesystem access guide.

Usage

create 

Create a new FileIO handle.

read 

Read n bytes from the current position, or the entire remaining file if n is None.

readline 

Read a single line from the current position.

readlines 

Read all lines from the current position.

write 

Write data to the current position.

Writes may not appear until the entire buffer is flushed, which can be done manually with flush() or automatically when the file is closed.

flush 

Flush the buffer to disk.

seek 

Move to a new position in the file.

whence defaults to 0 (absolute file positioning); other values are 1 (relative to the current position) and 2 (relative to the file’s end).

ls 

List the contents of the provided directory.

mkdir 

Create a new directory.

rm 

Remove a file or directory in the Sandbox.

watch 

close 

Flush the buffer and close the file.

modal.file_io.FileWatchEvent 

FileWatchEvent(paths: list[str], type: modal.file_io.FileWatchEventType)

modal.file_io.FileWatchEventType 

An enumeration.

The possible values are:

  • Unknown
  • Access
  • Create
  • Modify
  • Remove