Repickle makes it possible to serialize Python constructs not supported by the default pickle module from the Python standard library. Repickle just extends cloudpickle and add support for load and dump to files.
The latest release of repickle is available from pypi:
pip install repickle Pickling a lambda expression:
>>>importrepickle>>>squared=lambdax: x**2>>>repickle.dump_to_file(squared, "pickled_lambda.pkl") >>>new_squared=repickle.load_from_file("pickled_lambda.pkl") >>>new_squared(2) 4Pickling a function interactively defined in a Python shell session (in the __main__ module):
>>>CONSTANT=42>>>defmy_function(data: int) ->int: ... returndata+CONSTANT ... >>>importrepickle>>>repickle.dump_to_file(my_function, "pickled_lambda.pkl") >>>depickled_function=repickle.load_from_file("pickled_lambda.pkl") >>>depickled_function(43) 85