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
NameTypeDefaultDescription
pathstrPath inside the runtime.
max_bytesint | NoneNoneMaximum 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
NameTypeDefaultDescription
pathstrAbsolute destination path inside the runtime.
contentbytes | strText or binary content to write.
executableboolFalseMark 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'

Upload a local file or directory to the runtime.

async def upload(src: str, dst: str) -> None
NameTypeDefaultDescription
srcstrLocal source path.
dststrLocal destination path.

Download a runtime file or directory locally.

async def download(src: str, dst: str) -> None
NameTypeDefaultDescription
srcstrLocal source path.
dststrLocal destination path.