Skip to content

synaptome.io

synaptome.io

Saving, loading, and sharing studies.

atomic_replace(path, write_func)

Writes path atomically: write_func(tmp_path) writes the full content to a temporary sibling file, which then replaces path via os.replace (atomic on POSIX and Windows).

path is therefore always either its previous complete content or the new complete content -- never a truncated file -- even if the process is killed mid-write. The temporary file is removed if write_func fails.

Technical details

The temporary name only prefixes path.name with a unique token, so writers that check or auto-append a suffix (e.g. np.savez appending ".npz") still produce exactly the temporary path given.

Parameters:

Name Type Description Default
path str | Path

Final destination.

required
write_func Callable[[Path], None]

Called once with the temporary path; must write the complete file there.

required

load(path, variables=None)

Loads a saved study (folder or .syn file).

Parameters:

Name Type Description Default
path str | Path
required
variables list[str] | None

Load only these variables (definitions and values); by default all of them. The variable that a requested replicate variable replicates is loaded too. Units, identity, protocol (with every pre-specified question) and attachments are always loaded.

None

Returns:

Type Description
Study

peek(path)

What a saved study contains, read from its manifest only (no data is loaded).

Returns:

Type Description
dict

title, created_at, synaptome_version, software, levels ({name: n_units}), variables ({name: {level, dims, dtype, n_values}}), questions ({title: status}, the pre-specified questions) and attachments (names).

save(study, path, overwrite=False)

Saves a study. A path ending with .syn gives a single zip file; any other path gives a folder.

The save is all-or-nothing: everything is written to a temporary location first, then moved into place, so an interrupted save never leaves a half-written study (an existing one is kept intact).

Parameters:

Name Type Description Default
study Study
required
path str | Path
required
overwrite bool

Replace an existing save at path (default False). Only previous synaptome saves are ever replaced: any other file or folder at path raises.

False

Returns:

Type Description
Path

Where the study was saved.