read_file#

pypillometry.read_file(fname, cache_file=None, force_download=False, session=None, cache_dir=None, autodelete=None, cache_layout='flat')[source]#

Read a Python object from a file using pickle (or HDF5).

Plain, zstd- and gzip-compressed pickle files and HDF5 files written by write_file() are supported (the format is detected from the file content). Objects saved with an older version of pypillometry are upgraded to the current version.

URLs are downloaded with fetch_url(), in the same way as in read_eyelink().

Parameters:
  • fname (str) – filename, HTTP(S) URL or SSH URL (ssh://server/folder/file.pd)

  • cache_file (Optional[str]) – local filename to store a downloaded file in

  • cache_dir (Optional[str]) – directory to store a downloaded file in (as cache_dir/<file>, see cache_layout), used if cache_file is None. If both are None, a temporary directory is used.

  • force_download (bool) – if True, download again even if a local copy exists in cache_file/cache_dir

  • session (Optional[Session]) – requests session for HTTP(S) downloads (e.g., from osf_authenticate() for private projects)

  • autodelete (Optional[bool]) – if True, the downloaded copy is deleted after it was read (also in cache_file/cache_dir). If None (default), only a temporary download (no cache_file/cache_dir) is deleted. Local files are never deleted.

  • cache_layout (str) – "flat" (default) or "mirror" (cache_dir/<host>/<path>), see fetch_url()

Return type:

object

Returns:

loaded object

Warning

Pickle files can run arbitrary code when they are read. Only read pickle files from sources you trust; HDF5 files do not run code.