Skip to content

Files

Read, write, upload, download and watch files in a sandbox.

Every method shows the same operation in each SDK; pick a language once and every tab on the site follows it.

Python TypeScript Go Ruby Java

Authenticated FilesystemService client bound to one sandbox.

def list(self, path: str, *, depth: int=1, user: str | None=None) -> list[FileInfo]
Parameter Type Default
path str
depth int 1
user str | None None

Returns list[FileInfo]

Source: sdk/python/svm/files.py:122
def close(self) -> None

Close the channel; a later call opens a new one. A watch_dir in flight ends (its iterator stops) and does not poll or reconnect again.

Source: sdk/python/svm/files.py:76

Not in the Python SDK’s FileClient.

def download(self, path: str, dest: 'str | os.PathLike[str] | BinaryIO', *, expected_sha256: str | None=None, resume: bool=False, user: str | None=None, gzip: bool=False) -> TransferResult

Stream a file to dest (a path or a binary file) holding one chunk in memory.

A broken connection resumes from the last byte written; a file that changed meanwhile fails with TransferError. To a path the bytes go to <dest>.part, renamed when complete, and resume=True continues a partial one left by an earlier run. The size is checked, and expected_sha256 when given.

Parameter Type Default
path str
dest 'str | os.PathLike[str] | BinaryIO'
expected_sha256 str | None None
resume bool False
user str | None None
gzip bool False

Returns TransferResult

Raises TransferError

Source: sdk/python/svm/files.py:161

Not in the Python SDK’s FileClient.

def download_url(self, path: str, *, user: str | None=None, expires_in_seconds: int=300) -> FileUrl

A signed URL that downloads path with a plain HTTP request, valid for expires_in_seconds (1..3600).

Parameter Type Default
path str
user str | None None
expires_in_seconds int 300

Returns FileUrl

Source: sdk/python/svm/files.py:336
def exists(self, path: str, *, user: str | None=None) -> bool
Parameter Type Default
path str
user str | None None

Returns bool

Source: sdk/python/svm/files.py:113
def get_info(self, path: str, *, user: str | None=None) -> FileInfo
Parameter Type Default
path str
user str | None None

Returns FileInfo

Source: sdk/python/svm/files.py:110

Not in the Python SDK’s FileClient.

def make_dir(self, path: str, *, user: str | None=None) -> FileInfo
Parameter Type Default
path str
user str | None None

Returns FileInfo

Source: sdk/python/svm/files.py:128
def read(self, path: str, *, offset: int=0, limit: int=0, user: str | None=None, gzip: bool=False) -> bytes

The file’s bytes, resumed where a break left off. All in memory: use download for large files. gzip sends the data compressed over the wire (worth it for large, compressible files); the bytes you get are the same.

Parameter Type Default
path str
offset int 0
limit int 0
user str | None None
gzip bool False

Returns bytes

Source: sdk/python/svm/files.py:147
def read_text(self, path: str, *, encoding: str='utf-8', user: str | None=None, gzip: bool=False) -> str
Parameter Type Default
path str
encoding str 'utf-8'
user str | None None
gzip bool False

Returns str

Source: sdk/python/svm/files.py:158
def remove(self, path: str, *, user: str | None=None) -> None
Parameter Type Default
path str
user str | None None
Source: sdk/python/svm/files.py:135
def rename(self, source: str, destination: str, *, user: str | None=None) -> FileInfo
Parameter Type Default
source str
destination str
user str | None None

Returns FileInfo

Source: sdk/python/svm/files.py:131
def upload(self, path: str, source: 'bytes | os.PathLike[str] | BinaryIO', *, mode: int=420, owner: str='', group: str='', user: str | None=None, metadata: dict[str, str] | None=None, gzip: bool=False, verify_checksum: bool=False, _info: bool=False)

Send bytes, a file path or a binary file in 1 MiB chunks. A broken connection sends it again from the start (the file is rewound), which is safe because the sandbox replaces the target atomically; the size sent and written must agree, and verify_checksum reads the file back to compare its SHA-256.

Parameter Type Default
path str
source 'bytes | os.PathLike[str] | BinaryIO'
mode int 420
owner str ''
group str ''
user str | None None
metadata dict[str, str] | None None
gzip bool False
verify_checksum bool False
_info bool False

Raises FileUploadError

Source: sdk/python/svm/files.py:219

Not in the Python SDK’s FileClient.

Not in the Python SDK’s FileClient.

def upload_url(self, path: str, *, user: str | None=None, expires_in_seconds: int=300) -> FileUrl

A signed URL that uploads to path with a plain HTTP request, valid for expires_in_seconds (1..3600).

Parameter Type Default
path str
user str | None None
expires_in_seconds int 300

Returns FileUrl

Source: sdk/python/svm/files.py:332
def watch_dir(self, path: str, *, recursive: bool=False, resilient: bool=True, user: str | None=None, _stop=None) -> Iterator[FileEvent]

Changes in a directory. resilient (the default) polls a watcher the sandbox keeps, so a break loses no event (up to 0.25 s late) and WatchLostError means the watcher is gone; otherwise events stream. close() on this client ends the iteration.

Parameter Type Default
path str
recursive bool False
resilient bool True
user str | None None
_stop None

Returns Iterator[FileEvent]

Raises WatchLostError

Source: sdk/python/svm/files.py:284
def write(self, path: str, content: str | bytes, *, mode: int=420, owner: str='', group: str='', user: str | None=None, metadata: dict[str, str] | None=None, gzip: bool=False) -> FileInfo

Write a file. metadata (up to 16 string pairs) is stored with it and returned in FileInfo.metadata; a write replaces the file and its pairs. gzip sends the data compressed over the wire.

Parameter Type Default
path str
content str | bytes
mode int 420
owner str ''
group str ''
user str | None None
metadata dict[str, str] | None None
gzip bool False

Returns FileInfo

Source: sdk/python/svm/files.py:208
def write_batch(self, files: dict[str, str | bytes], *, concurrency: int=8, user: str | None=None, gzip: bool=False) -> list[FileInfo]

Write many files at once, in order of files, all as user (the sandbox default when None).

Parameter Type Default
files dict[str, str | bytes]
concurrency int 8
user str | None None
gzip bool False

Returns list[FileInfo]

Source: sdk/python/svm/files.py:270
Python TypeScript Go Ruby Java

FileInfo is an envd filesystem entry.

Property Type Description
group str
is_dir bool Whether the entry is a directory (type is the protocol’s name, FILE\_TYPE\_DIRECTORY).
is_file bool
is_symlink bool
metadata dict[str, str]
mode int
modified_at str | None
name str
owner str
path str
permissions str
size int
symlink_target str | None
type str
def from_proto(cls, entry: pb.EntryInfo) -> 'FileInfo'
static
Parameter Type Default
entry pb.EntryInfo

Returns 'FileInfo'

Source: sdk/python/svm/file_types.py:38
Python TypeScript Go Ruby Java

FileEvent reports one filesystem change.

Property Type Description
name str
type str
Python TypeScript Go Ruby Java
Property Type Description
expires_at str
url str
Python TypeScript Go Ruby Java

TransferResult is what a transfer moved: its size and the SHA-256 of the bytes.

Property Type Description
sha256 str
size int
Python TypeScript Go Ruby Java

A ReadFile response stream of gzip chunks seen as the plain chunks read_ranges expects (each with .data).

Memory stays bounded however well the data compresses (output is taken one chunk at a time), and a stream that ends before the gzip trailer is a TransferError, not a shorter file. A broken connection is raised as the gRPC error it is, so the caller resumes from the plain bytes it has: a new request, a new gzip stream.

def cancel(self) -> bool

Returns bool

Source: sdk/python/svm/transfer.py:160
Python TypeScript Go Ruby Java

A transfer finished wrongly (size or checksum differs) or could not be retried safely. A SandboxError, as every error this package raises is.

Python exposes these as methods; see below.

Not in the Python SDK’s TransferError.

Not in the Python SDK’s TransferError.

Not in the Python SDK’s TransferError.

Python TypeScript Go Ruby Java

An upload to a sandbox did not complete correctly: the sandbox wrote a different size than was sent, the file’s checksum differs from what was sent, or the connection broke and the source cannot be read again (the reference vendor’s FileUploadError). A TransferError, so except TransferError still catches it. Downloads keep raising plain TransferError.

Python exposes these as methods; see below.

Not in the Python SDK’s FileUploadError.

Not in the Python SDK’s FileUploadError.

Not in the Python SDK’s FileUploadError.

Not in the Python SDK’s FileUploadError.

Python TypeScript Go Ruby Java

The server answered FILE_UPLOAD_FAILED: the file in the sandbox is not what was sent. A FileUploadError (so a TransferError) and, by its HTTP status, an InternalError; error_kind says file_upload.

Not in the Python SDK’s FileUploadApiError.

Not in the Python SDK’s FileUploadApiError.

Not in the Python SDK’s FileUploadApiError.

Python TypeScript Go Ruby Java

The sandbox no longer knows the watcher, so events may have been missed: list the directory again. A SandboxError, as every error this package raises is.

Not in the Python SDK’s WatchLostError.

Not in the Python SDK’s WatchLostError.

Not in the Python SDK’s WatchLostError.

Not in the Python SDK’s WatchLostError.