, *, fallback=False, defaults=None, unpack=False)

Decorator for serializing functions

  • extension_mapping (dict, default=None) – An extension -> function mapping. Calling the decorated function with a File of a given extension will use the one in the mapping if it exists, e.g., {‘.csv’: to_csv, ‘.json’: to_json}.

  • fallback (bool or str, default=False) – Determines what method to use if extension_mapping does not match the product to serialize. Valid values are True (uses the pickle module), ‘joblib’, and ‘cloudpickle’. If you use any of the last two, the corresponding moduel must be installed. If this is enabled, the body of the decorated function is never executed. To turn it off pass False.

  • defaults (list, default=None) – Built-in serializing functions to use. Must be a list with any combinations of values: ‘.txt’, ‘.json’, ‘.csv’, ‘.parquet’. To save to .txt, the returned object must be a string, for .json it must be a json serializable object (e.g., a list or a dict), for .csv and .parquet it must be a pandas.DataFrame. If using .parquet, a parquet library must be installed (e.g., pyarrow). If extension_mapping and defaults contain overlapping keys, an error is raised

  • unpack (bool, default=False) – If True, it treats every element in a dictionary as a different file, calling the serializing function one per (key, value) pair and using the key as filename.