Skip to content

AsyncFileManager

Reads, writes, uploads, and downloads runtime files asynchronously.

Async · Sync counterpart: FileManager

class AsyncFileManager(_SdkOwnedHandle):

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

manager = runtime.files

Read a file from the runtime as bytes.

async 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.

async 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.
>>> await runtime.files.write(
... "/workspace/hello.sh", "#!/bin/sh\necho hello\n", executable=True
... )
>>> result = await runtime.exec(["/workspace/hello.sh"])
>>> result.stdout_text
'hello\n'

Asynchronously stream a local file or directory to the runtime.

async 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.
>>> await runtime.files.upload("./project", "/workspace/project")

Asynchronously stream a runtime file or directory locally.

async def download(src: str, dst: str) -> None
Name Type Default Description
src str Source file or directory inside the runtime.
dst str Local destination path.
>>> await runtime.files.download("/workspace/dist", "./artifacts/")