Skip to content

Xfel/init-args-serializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python init-args based Serializer

PyPI version codecov

This package provides improved pickling support. Instead of storing the entire state dict __dict__, the parameters passed to the initializer __init__() are captured. During unpickling, the captured parameters are used to create a new object instance.

This behaviour is implemented using the __reduce__() hook. Thus, it is strongly discouraged to override the __reduce__() method. If you need to pickle variables beyond the constructor parameters, you should use the regular __getstate__() and __setstate__() methods.

Installation

pip install init-args-serializer

Usage

class MyCustomClass(OptionalBaseClass, Serializable):
    
    def __init__(self, *args, **kwargs):
        # Recommended to call this first
        Serializable._init(self, locals())

About

Python init-args based Serializer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages