loadarchive(filename, folder=None, loadobj=True, loadmetadata=False, remapping=None, die=True, **kwargs)[source]#

Load a zip file saved with sc.savearchive().

Note: Since this function relies on pickle, it can potentially execute arbitrary code, so you should only use it with sources you trust. For more information, see: https://docs.python.org/3/library/pickle.html

  • filename (str/path) – the file load to (usually ends in .zip)

  • folder (str) – optional additional folder to load from

  • loadobj (bool) – whether to load the saved object

  • loadmetadata (bool) – whether to load the metadata as well

  • remapping (dict) – any known module remappings between the saved pickle version and the current libraries

  • die (bool) – whether to fail if an exception is raised (else, just return the metadata)

  • kwargs (dict) – passed to sc.load()


If loadobj=True and loadmetadata=False, return the object; If loadobj=False and loadmetadata=True, return the metadata If loadobj=True and loadmetadata=True, return a dictionary of both


obj = MyClass() # Create an arbitrary object
sc.savearchive('my-class.zip', obj)

# Much later...
data = sc.loadarchive('my-class.zip', loadmetadata=True)
metadata, obj = data['metadata'], data['obj']

Note: This function expects the zip file to contain two files in it, one called “metadata.json” and one called “sciris_pickle.obj”. If you need to change these, you can manually modify sc.sc_versioning._metadata_filename and sc.sc_versioning._obj_filename, respectively. However, you almost certainly should not do so!

New in version 3.0.0.