Volume Sync
Volume
class Volume()E2B Volume for persistent storage that can be mounted to sandboxes.
create
@classmethod
def create(cls, name: str, **opts: Unpack[ApiParams]) -> "Volume"Create a new volume.
Arguments:
name: Name of the volume
Returns:
A Volume instance for the new volume
connect
@classmethod
def connect(cls, volume_id: str, **opts: Unpack[ApiParams]) -> "Volume"Connect to an existing volume by ID.
Arguments:
volume_id: Volume ID
Returns:
A Volume instance for the existing volume
destroy
@staticmethod
def destroy(volume_id: str, **opts: Unpack[ApiParams]) -> boolDestroy a volume.
Arguments:
volume_id: Volume ID
make_dir
def make_dir(path: str,
uid: Optional[int] = None,
gid: Optional[int] = None,
mode: Optional[int] = None,
force: Optional[bool] = None,
**opts: Unpack[VolumeApiParams]) -> VolumeEntryStatCreate a directory.
Arguments:
path: Path to the directory to createuid: User ID of the created directorygid: Group ID of the created directorymode: Mode of the created directoryforce: Create parent directories if they don’t existopts: Connection options
Returns:
Information about the created directory
exists
def exists(path: str, **opts: Unpack[VolumeApiParams]) -> boolCheck whether a file or directory exists.
Uses get_info under the hood. Returns True if the path exists, False if it does not (404). Other errors are re-raised.
Arguments:
path: Path to the file or directoryopts: Connection options
Returns:
True if the path exists, False otherwise
update_metadata
def update_metadata(path: str,
uid: Optional[int] = None,
gid: Optional[int] = None,
mode: Optional[int] = None,
**opts: Unpack[VolumeApiParams]) -> VolumeEntryStatUpdate file or directory metadata.
Arguments:
path: Path to the file or directoryuid: User ID of the file or directorygid: Group ID of the file or directorymode: Mode of the file or directoryopts: Connection options
Returns:
Updated entry information
read_file
def read_file(
path: str,
format: Literal["text", "bytes", "stream"] = "text",
**opts: Unpack[VolumeApiParams]) -> Union[str, bytes, Iterator[bytes]]Read file content.
You can pass text, bytes, or stream to format to change the return type.
Arguments:
path: Path to the fileformat: Format of the file content—textby defaultopts: Connection options
Returns:
File content as string, bytes, or iterator of bytes
write_file
def write_file(path: str,
data: Union[str, bytes, IO[bytes]],
uid: Optional[int] = None,
gid: Optional[int] = None,
mode: Optional[int] = None,
force: Optional[bool] = None,
**opts: Unpack[VolumeApiParams]) -> VolumeEntryStatWrite content to a file.
Writing to a file that doesn’t exist creates the file. Writing to a file that already exists overwrites the file.
Arguments:
path: Path to the filedata: Data to write to the file. Data can be a string, bytes, or IO.uid: User ID of the created filegid: Group ID of the created filemode: Mode of the created fileforce: Force overwrite of an existing fileopts: Connection options
Returns:
Information about the written file
remove
def remove(path: str, **opts: Unpack[VolumeApiParams]) -> NoneRemove a file or directory.
Arguments:
path: Path to the file or directory to removeopts: Connection options