squirrel.framework.io

Contains methods that help with writing/reading from files.

Module Contents

Functions

read_from_file(→ Any)

Reads from a file.

write_to_file(→ None)

Writes an object to a file.

squirrel.framework.io.read_from_file(fp: str, fs: Optional[squirrel.constants.FILESYSTEM] = None, serializer: Optional[squirrel.serialization.SquirrelSerializer] = None, **open_kwargs)Any

Reads from a file.

Parameters
  • fp (str) – Path to the file.

  • fs (FILESYSTEM, optional) – Filesystem object to be used to open the file. If not provided, the suitable filesystem will be determined using squirrel.fsspec.fs.get_fs_from_url(). Defaults to None.

  • serializer (SquirrelSerializer, optional) – Serializer to be used to deserialize the data read from the file. If not provided, read data will not be deserialized. Defaults to None.

  • **open_kwargs – Keyword arguments that will be forwarded to the filesystem object when opening the file.

Returns

(Any) Read (and possibly deserialized) data.

squirrel.framework.io.write_to_file(fp: str, obj: Any, fs: Optional[squirrel.constants.FILESYSTEM] = None, serializer: Optional[squirrel.serialization.SquirrelSerializer] = None, **open_kwargs)None

Writes an object to a file.

Parameters
  • fp (str) – Path to the file.

  • obj (Any) – Object to be written.

  • fs (FILESYSTEM, optional) – Filesystem object to be used to open the file. If not provided, the suitable filesystem will be determined using squirrel.fsspec.fs.get_fs_from_url(). Defaults to None.

  • serializer (SquirrelSerializer, optional) – Serializer to be used to serialize obj before writing to file. If not provided, obj will not be serialized. Defaults to None.

  • **open_kwargs – Keyword arguments that will be forwarded to the filesystem object when opening the file.