Skip to content

FileManager

Reads, writes, uploads, and downloads files for a runtime.

Sync · Async counterpart: AsyncFileManager

class FileManager(_SdkOwnedHandle):

This type is created by the SDK; do not construct it directly.

manager = runtime.files

Read a file from the runtime as bytes.

def read(path: str, max_bytes: int | None = None) -> bytes
Name Type Default Description
path str Path inside the runtime.
max_bytes int | None None Maximum number of bytes to return.
  • bytes

Write bytes or text to a runtime file.

def write(path: str, content: bytes | str, executable: bool = False) -> None
Name Type Default Description
path str Absolute destination path inside the runtime.
content bytes | str Text or binary content to write.
executable bool False Mark the resulting file executable.
>>> runtime.files.write(
... "/workspace/hello.sh", "#!/bin/sh\necho hello\n", executable=True
... )
>>> runtime.exec(["/workspace/hello.sh"]).stdout_text
'hello\n'

Stream a local file or directory to the runtime.

The transfer isn’t limited by the REST request-body size. Files are written through a temporary sibling and atomically renamed. Directory uploads are extracted into a staging directory and committed only after the complete archive is received.

def upload(src: str, dst: str) -> None
Name Type Default Description
src str Local file or directory path.
dst str Destination path inside the runtime. A trailing slash places a file beneath that directory using its local basename.
>>> runtime.files.upload("./project", "/workspace/project")
>>> runtime.files.upload("./model.bin", "/workspace/models/")

Stream a runtime file or directory to a staged local path.

def download(src: str, dst: str) -> None
Name Type Default Description
src str Source file or directory inside the runtime.
dst str Local destination. A trailing slash or existing directory places the source beneath it using the remote basename.
>>> runtime.files.download("/workspace/dist", "./artifacts/")